Created
July 29, 2016 08:07
-
-
Save ans-4175/2f1227626480f1e913a42032081c7b9b to your computer and use it in GitHub Desktop.
larave-csrf-method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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