Verify Cross Site Request Forgery Protection

@return object
487744
public function csrf_verify() {
		// If no POST data exists we will set the CSRF cookie
		if (count($_POST) == 0) {
			return $this->csrf_set_cookie();
		}
		
		// Do the tokens exist in both the _POST and _COOKIE arrays?
		if (!isset($_POST[$this->_csrf_token_name]) or !isset($_COOKIE[$this->_csrf_cookie_name])) {
			$this->csrf_show_error();
		}
		
		// Do the tokens match?
		if ($_POST[$this->_csrf_token_name] != $_COOKIE[$this->_csrf_cookie_name]) {
			$this->csrf_show_error();
		}
		
		// We kill this since we're done and we don't want to
		// polute the _POST array
		unset($_POST[$this->_csrf_token_name]);
		
		// Nothing should last forever
		unset($_COOKIE[$this->_csrf_cookie_name]);
		$this->_csrf_set_hash();
		$this->csrf_set_cookie();
		
		//log_message('debug', "CSRF token verified ");
		
		return $this;
	}
1250517
public function verify()
	{
		if (!$this->request->has('transaction_id') && !$this->request->has('iN'))
			throw new InvalidRequestException;
		if ($this->request->has('transaction_id')) {
			$id = $this->request->get('transaction_id');
		}else {
			$id = $this->request->get('iN');
		}

		$transaction = $this->getTable()->whereId($id)->first();

		if (!$transaction)
			throw new NotFoundTransactionException;

		if (in_array($transaction->status, [Enum::TRANSACTION_SUCCEED, Enum::TRANSACTION_FAILED]))
			throw new RetryException;

		$this->make($transaction->port);

		return $this->port->verify($transaction);
	}
1366444
public function authenticate()
	{
		if (!$this->checkError()) {
			return false;
		}

		try {
			$proxy = $this->getProxy();

			if (!empty($_GET['code'])) {
				// This was a callback request from a service, get the token
				$proxy->requestAccessToken($_GET['code']);
				$this->authenticated = true;
			} else if ($proxy->hasValidAccessToken()) {
				$this->authenticated = true;
			} else {
				/** @var $url Uri */
				$url = $proxy->getAuthorizationUri();
				Yii::$app->getResponse()->redirect($url->getAbsoluteUri())->send();
			}
		} catch (OAuthException $e) {
			throw new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e);
		}

		return $this->getIsAuthenticated();
	}
720899
private function verify()
    {
        //====================================================================//
        // Verify host address is present
        if (empty($this->host)) {
            return Splash::log()->err('ErrWsNoHost');
        }

        //====================================================================//
        // Verify Server Id not empty
        if (empty($this->id)) {
            return Splash::log()->err('ErrWsNoId');
        }

        //====================================================================//
        // Verify Server Id not empty
        if (empty($this->key)) {
            return Splash::log()->err('ErrWsNoKey');
        }

        //====================================================================//
        // Verify Http Auth Configuration
        if ($this->httpAuth) {
            if (empty($this->httpUser)) {
                return Splash::log()->err('ErrWsNoHttpUser');
            }
            if (empty($this->httpPassword)) {
                return Splash::log()->err('ErrWsNoHttpPwd');
            }
        }

        return true;
    }
633237
protected function GetCaptchaValue()
    {
        $sCaptchaValue = false;
        if (array_key_exists(self::SESSION_CAPTCHA, $_SESSION)) {
            $sCaptchaValue = $_SESSION[self::SESSION_CAPTCHA];
        }

        return $sCaptchaValue;
    }
623549
public function verify()
	{
		$registry = function_exists('json_encode')
			? json_encode($this->data[self::REGISTRY])
			: CJSON::encode(
				$this->data[self::REGISTRY]
			);
		return $this->data[self::META]["hash"] == md5($registry);
	}
