check csrf
@access protected
@return boolean
@since 3.0
@package Gcs\Framework\Core\Security
5188
protected function _checkCsrf() {
        if ($this->_configFirewall['csrf']['enabled'] == true && $this->request->logged == true) {
            if ($this->_csrf['SESSION'] != false && ($this->_csrf['GET'] != false || $this->_csrf['POST'] != false)) {
                if ($this->_csrf['POST'] == $this->_csrf['SESSION'] || $this->_csrf['GET'] == $this->_csrf['SESSION']) {
                    return true;
                }
                else {
                    return false;
                }
            }
            else {
                return true;
            }
        }
        else {
            return true;
        }
    }
20470
public static function hasCookieToken(): bool
    {
        $cookieName = static::getCookieName();

        if ($cookieName === null || strlen($cookieName) == 0) {
            throw new Exception('Can not check if CSRF token is in cookie when cookie name is not set in CSRF configuration');
        }

        return Cookie::has($cookieName);
    }
434248
public function check()
    {
        $response = $this->client->get($this->getURL());
        $cookie = $this->getCookie($response);
        $fullURL = $this->getURL();

        if ($cookie) {
            return [
                EnvironmentCheck::ERROR,
                "Sessions are being set for {$fullURL} : Set-Cookie => " . $cookie,
            ];
        }
        return [
            EnvironmentCheck::OK,
            "Sessions are not being created for {$fullURL} 👍",
        ];
    }
743159
public function check() {
        if ($this->_checkCsrf() == true) {
            switch ($this->request->logged) {
                case '*' :
                    return true;
                    break;

                case 'true' :
                    if ($this->_checkLogged()) {
                        if ($this->_checkRole()) {
                            return true;
                        }
                        else {
                            $t = new Template($this->_configFirewall['forbidden']['template'], 'gcsfirewall', 0);
                            foreach ($this->_configFirewall['forbidden']['variable'] as $val) {
                                if ($val['type'] == 'var') {
                                    $t->assign([$val['name'] => $val['value']]);
                                }
                                else {
                                    $t->assign([$val['name'] => $this->useLang($val['value'])]);
                                }
                            }
                            echo $t->show();

                            $this->addError('The access to the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action . ' is forbidden', __FILE__, __LINE__, ERROR_FATAL);

                            return false;
                        }
                    }
                    else {
                        $this->addError('The access to the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action . ' is forbidden because the user must be logged', __FILE__, __LINE__, ERROR_FATAL);
                        $url = Url::get($this->_configFirewall['login']['name'], $this->_configFirewall['login']['vars']);

                        if ($url != "") {
                            $this->response->header('Location: ' . $url);

                            return false;
                        }
                        else {
                            $this->addError('The firewall failed to redirect the user to the url ' . $url, __FILE__, __LINE__, ERROR_FATAL);

                            return false;
                        }
                    }
                    break;

                case 'false' :
                    if ($this->_checkLogged() == false) {
                        return true;
                    }
                    else {
                        $this->addError('The access to the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action . ' is forbidden because the user mustn\'t be logged', __FILE__, __LINE__, ERROR_FATAL);
                        $url = Url::get($this->_configFirewall['default']['name'], $this->_configFirewall['default']['vars']);

                        if ($url != "") {
                            $this->response->header('Location:' . $url);
                        }
                        else {
                            $this->addError('The firewall failed to redirect the user to the url ' . $url, __FILE__, __LINE__, ERROR_FATAL);

                            return false;
                        }

                        return false;
                    }
                    break;
            }
        }
        else {
            $t = new Template($this->_configFirewall['csrf']['template'], 'gcsfirewall', 0);
            foreach ($this->_configFirewall['csrf']['variable'] as $val) {
                if ($val['type'] == 'var') {
                    $t->assign([$val['name'] => $val['value']]);
                }
                else {
                    $t->assign([$val['name'] => $this->useLang($val['value'])]);
                }
            }

            echo $t->show();
            $this->addError('The access to the page ' . $this->request->src . '/' . $this->request->controller . '/' . $this->request->action . ' is forbidden : CSRF error', __FILE__, __LINE__, ERROR_FATAL);

            return false;
        }

        return true;
    }
964910
protected function getCode() {
    if (isset($_REQUEST['code'])) {
      if ($this->state !== null &&
          isset($_REQUEST['state']) &&
          $this->state === $_REQUEST['state']) {

        // CSRF state has done its job, so clear it
        $this->state = null;
        $this->clearPersistentData('state');
        return $_REQUEST['code'];
      } else {
        self::errorLog('CSRF state token does not match one provided.');
        return false;
      }
    }

    return false;
  }
105583
public function getCsrfToken() {
		if (!isset($_SESSION[$this->csrfTokenSessionKey])) {
			$this->generateCsrfToken();
		}
		return $_SESSION[$this->csrfTokenSessionKey];
	}
147176
public static function csrfInput()
    {
        return Html::hiddenInput(\Yii::$app->request->csrfParam, \Yii::$app->request->csrfToken);
    }
811396
public function setCsrfProtection($value)
    {
        $this->csrfProtection = (bool)$value;

        if (!$value) {
            $this->removeFieldByName('csrftoken');
        } else {
            $field = $this->getFieldByName('csrftoken');

            // if the field does not exists yet, lets add it.
            if ($field === null) {
                $submitted = $this->isSubmitted();

                // Add a hidden 'csrftoken' field.
                $field = $this->hiddenField('csrftoken');

                $field->addValidator(new CsrfValidator());

                if (!$submitted && !$field->getValue()) {
                    $field->setValue(CsrfValidator::generateToken());
                }
            }
        }

        return $this;
    }
259
public static function checkCsrf($type = 1)
    {
        if ($type !== 0 && isset($_SERVER['HTTP_REFERER']) && !strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'])) {
            if ($type == 1) {
                if (!empty($_POST)) {
                    Response::sendHttpStatus(403);
                    throw new \UnexpectedValueException(Lang::get('_ILLEGAL_REQUEST_'));
                }
            } else {
                Response::sendHttpStatus(403);
                throw new \UnexpectedValueException(Lang::get('_ILLEGAL_REQUEST_'));
            }
        }
    }
589502
public function check()
    {
        $attributes = $this->getInputAttributes();
        if (array_key_exists('name', $attributes)) {
            $inputName = $attributes['name'];
        } else {
            $inputName = static::DEFAULT_INPUT_NAME;
        }
        $checkCode = $this->request->get($inputName);
        if (!is_string($checkCode)) {
            $checkCode = '';
        }

        return $this->securimage->check($checkCode);
    }
278090
private static function checkCSRF($session_object=null) {
        global $CFG;
        $token = self::wrapped_session_get($session_object,'CSRF_TOKEN');
        if ( ! $token ) return false;
        if ( isset($_POST['CSRF_TOKEN']) && $token == $_POST['CSRF_TOKEN'] ) return true;
        $headers = array_change_key_case(apache_request_headers());
        if ( isset($headers['x-csrf-token']) && $token == $headers['x-csrf-token'] ) return true;
        if ( isset($headers['x-csrftoken']) && $token == $headers['x-csrftoken'] ) return true;
        return false;
    }
1239427
def disable_csrf_protection():
    
    if not HAS_PLONE_PROTECT:
        logger.warn(
            "Can not disable CSRF protection – please install plone.protect"
        )
        return False
    request = get_request()
    interface.alsoProvides(request, IDisableCSRFProtection)
    return True
707612
protected function validate()
    {
        // Are needed session variables set ?
        if (!isset($_SESSION['s3ss10nCr3at3d']) || !isset($_SESSION['n3k0t'])) {
            return false;
        }

        // Check if session token match ?
        if ($this->matchUserAgent) {
            if ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SERVER['HTTP_USER_AGENT'] . $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
                return false;
            }
        } elseif ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
            return false;
        }

        // Is session expired ?
        if ((time() > ($_SESSION['s3ss10nCr3at3d']) + $this->expiration)) {
            return false;
        }

        // Everything is fine return true
        return true;
    }
1352769
public function check()
    {
        $hasUser = $this->session->has('twitter.user_id') && $this->session->has('twitter.screen_name');

        return $this->hasSessionToken() && $hasUser;
    }
595610
protected function GetCSRFToken()
	{
		$token = $this->Context->Get('X-CSRFToken');
	
		if (!$token)
		{
			$token = md5(rand(1111111111,9999999999).microtime());
			$this->Context->Set('X-CSRFToken',$token);
		}
	
		return $token;
	}
431460
protected function getCsrfToken(): ?string
    {
        if (is_null($this->csrfToken)) {
            $this->csrfToken = $this->app->make('session')->token();
        }

        return $this->csrfToken;
    }
837631
public function csrf($check = false, $force = false)
    {
        if ($this->config['csrf'] !== true) {
            return !empty($check) ? true : '';
        }

        if (session_id() == '' && $this->config['auto_session'] === true) {
            @session_start();
        }

        if ($check === false) {
            $current_token = $this->get_csrf_token();

            if (($current_token !== false && $force) || $current_token === false) {
                $token = sha1(uniqid(microtime(true), true));

                $_SESSION['phery'] = array(
                    'csrf' => $token
                );

                $token = base64_encode($token);
            } else {
                $token = base64_encode($_SESSION['phery']['csrf']);
            }

            return "<meta id=\"csrf-token\" name=\"csrf-token\" content=\"{$token}\" />\n";
        } else {
            if (empty($_SESSION['phery']['csrf'])) {
                return false;
            }

            return $_SESSION['phery']['csrf'] === base64_decode($check, true);
        }
    }