Initialize validator. Set csrf protection token from request data if available.
@param bool $csrf
511779
public function initialize($csrf = false)
    {
        $this->_tokenRequired = $csrf;
        if ($csrf) {
            // get current token value from session
            $currentToken = App::$Session->get('_csrf_token', false);
            // set new token value to session
            $newToken = Crypt::randomString(mt_rand(32, 64));
            App::$Session->set('_csrf_token', $newToken);
            // if request is submited for this model - try to validate input data
            if ($this->send()) {
                // token is wrong - update bool state
                if ($currentToken !== $this->getRequest('_csrf_token')) {
                    $this->_tokenOk = false;
                }
            }
            // set token data to display
            $this->_csrf_token = $newToken;
        }
    }
1275812
protected function validCsrf($token, $request)
    {
        return isset($token['csrf']) && hash_equals(
            $token['csrf'], (string) $request->header('X-CSRF-TOKEN')
        );
    }
1069920
protected function initialize()
    {
        if (is_null($this->synchronizerToken)) {
            $this->synchronizerToken = new SynchronizerTokenNativeSession();
        }
        if (is_null($this->validator)) {
            $this->validator = new Validator($this->configuration, $this->getTranslator());
        }
    }
540205
public function initialize(Controller $controller) {
        if ($controller->request->is('ajax')) {
            Configure::write('debug', 0);

            // Must disable security component for AJAX
            if (isset($controller->Security)) {
                $controller->Security->validatePost = false;
                $controller->Security->csrfCheck = false;
            }

            // If not from this domain, destroy
            if (!$this->allowRemote && (strpos(env('HTTP_REFERER'), trim(env('HTTP_HOST'), '/')) === false)) {
                if (isset($controller->Security)) {
                    $controller->Security->blackHole($controller, 'Invalid referrer detected for this request.');
                } else {
                    $controller->redirect(null, 403, true);
                }
            }
        }

        $this->controller = $controller;
    }
360050
public function check(bool $value = true)
    {
        if ($value == false) {
            unset($this->attributes['checked']);
        } else {
            $this->attributes['checked'] = $value;
        }
    }
1042158
public function init() {
        $this->addPrefixPath('Garp_Form', 'Garp/Form')
            ->addElementPrefixPath('Garp_Form', 'Garp/Form/')
            ->addDecorator('FormElements')
            ->addDecorator('Form');

        if (!$this->getAttrib('class')) {
            $this->setAttrib('class', 'garp-form');
        }

        // Anti-spam fields
        if ($this->_addTimestampValidation) {
            $this->addTimestampValidation();
        }
        if ($this->_addHoneypotValidation) {
            $this->addHoneypotValidation();
        }
    }
468588
public function init() {
		
		self::addCssClass($this->htmlOptions, 'form' . self::$typeClasses[$this->type]);
		
		if (!isset($this->errorMessageCssClass)) {
			$this->errorMessageCssClass = 'help-block error';
		}
		if(!isset($this->clientOptions['errorCssClass'])){
			$this->clientOptions['errorCssClass'] = 'has-error';
		}
		if(!isset($this->clientOptions['successCssClass'])){
			$this->clientOptions['successCssClass'] = 'has-success';
		}
		if(!isset($this->clientOptions['inputContainer'])){
			$this->clientOptions['inputContainer'] = 'div.form-group';
		}

		parent::init();
	}
296123
public function checkToken($request_token)
    {
        $token_manager = $this->container->get('security.csrf.token_manager');
        $token = new CsrfToken('file_manager', $request_token);
        $valid = $token_manager->isTokenValid($token);

        if (!$valid) {
            throw new InvalidCsrfTokenException();
        }
    }
986820
private function checkCsrf($tokenValue)
    {
        /** @var \Symfony\Component\Security\Csrf\CsrfTokenManager $csrfTokenManager */
        $csrfTokenManager = $this->get('security.csrf.token_manager');

        $token = new CsrfToken('datagrid', $tokenValue);

        if (!$csrfTokenManager->isTokenValid($token)) {
            throw new AccessDeniedException('Invalid token');
        }
    }
1059659
public function validateToken($token)
    {
        /*
         | Return false if given token is not string
         */
        if (!is_string($token)) {
            return false;
        }

        if (isset($this->storage->csrf_tokens[$token])) {
            $this->storage->csrf_tokens = [trim($token) => null];

            return true;
        }

        return false;
    }