412505
public function actionVerify()
    {
        /** @var RecoveryForm */
        $model = $this->module->createFormModel('RecoveryForm', 'verify');
        $model->setAttributes($_GET);
        if ($model->validate() && $model->getIdentity()->verifyEmail($this->module->requireVerifiedEmail)) {
            // regenerate the activation key to prevent reply attack
            $model->getIdentity()->getActivationKey();
            Yii::$app->session->setFlash('success', Yii::t('usr', 'Your email address has been successfully verified.'));
        } else {
            Yii::$app->session->setFlash('error', Yii::t('usr', 'Failed to verify your email address.'));
        }

        return $this->redirect([Yii::$app->user->isGuest ? 'login' : 'profile']);
    }
196185
protected function isValidLoginRequest()
    {
        $check_hash = $this->queryParameters->get('hash');

        // Get sorted array of values
        $check = $this->queryParameters
            ->except('hash')
            ->map(function ($value, $key) {
                return $key.'='.$value;
            })
            ->values()
            ->sort();
        $check_string = implode("\n", $check->toArray());

        $secret = hash('sha256', $this->config->get('token'), true);
        $hash = hash_hmac('sha256', $check_string, $secret);

        if (strcmp($hash, $check_hash) !== 0) {
            return false;
        }
        if ((time() - $this->queryParameters->get('auth_date')) > 86400) {
            return false;
        }

        return true;
    }
763304
public function verifyHash() {
		$this->ensureInput();
		if(empty($this->input['hash']))
			throw new WebHookHandlerException('No hash provided in input payload', WebHookHandlerException::NO_INPUT_HASH);
		
		if($this->input['payloadEncrypted']) {
			if(!$this->payloadJSONString && !$this->getPayload()) return false;
		} else {
			if(!$this->payloadJSONString) $this->payloadJSONString = json_encode($this->input['payload']);
		}
		
		$webHookSalt = substr($this->input['hash'], 0, self::SALT_LENGTH);
		return $this->input['hash'] === $webHookSalt.hash(self::HASH_METHOD, $webHookSalt.$this->secret.$this->payloadJSONString);
	}
818573
public function csrfFixupNeeded() {
        $result = false;
        $isEnterprise = false; // ce
        if (method_exists('Mage', 'getEdition')) {
            if (Mage::getEdition() === Mage::EDITION_ENTERPRISE) {
                $isEnterprise = true;
            }
        } else {
            if (Mage::getConfig()->getModuleConfig('Enterprise_Enterprise')) {
                $isEnterprise = true;
            }
        }
        if ($isEnterprise) {
            if (version_compare(Mage::getVersion(), '1.13', '>=')) {
                $result = true;
            }
        } else {
            if (version_compare(Mage::getVersion(), '1.8', '>=')) {
                $result = true;
            }
        }
        return $result;
    }
780370
public function getIsAuthenticated()
	{
		if (!$this->authenticated) {
			try {
				$proxy = $this->getProxy();
				$this->authenticated = $proxy->hasValidAccessToken();
			} catch (\OAuth\Common\Exception\Exception $e) {
				throw new ErrorException($e->getMessage(), $e->getCode(), 1, $e->getFile(), $e->getLine(), $e);
			}
		}
		return parent::getIsAuthenticated();
	}
603415
protected function verifyRequest() : bool
    {
        $fieldName = $this->config->get('antispam.sequence.field_name', '__sequence_id');

        if (!$this->request->has($fieldName)) {
            $this->redirectMessage = 'Form sequence ID is not set';

            return false;
        }

        $session = $this->request->session();

        $sequence = $session->get(self::SESSION_KEY);

        if ($sequence === null) {
            $this->redirectMessage = 'The form session ID does not exist, this could be due to session expiry, or submitting the form more than once';

            return false;
        }

        $totalKey = self::SESSION_KEY.'.total';

        $session->increment($totalKey, $sequence['add']);

        if (((int) $this->request->get($fieldName) + $sequence['add']) === $session->get($totalKey, -1)) {
            $session->forget(self::SESSION_KEY);

            return true;
        }

        $session->keep(self::SESSION_KEY);

        $this->redirectMessage = 'The form session ID does not match, this could be due to session expiry, or submitting the form more than once';

        return false;
    }
