Skip to content

Commit

Permalink
Merge pull request #7528 from barryvdh/patch-9
Browse files Browse the repository at this point in the history
Allow both encrypted + unencrypted CSRF header token
  • Loading branch information
taylorotwell committed Feb 20, 2015
2 parents 35a40dc + bd41d7f commit 8687d42
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ public function handle($request, Closure $next)
*/
protected function tokensMatch($request)
{
$token = $request->session()->token();
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');

$header = $request->header('X-XSRF-TOKEN');
if ( ! $token && $header = $request->header('X-XSRF-TOKEN'))
{
$token = $this->encrypter->decrypt($header);
}

return StringUtils::equals($token, $request->input('_token')) ||
($header && StringUtils::equals($token, $this->encrypter->decrypt($header)));
return StringUtils::equals($request->session()->token(), $token);
}

/**
Expand Down

0 comments on commit 8687d42

Please sign in to comment.