Note: 'csrf' may be either: - A boolean indicating whether the token is needed (will use default selector to find it) - The name of the meta tag containing the token
778889
function getTokenFromDocument (csrf) {
  if (!document) return
  const selector = isString(csrf) ? csrf : DEFAULT_CSRF_SELECTOR
  const meta = document.querySelector(`meta[name="${ selector }"]`)
  if (meta && (meta instanceof window.HTMLMetaElement)) return meta.content
}
973104
def check_input(self, token):
        
        if token is None:
            raise Exception(self.full_name + ": No token provided!")
        if isinstance(token.payload, str):
            return
        raise Exception(self.full_name + ": Unhandled class: " + classes.get_classname(token.payload))
98134
def csrf_token():
    
    from uliweb import request, settings
    from uliweb.utils.common import safe_str
    
    v = {}
    token_name = settings.CSRF.cookie_token_name
    if not request.session.deleted and request.session.get(token_name):
        v = request.session[token_name]
        if time.time() >= v['created_time'] + v['expiry_time']:
            v = {}
        else:
            v['created_time'] = time.time()
    if not v:
        token = request.cookies.get(token_name)
        if not token:
            token = uuid.uuid4().get_hex()
        
        v = {'token':token, 'expiry_time':settings.CSRF.timeout, 'created_time':time.time()}

    if not request.session.deleted:
        request.session[token_name] = v
    return safe_str(v['token'])
839683
public static function _init()
	{
		static::$csrf_token_key = \Config::get('security.csrf_token_key', 'fuel_csrf_token');
		static::$csrf_old_token = \Input::cookie(static::$csrf_token_key, false);

		// if csrf automatic checking is enabled, and it fails validation, bail out!
		if (\Config::get('security.csrf_autoload', true))
		{
			$check_token_methods = \Config::get('security.csrf_autoload_methods', array('post', 'put', 'delete'));
			if (in_array(strtolower(\Input::method()), $check_token_methods) and ! static::check_token())
			{
				throw new \SecurityException('CSRF validation failed, Possible hacking attempt detected!');
			}
		}

		// throw an exception if the output filter setting is missing from the app config
		if (\Config::get('security.output_filter', null) === null)
		{
			throw new \FuelException('There is no security.output_filter defined in your application config file');
		}

		// deal with duplicate filters, no need to slow the framework down
		foreach (array('output_filter', 'uri_filter', 'input_filter') as $setting)
		{
			$config = \Config::get('security.'.$setting, array());
			is_array($config) and \Config::set('security.'.$setting, \Arr::unique($config));
		}
	}
1321943
def form_authenticity_token
        raise 'CSRF token secret must be defined' if CSRF_TOKEN_SECRET.nil? || CSRF_TOKEN_SECRET.empty?
        if request.session_options[:id].nil? || request.session_options[:id].empty?
          original_form_authenticity_token
        else
          Digest::SHA1.hexdigest("#{CSRF_TOKEN_SECRET}#{request.session_options[:id]}#{request.subdomain}")
        end
      end
431460
protected function getCsrfToken(): ?string
    {
        if (is_null($this->csrfToken)) {
            $this->csrfToken = $this->app->make('session')->token();
        }

        return $this->csrfToken;
    }
201889
private function addCsrf()
    {
        if (!$this->getName()) {
            throw new \LogicException("Can't set CSRF token with form name");
        }

        $csrfName = 'CSRF_' . $this->getName();
        $csrfToken = md5((string) mt_rand());
        self::session()->set($csrfName, $csrfToken);
        $this->addFirst(new Hidden('_csrf', $csrfToken));
    }
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();
    }
333970
def new_csrf_token(self, session_key):
        
        try:
            csrf_token = self._generate_csrf_token()

            session = self._lookup_required_session(session_key)
            session.set_internal_attribute('csrf_token', csrf_token)
            self.session_handler.on_change(session)

        except AttributeError:
            raise CSRFTokenException('Could not save CSRF_TOKEN to session.')

        return csrf_token
875933
protected function addCsrfElement()
    {
        if ($this->has('csrf')) {
            return;
        }

        $spec = array_replace_recursive($this->csrfElementSpec, [
                'name' => $this->getCsrfElementName(),
                'options' => [
                    'csrf_options' => [
                        'timeout' => $this->getFormTimeout(),
                    ],
                ],
            ]);

        $this->add($spec, ['priority' => -980]);
    }
848395
function getCSRFToken() {
		if (typeof document === "undefined") return null;
		var cookies = document.cookie.split(";");//$NON-NLS-0$

		var i,n,v;
		for(i = 0; i<cookies.length; i++) {
			n = cookies[i].substr(0, cookies[i].indexOf("=")).trim();//$NON-NLS-0$
			v = cookies[i].substr(cookies[i].indexOf("=") + 1).trim();//$NON-NLS-0$

			if(n.endsWith(XSRF_TOKEN)) {
				return v;
			}
		}
	}
998442
def csrf_token():
    
    if "_csrf_token" not in session:
        session["_csrf_token"] = os.urandom(128)
    return hmac.new(app.secret_key, session["_csrf_token"],
            digestmod=sha1).hexdigest()
21468
protected function verifyCsrfToken()
    {
        if (!Config::get('cms.enableCsrfProtection')) {
            return true;
        }

        if (in_array(Request::method(), ['HEAD', 'GET', 'OPTIONS'])) {
            return true;
        }

        $token = Request::input('_token') ?: Request::header('X-CSRF-TOKEN');

        if (!strlen($token)) {
            return false;
        }

        return hash_equals(
            Session::token(),
            $token
        );
    }
454055
def check_input(self, token):
        
        if not isinstance(token.payload, ModelContainer):
            raise Exception(self.full_name + ": Input token is not a ModelContainer!")
882507
function isURL(token) {
  try {
    if (!validProtocols.test(token)) {
      return false;
    }
    new URL(token);
    return true;
  } catch (e) {
    return false;
  }
}
146100
public static function csrfMetaTags()
    {
        $csrf = static::getCSRF();
        if ($csrf instanceof CSRF && $csrf->enableCsrfValidation) {
            return static::tag('meta', '', ['name' => 'csrf-param', 'content' => $csrf->csrfParam]) . "\n    "
            . static::tag('meta', '', ['name' => 'csrf-token', 'content' => $csrf->get()]) . "\n";
        } else {
            return '';
        }
    }
1027000
private function check(){
            if (Input::has($this->getFormFieldName())) {
                $key = Input::get($this->getFormFieldName());
                if ($key === Session::get($this->getFormFieldName())) {
                    return true;
                } else {
                    throw new CsrfTokenMatchException(sprintf('Girdiğiniz %s token olması gereken tokenle eşleşmiyor',
                        $key));
                }
            } else {
                throw new CsrfTokenMatchException(sprintf('Herhangi bir Token Girişi yapmamışsınız'));
            }

        }