266032
private function _csrf_validate()
    {

        // if CSRF protection is enabled (is not boolean FALSE)
        if ($this->form_properties['csrf_storage_method'] !== false) {

            // reference to the form submission method
            global ${'_' . $this->form_properties['method']};

            $method = & ${'_' . $this->form_properties['method']};

            // if
            if (

                // the hidden field with the CSRF token was submitted
                isset($method[$this->form_properties['csrf_token_name']]) && (

                    // CSRF token is stored in a session variable
                    ($this->form_properties['csrf_storage_method'] == 'session' &&
                    // the session variable exists
                    isset($_SESSION[$this->form_properties['csrf_cookie_name']]) &&
                    // the session variable holds an array
                    is_array($_SESSION[$this->form_properties['csrf_cookie_name']]) &&
                    // the array has 2 entries
                    count($_SESSION[$this->form_properties['csrf_cookie_name']]) == 2 &&
                    // the value of the hidden field and the value in the session match
                    $method[$this->form_properties['csrf_token_name']] == $_SESSION[$this->form_properties['csrf_cookie_name']][0] &&
                    // if CSRF token doesn't expire or it does but it didn't yet
                    ($_SESSION[$this->form_properties['csrf_cookie_name']][1] == 0 || $_SESSION[$this->form_properties['csrf_cookie_name']][1] > time()))

                    ||

                    // CSRF token is stored in a cookie
                    ($this->form_properties['csrf_storage_method'] == 'cookie' &&
                    // the cookie exists
                    isset($_COOKIE[$this->form_properties['csrf_cookie_name']]) &&
                    // the value of the hidden field and the value in the cookie match
                    $method[$this->form_properties['csrf_token_name']] == $_COOKIE[$this->form_properties['csrf_cookie_name']])

                )

            // everything seems in order, then
            ) return true;

            // if we get here something was fishy...
            return false;

        }

        // if protection against CSRF attacks is not enabled, pretend nothing happened
        return true;

    }
371772
protected function _validateToken(ServerRequest $request)
    {
        $cookies = $request->getCookieParams();
        $cookie = Hash::get($cookies, $this->_config['cookieName']);
        $post = Hash::get($request->getParsedBody(), $this->_config['field']);
        $header = $request->getHeaderLine('X-CSRF-Token');

        if (!$cookie) {
            throw new InvalidCsrfTokenException(__d('cake', 'Missing CSRF token cookie'));
        }

        if (!Security::constantEquals($post, $cookie) && !Security::constantEquals($header, $cookie)) {
            throw new InvalidCsrfTokenException(__d('cake', 'CSRF token mismatch.'));
        }
    }
755982
protected function onInValid()
    {
        // We disable this standard error message as we are not changing anything here
        //$this->addMessage(sprintf($this->_('Input error! Changes to %s not saved!'), $this->getTopic()));

        if ($this->_csrf) {
            if ($this->_csrf->getMessages()) {
                $this->addMessage($this->_('The form was open for too long or was opened in multiple windows.'));
            }
        }
    }
1181843
private function validateCsrfTokenInternal($clientSuppliedToken, $trueToken)
    {
        if (!is_string($clientSuppliedToken)) {
            return false;
        }

        $security = $this->app->security;

        return $security->unmaskToken($clientSuppliedToken) === $security->unmaskToken($trueToken);
    }
366454
public function validateCsrf()
    {
        $tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);

        $tokenName = $tokenService->getTokenName();
        $token = $this->getRequestParameter($tokenName);

        if ( $tokenService->checkToken($token) ) {
            $tokenService->revokeToken($token);
            $newToken = $tokenService->createToken();
            $this->setCookie($tokenName, $newToken, null, '/');
            return true;
        }

        \common_Logger::w('Csrf validation failed');
        throw new \common_exception_Unauthorized();
    }
1204966
protected function validateCsrf()
    {
        if (empty($this->getInput('state'))
            || ($this->getInput('state') !== $this->store->get('oauth2state'))
        ) {
            $this->store->set('oauth2state', null);
            throw new CsrfException('Invalid state');
        }
        return;
    }
350207
public function registerCSRFString()
    {
        mt_srand(time());
        $string = md5(mt_rand().'_'.time().'_'.mt_rand().'_'.mt_rand());
        $_SESSION[$this->csrfTokenString] = $string;
    }