Skip to content

Instantly share code, notes, and snippets.

@ans-4175
Created July 29, 2016 08:07
Show Gist options
  • Save ans-4175/2f1227626480f1e913a42032081c7b9b to your computer and use it in GitHub Desktop.
Save ans-4175/2f1227626480f1e913a42032081c7b9b to your computer and use it in GitHub Desktop.
larave-csrf-method
/**
* Determine if the session and input CSRF tokens match.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function tokensMatch($request)
{
$sessionToken = $request->session()->token();
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');
if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
$token = $this->encrypter->decrypt($header);
}
if (! is_string($sessionToken) || ! is_string($token)) {
return false;
}
return hash_equals($sessionToken, $token);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment