Extract code handling CSRF protection.