419 Page Expired
Laravel refused a form or request because its CSRF token was missing or did not match the session. Send the token and make sure the session cookie comes back.
- Message
- CSRF token mismatch.
- Exception
- Illuminate\Session\TokenMismatchException
What it means
The PreventRequestForgery middleware in the web middleware group checks every request except GET, HEAD and OPTIONS. When a request cannot show that it came from your own pages, the middleware throws TokenMismatchException with the message "CSRF token mismatch." and Laravel answers with status 419. A browser gets a page titled "Page Expired". A request that asks for JSON gets {"message": "CSRF token mismatch."}.
A request passes in one of two ways. A browser that sends the header Sec-Fetch-Site: same-origin is let through without a token, and browsers send that header only to secure origins: HTTPS, or localhost. Every other request needs a token that matches the one in the visitor's session, sent as the _token form field or in an X-CSRF-TOKEN or X-XSRF-TOKEN header.
Why it happens
- The form has no
@csrffield. Over HTTPS a current browser passes the origin check without it, so the form can work in production and fail over plain HTTP on a real host name or in an older browser. - The session ended while the page sat open. The token in the form belongs to a session that is gone.
SESSION_LIFETIMEsets how long an idle session lives, 120 minutes by default. - The session cookie never comes back. A
SESSION_DOMAINthat does not cover the host,SESSION_SECURE_COOKIE=trueon a site served over plain HTTP, or asame_sitevalue the request does not meet keeps the browser from sending the cookie. Laravel then starts a new session on every request, with a new token. - A cached page serves an old token. A full-page cache or a CDN that stores the HTML hands every visitor the token of the session it was cached under.
- A JavaScript request sends no token and fails the origin check, because it runs over plain HTTP or comes from another origin. A same-origin
fetchover HTTPS passes without a token. Axios copies theXSRF-TOKENcookie into theX-XSRF-TOKENheader on same-origin requests by itself. - The request comes from another site or subdomain, such as a payment page posting back. Its
Sec-Fetch-Siteiscross-siteorsame-site, so it does not pass the origin check by default, and it carries no token for your session.
How to fix it
Put the token in every form that changes something:
<form method="POST" action="/profile">
@csrf
<!-- fields -->
</form>
For JavaScript, print the token in the page and send it as a header:
<meta name="csrf-token" content="{{ csrf_token() }}">
const form = document.querySelector('#profile-form');
fetch('/profile', {
method: 'POST',
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
},
body: new FormData(form),
});
Then check the cookie: in the browser's developer tools, the request should carry the session cookie, named by SESSION_COOKIE or else your snake-cased app name followed by _session, laravel_session by default. If it is missing, correct SESSION_DOMAIN, SESSION_SECURE_COOKIE or SESSION_SAME_SITE. Keep pages with forms out of any full-page cache.
A route that another service posts to, such as a payment webhook, cannot know the token. Exclude it in the withMiddleware closure of bootstrap/app.php:
$middleware->preventRequestForgery(except: [
'stripe/*',
]);
Find it in production
Laravel does not report this exception. TokenMismatchException is on the $internalDontReport list in Illuminate\Foundation\Exceptions\Handler, so it is never logged and never reaches an error tracker that hooks into the exception handler, Ranetrace's error monitoring included. A visitor who loses a form to it leaves nothing in your error list.
The trace is in the web server's access log: POST requests answered with status 419, each with the path of the form that failed.
To have Laravel report it like any other exception, stop ignoring it in the withExceptions closure of bootstrap/app.php:
$exceptions->stopIgnoring(\Illuminate\Session\TokenMismatchException::class);
Each mismatch is then logged and passed to the error trackers hooked into the handler, Ranetrace included.
Reproduced on Laravel 13.45, PHP 8.5, 5 December 2026.
Related
Read more
Start monitoring today
Websites go down and code throws errors. Ranetrace tells you when it happens to yours, why it matters and what to do next.