1255189
public static function authenticate() {
    // If a client does't support cookies, they can use the X-TILMELDAUTH header
    // to provide the auth token.
    if (!empty($_SERVER['HTTP_X_TILMELDAUTH']) && empty($_COOKIE['TILMELDAUTH'])) {
      $fromAuthHeader = true;
      $authToken = $_SERVER['HTTP_X_TILMELDAUTH'];
    } elseif (!empty($_COOKIE['TILMELDAUTH'])) {
      $fromAuthHeader = false;
      $authToken = $_COOKIE['TILMELDAUTH'];
    } else {
      return false;
    }
    $setupUrlParts = parse_url(self::$config['setup_url']);
    $setupHost = $setupUrlParts['host'].
      (array_key_exists('port', $setupUrlParts) ? ':'.$setupUrlParts['port'] : '');
    if ($_SERVER['HTTP_HOST'] === $setupHost
        && $_SERVER['REQUEST_URI'] === $setupUrlParts['path']
      ) {
      // The request is for the setup app, so don't check for the XSRF token.
      $extract = self::$config['jwt_extract']($authToken);
    } else {
      // The request is for something else, so check for a valid XSRF token.
      if (empty($_SERVER['HTTP_X_XSRF_TOKEN'])) {
        return false;
      }

      $extract = self::$config['jwt_extract'](
          $authToken,
          $_SERVER['HTTP_X_XSRF_TOKEN']
      );
    }

    if (!$extract) {
      self::logout();
      return false;
    }
    $guid = $extract['guid'];
    $expire = $extract['expire'];

    $user = Nymph::getEntity(
        ['class' => '\Tilmeld\Entities\User'],
        ['&',
          'guid' => $guid
        ]
    );
    if (!$user || !$user->guid || !$user->enabled) {
      self::logout();
      return false;
    }

    if ($expire < time() + self::$config['jwt_renew']) {
      // If the user is less than renew time from needing a new token, give them
      // a new one.
      self::login($user, $fromAuthHeader);
    } else {
      self::fillSession($user);
    }
    return true;
  }
1081497
def verify_same_origin_request # :doc:
        if marked_for_same_origin_verification? && non_xhr_javascript_response?
          if logger && log_warning_on_csrf_failure
            logger.warn CROSS_ORIGIN_JAVASCRIPT_WARNING
          end
          raise ActionController::InvalidCrossOriginRequest, CROSS_ORIGIN_JAVASCRIPT_WARNING
        end
      end
809616
public function bingVerifAction()
    {
        if ( !$this->getConfigResolver()->hasParameter( 'bing_verification', 'nova_ezseo' ) )
        {
            throw new NotFoundHttpException( "Bing Verification Key not found" );
        }

        $key = $this->getConfigResolver()->getParameter( 'bing_verification', 'nova_ezseo' );

        $xml = new DOMDocument("1.0", "UTF-8");
        $xml->formatOutput = true;

        $root = $xml->createElement("users");
        $root->appendChild($xml->createElement("user", $key));
        $xml->appendChild($root);

        $response = new Response($xml->saveXML());
        $response->setSharedMaxAge( 24 * 3600 );
        $response->headers->set("Content-Type", "text/xml");
        return $response;
    }
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);
    }
1278609
public function getRequestSignature()
    {
        if (empty($this->requestSignature)) {

            $string = $this->getApiId()
                . $this->getTimeStamp()
                . $this->getNonce()
                . $this->getDataString();

            $this->requestSignature = hash_hmac('sha1', $string, $this->getService()->getApiSecret());
        }

        return $this->requestSignature;
    }