mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
Prevent TokenMismatchException for HTTP OPTIONS requests
`OPTIONS` HTTP requests should be treated in the same way than `GET` requests by the `VerifyCsrfToken` middleware. Otherwise, an exception is thrown, thus preventing any `OPTIONS` route to work.
This commit is contained in:
parent
27aa85ccdb
commit
70d516b7ce
@ -17,7 +17,7 @@ class VerifyCsrfToken implements Middleware {
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($request->method() == 'GET' || $this->tokensMatch($request))
|
||||
if ($this->isReadOnly($request) || $this->tokensMatch($request))
|
||||
{
|
||||
return $next($request);
|
||||
}
|
||||
@ -36,4 +36,15 @@ class VerifyCsrfToken implements Middleware {
|
||||
return $request->session()->token() == $request->input('_token');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the HTTP request uses a ‘read’ verb.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return bool
|
||||
*/
|
||||
protected function isReadOnly($request)
|
||||
{
|
||||
return in_array($request->method(), ['GET', 'OPTIONS']);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user