If you're seeing:
419 Page Expired
CSRF token mismatch
orTokenMismatchException
You're not alone.
This is one of the most common Laravel errors — especially when working with forms, authentication, AJAX requests, or after deployment.
In this step-by-step guide, you’ll learn:
-
What CSRF protection is in Laravel
-
Why the 419 error happens
-
How to fix CSRF token mismatch properly
-
Production deployment pitfalls
-
Livewire & AJAX issues
-
When (and when not) to disable CSRF protection
Let’s debug this correctly.
What Is CSRF Protection in Laravel?
CSRF stands for Cross-Site Request Forgery.
It’s a security mechanism that prevents malicious websites from performing actions on behalf of authenticated users.
Laravel enables CSRF protection by default using middleware:
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class
Whenever you submit a POST, PUT, PATCH, or DELETE request, Laravel checks:
-
Does this request contain a valid CSRF token?
-
Does the token match the session?
If not, Laravel blocks the request and throws:
419 Page Expired
CSRF Token Mismatch
This is expected behavior — not a bug.
Why You’re Getting “Laravel CSRF Token Mismatch”
Here are the most common causes:
-
Missing
@csrfin Blade form -
Expired session
-
AJAX request without CSRF header
-
Domain mismatch (http vs https)
-
Session driver misconfiguration
-
Cache/config not cleared after deployment
-
SPA misconfiguration
-
Load balancer or proxy cookie issues
Let’s fix them one by one.
Fix #1 – Missing @csrf in Blade Form
This is the most common cause.
If your form looks like this:
<form method="POST" action="/submit">
<input type="text" name="name">
</form>
It will fail.
Correct version:
<form method="POST" action="/submit">
@csrf
<input type="text" name="name">
</form>
@csrf generates a hidden token field:
<input type="hidden" name="_token" value="...">
Without this token, Laravel rejects the request.
Fix #2 – CSRF Token Mismatch in AJAX Requests
If you're using Axios, Fetch API, or jQuery, you must send the token in headers.
First, ensure this meta tag exists in your layout:
<meta name="csrf-token" content="{{ csrf_token() }}">
Then configure Axios:
axios.defaults.headers.common['X-CSRF-TOKEN'] =
document.querySelector('meta[name="csrf-token"]').getAttribute('content');
Without this header:
-
Laravel receives no token
-
Middleware blocks request
-
419 error appears
Fix #3 – Session Expired or SESSION_DRIVER Issue
Laravel stores CSRF tokens inside sessions.
If your session expires, the token becomes invalid.
Check your .env:
SESSION_DRIVER=file
SESSION_LIFETIME=120
If using Redis or database sessions, confirm:
-
Redis is running
-
Database session table exists
-
Session driver matches production environment
Clear cache after changes:
php artisan config:clear
php artisan cache:clear
php artisan route:clear
Deployment without clearing cache frequently causes 419 errors.
Fix #4 – CSRF Token Mismatch After Deployment
If it works locally but fails on production, check:
1. APP_URL mismatch
APP_URL=https://yourdomain.com
If your site uses HTTPS but APP_URL is HTTP, cookies may not match.
2. HTTPS & Secure Cookies
If using HTTPS, set:
SESSION_SECURE_COOKIE=true
Otherwise, cookies may not persist correctly.
3. Proxy or Load Balancer Issues
If using Nginx + reverse proxy:
Ensure forwarded headers are handled properly.
Laravel needs correct request scheme detection.
Fix #5 – CSRF Token Mismatch in Livewire
If you're using Livewire, CSRF is handled automatically.
Common mistakes:
-
Missing
<livewire:scripts /> -
Missing
<livewire:styles /> -
Cached config after deployment
-
Session not persisting
Livewire relies on session + CSRF.
Clear cache:
php artisan view:clear
php artisan config:clear
Fix #6 – SPA or Sanctum Configuration Issues
If you're using Laravel Sanctum with SPA:
Check:
SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1,yourdomain.com
SESSION_DOMAIN=.yourdomain.com
Common issue:
Frontend domain ≠ backend domain
Result:
Cookies not shared → CSRF mismatch.
Fix #7 – Should You Disable CSRF Protection?
Sometimes developers try this:
protected $except = [
'*'
];
Do NOT do this.
Only exclude specific webhook routes:
protected $except = [
'webhook/*',
];
Disabling CSRF globally removes important security protection.
Laravel 419 Error Debugging Checklist
If you're stuck, follow this structured checklist:
✔ Add @csrf to Blade forms
✔ Verify meta CSRF token tag
✔ Confirm Axios header setup
✔ Check SESSION_DRIVER
✔ Increase SESSION_LIFETIME
✔ Clear config/cache
✔ Verify HTTPS configuration
✔ Confirm APP_URL matches domain
✔ Check Sanctum configuration
✔ Inspect browser cookies
This methodical approach solves most 419 errors.
Why Laravel Shows “419 Page Expired”
Technically, Laravel returns HTTP 419 when:
-
Token does not match session
-
Token missing
-
Session expired
It is not a server crash like a 500 error.
It is a security validation failure.
When to Seek Professional Help
If your Laravel app:
-
Works locally but fails in production
-
Has inconsistent CSRF behavior
-
Breaks after deployment
-
Fails behind reverse proxy
The issue may involve:
-
Server configuration
-
Cookie domain mismatch
-
HTTPS enforcement
-
Load balancer misconfiguration
In such cases, structured debugging is required.
Frequently Asked Questions (FAQ)
Why does Laravel show 419 Page Expired?
Laravel returns 419 when the CSRF token is missing or invalid. This usually happens due to missing @csrf, expired sessions, or incorrect cookie configuration.
How do I fix CSRF token mismatch in Laravel?
Add @csrf to forms, ensure CSRF meta tag exists, configure Axios headers, verify session driver, and clear cache after deployment.
Can I disable CSRF protection in Laravel?
You can exclude specific routes (like webhooks), but disabling CSRF globally is not recommended due to security risks.
Why does CSRF work locally but not in production?
Common causes include:
-
APP_URL mismatch
-
HTTPS cookie issues
-
Session driver differences
-
Cache not cleared
-
Proxy misconfiguration
user@blog:~$ ls related-articles
How to Fix 500 Server Error in Laravel (Step-by-Step Debugging Guide)
Debug production crashes, log issues, and server misconfigurations in Laravel applications.
Laravel Livewire Performance Optimization (Real Production Fixes)
Improve session handling, optimize components, and fix production bottlenecks.
Laravel Sanctum API Authentication (Full Guide)
Secure APIs properly and understand how CSRF interacts with authentication.
How to Create a Livewire Component in Laravel 12
Build reactive form components correctly with proper CSRF handling.