-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b62983e
commit 893a044
Showing
3 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,7 +59,7 @@ public function handle($request, Closure $next) | |
if ( | ||
$this->isReading($request) || | ||
$this->runningUnitTests() || | ||
$this->shouldPassThrough($request) || | ||
$this->inExceptArray($request) || | ||
$this->tokensMatch($request) | ||
) { | ||
return $this->addCookieToResponse($request, $next($request)); | ||
|
@@ -68,13 +68,34 @@ public function handle($request, Closure $next) | |
throw new TokenMismatchException; | ||
} | ||
|
||
/** | ||
This comment has been minimized.
Sorry, something went wrong.
GrahamCampbell
Member
|
||
* Determine if the HTTP request uses a ‘read’ verb. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
protected function isReading($request) | ||
{ | ||
return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS']); | ||
} | ||
|
||
/** | ||
* Determine if the application is running unit tests. | ||
* | ||
* @return bool | ||
*/ | ||
protected function runningUnitTests() | ||
{ | ||
return $this->app->runningInConsole() && $this->app->runningUnitTests(); | ||
} | ||
|
||
/** | ||
* Determine if the request has a URI that should pass through CSRF verification. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
protected function shouldPassThrough($request) | ||
protected function inExceptArray($request) | ||
{ | ||
foreach ($this->except as $except) { | ||
if ($except !== '/') { | ||
|
@@ -90,36 +111,35 @@ protected function shouldPassThrough($request) | |
} | ||
|
||
/** | ||
* Determine if the application is running unit tests. | ||
* Determine if the session and input CSRF tokens match. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
protected function runningUnitTests() | ||
protected function tokensMatch($request) | ||
{ | ||
return $this->app->runningInConsole() && $this->app->runningUnitTests(); | ||
$token = $this->getTokenFromRequest($request); | ||
|
||
return is_string($request->session()->token()) && | ||
is_string($token) && | ||
hash_equals($request->session()->token(), $token); | ||
} | ||
|
||
/** | ||
* Determine if the session and input CSRF tokens match. | ||
* Get the CSRF token from the request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
* @return string | ||
*/ | ||
protected function tokensMatch($request) | ||
protected function getTokenFromRequest($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); | ||
return $token; | ||
} | ||
|
||
/** | ||
|
@@ -142,15 +162,4 @@ protected function addCookieToResponse($request, $response) | |
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Determine if the HTTP request uses a ‘read’ verb. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return bool | ||
*/ | ||
protected function isReading($request) | ||
{ | ||
return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS']); | ||
} | ||
} |
Shouldn't this be
ValidatePostSize
? It was renamed after all, this file doesn't exist anymore...Sent a PR #16871 so we don't forget about it 😄