Laravel answers a form or AJAX call with 419 Page Expired
419 | Page ExpiredShort answer
Laravel could not match the CSRF token in your request to the one stored in the visitor's session. Either the request carried no token, or the session it belongs to was not found. Add @csrf or the token header, make sure the session is saved and its cookie comes back, and never cache pages that contain forms. Do not switch CSRF off.
Fix it fast
1Find out which cause you have
Find out whether the request carried a token and whether the session cookie came back. Open DevTools, Network tab, the failing request: look for the _token form field (or an X-CSRF-TOKEN or X-XSRF-TOKEN header) and for the session cookie in the request headers. Then check what the server hands out.
# does a fresh visit receive a session cookie and an XSRF-TOKEN cookie? curl -s -o /dev/null -D - -c /dev/stdout https://example.com/login | grep -iE "set-cookie|laravel|xsrf"2Match what you see, then jump to its fix
- 1
The failing request has no _token field and no X-CSRF-TOKEN or X-XSRF-TOKEN header.The form or the AJAX call sends no tokenFix - 2
Every request gets a new session cookie value, or storage/logs shows a database or permission error, or the error appears only on some servers behind a load balancer.The session cannot be stored, or is stored somewhere the next request does not lookFix - 3
The cookie is set (a Set-Cookie header is visible) but is missing from the next request, or DevTools shows it as blocked; typical after moving to HTTPS, a new domain or an iframe.The browser does not send the session cookie backFix - 4
The first submit after a long pause, or after login or logout in another tab, fails; the page source shows the same token for different visitors; curl shows Age or X-Cache headers on the form page.A cached page or an expired session holds an old tokenFix - 5
Only calls from another service (Stripe, a payment gateway, a mobile app, a script) get 419, and the route lives in routes/web.php.A webhook or outside client posts to a web routeFix
- 1
What does the error look like?
419 | Page Expired419 Page Expired (a POST, PUT, PATCH or DELETE request)CSRF token mismatch.message: "CSRF token mismatch." in a JSON response to an AJAX or fetch call
Cause 1 of 5
The form or the AJAX call sends no token
1Check
Laravel checks every POST, PUT, PATCH and DELETE request that goes through the web middleware group for a token in the request input or in a header. A hand-written form, a Blade file without the directive, or a JS call without the header is enough.
curl -s https://example.com/profile | grep -iE "name=.?_token|csrf-token"
grep -rn "<form" resources/views | grep -iv "csrf" | head2Fix
Put @csrf in every form that is not a GET form. For fetch or axios calls, put the token in a meta tag and send it in the X-CSRF-TOKEN header. Axios from the default Laravel scaffolding already sends the X-XSRF-TOKEN header from the XSRF-TOKEN cookie on same-origin requests.
{{-- form.blade.php --}}
<form method="POST" action="/profile">
@csrf
...
</form>
{{-- layout head --}}
<meta name="csrf-token" content="{{ csrf_token() }}">
// fetch
await fetch('/profile', {
method: 'POST',
headers: {
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
'Content-Type': 'application/json',
},
body: JSON.stringify({ name: 'Ada' }),
})3Verify
The request in the Network tab shows the token, and the response is the page you expect instead of 419.
curl -s https://example.com/profile | grep -ic "name=.\?_token"Confirmed by laravel.com
Cause 2 of 5
The session cannot be stored, or is stored somewhere the next request does not look
1Check
The token lives in the session. The default driver is database, which needs a sessions table; the file driver writes to storage/framework/sessions, which the web server's user must be able to write to; a file driver on several servers gives each server its own sessions.
grep -E "^SESSION_" .env
php artisan migrate:status | grep -i session
ls -ld storage/framework/sessions
tail -n 20 storage/logs/laravel.log2Fix
Create the missing table, fix ownership of the writable folders, or move to a shared driver such as redis or the database when more than one server answers. Clear a cached config after changing .env.
php artisan make:session-table
php artisan migrate
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R ug+rwX storage bootstrap/cache
php artisan config:clear3Verify
Two requests in a row send and receive the same session cookie value, and a form post succeeds.
curl -s -c jar.txt -o /dev/null https://example.com/login && curl -s -b jar.txt -c jar.txt -o /dev/null https://example.com/login && cat jar.txtConfirmed by laravel.com
Cause 3 of 5
The browser does not send the session cookie back
1Check
SESSION_SECURE_COOKIE=true makes the browser return the cookie only over HTTPS, so it is lost on a plain http address. SESSION_DOMAIN must match the host being visited; leaving it unset ties the cookie to the current host. SESSION_SAME_SITE defaults to lax, which blocks the cookie in cross-site embeds and POSTs from other sites.
grep -E "^(APP_URL|SESSION_DOMAIN|SESSION_SECURE_COOKIE|SESSION_SAME_SITE)=" .env
curl -sI https://example.com/login | grep -i "^set-cookie"2Fix
Make the settings match how the site is reached. Use HTTPS with SESSION_SECURE_COOKIE=true in production; leave SESSION_DOMAIN unset unless subdomains must share a session, and then set it to the shared parent domain. If the app is truly embedded cross-site, SameSite=none works only together with a secure cookie.
# .env, production on HTTPS
APP_URL=https://example.com
SESSION_SECURE_COOKIE=true
SESSION_SAME_SITE=lax
# SESSION_DOMAIN=.example.com # only when subdomains share the login
php artisan config:clear3Verify
The session cookie appears in the request headers of the next page and the post goes through.
curl -sI https://example.com/login | grep -iE "^set-cookie" | grep -iE "secure|samesite"Confirmed by github.com
Cause 4 of 5
A cached page or an expired session holds an old token
1Check
A token belongs to one session and changes when the session is regenerated. A page cached by a CDN, a page-cache plugin or the browser's back button can carry a token that is no longer valid, and sessions end after the lifetime set in SESSION_LIFETIME (120 minutes by default).
curl -sI https://example.com/contact | grep -iE "^(cache-control|age|x-cache|cf-cache-status)"
grep -E "^SESSION_LIFETIME" .env2Fix
Do not cache pages that include forms or tokens: exclude them in the CDN or page cache and send a no-store header. For long-lived forms, refresh the token with a small request, or catch the 419 and ask the user to reload instead of losing their input.
// routes/web.php
Route::get('/contact', fn () => response()
->view('contact')
->header('Cache-Control', 'no-store, private'));3Verify
The page response carries no-store and no cache hit headers, and different visitors get different tokens.
curl -sI https://example.com/contact | grep -i "^cache-control"Confirmed by laravel.com
Cause 5 of 5
A webhook or outside client posts to a web route
1Check
Those callers cannot know a visitor's session token. Routes in routes/web.php get CSRF checking and sessions; outside callers belong on routes that do not use them and that are authenticated another way (API tokens, signed webhooks).
php artisan route:list --path=webhook
grep -n "webhook" routes/web.php2Fix
Move the endpoint to routes/api.php, or exclude only that URI from the check. Verify the caller another way, for example by the provider's signature. Never exclude everything. Laravel 12 uses validateCsrfTokens, Laravel 13 uses preventRequestForgery.
// bootstrap/app.php, Laravel 12
->withMiddleware(function (Middleware $middleware): void {
$middleware->validateCsrfTokens(except: ['stripe/*']);
})
// bootstrap/app.php, Laravel 13
->withMiddleware(function (Middleware $middleware): void {
$middleware->preventRequestForgery(except: ['stripe/*']);
})3Verify
The provider's test delivery gets a 2xx response, while a normal form post without a token still gets 419.
curl -s -o /dev/null -w "%{http_code}\n" -X POST https://example.com/profile # expect 419Confirmed by laravel.com
How do I stop it coming back?
- Use @csrf in every non-GET form and keep the csrf-token meta tag in the layout for JS calls.
- Run production on HTTPS with a secure session cookie, and keep sessions in a store every app server can reach.
- Keep pages with forms out of every cache layer.
- Exclude specific webhook URIs, never the whole application, and verify those callers some other way.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
Related fixes
Security
An HTTPS page is blocked from loading an insecure http:// resource
Mixed Content: The page at 'https://example.com/' was loaded over HTTPS, but attempted to connect to the insecure endpoint 'http://api.example.com/items'. This request has been blocked.
Your page came over HTTPS but something on it points at an http:// address, and the browser refuses the risky kinds (scripts, styles, frames, fetch calls).
4 causes, each with a fixSecurity
PHP LDAP in Laravel fails with Can't contact LDAP server over TLS
unable to get local issuer certificate
PHP's LDAP client uses OpenLDAP's settings.
3 causes, each with a fixBack end
Laravel says Class "Redis" not found when using phpredis
Class 'Redis' not found
Laravel uses the phpredis PHP extension by default, so a missing or disabled extension gives Class "Redis" not found.
3 causes, each with a fixBack end
A Laravel queue job times out, the worker exits or the job runs twice
Illuminate\Queue\MaxAttemptsExceededException
A Laravel queue worker stops any job that runs longer than its timeout, 60 seconds by default, and exits with an error.
4 causes, each with a fixSecurity
The browser warns about a SameSite cookie set from PHP
A cookie with SameSite=None is rejected because it lacks the Secure attribute
A cookie sent without a SameSite attribute gets the browser's default, and a cookie marked None is dropped unless it is also Secure.
4 causes, each with a fixSecurity
Is my PHP application affected by PHP2Shell, and how do I mitigate it?
A scanner or advisory feed reports CVE-2026-109619 (RCE via stale global state) on your server
You are exposed when the PHP serving web requests is older than 8.2.35, 8.3.36, 8.4.27 or 8.5.12 on its branch, or when a distribution package is older than its vendor's fixed build.
6 causes, each with a fix