| 1: | <?php |
| 2: | |
| 3: | namespace LaravelUi5\Core\Middleware; |
| 4: | |
| 5: | use Closure; |
| 6: | use Illuminate\Foundation\Http\Middleware\ValidateCsrfToken; |
| 7: | use Illuminate\Http\Exceptions\HttpResponseException; |
| 8: | |
| 9: | class VerifyCsrfToken extends ValidateCsrfToken |
| 10: | { |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function handle($request, Closure $next): mixed |
| 28: | { |
| 29: | if ( |
| 30: | $this->isReading($request) || |
| 31: | $this->runningUnitTests() || |
| 32: | $this->inExceptArray($request) || |
| 33: | $this->tokensMatch($request) |
| 34: | ) { |
| 35: | return tap($next($request), function ($response) use ($request) { |
| 36: | if ($this->shouldAddXsrfTokenCookie()) { |
| 37: | $this->addCookieToResponse($request, $response); |
| 38: | } |
| 39: | }); |
| 40: | } |
| 41: | |
| 42: | throw new HttpResponseException( |
| 43: | response('CSRF token mismatch.') |
| 44: | ->header('X-CSRF-Token', 'required') |
| 45: | ->setStatusCode(403) |
| 46: | ); |
| 47: | } |
| 48: | } |
| 49: | |