Laravel 11 - Disable CSRF for a route

Laravel 11 - Disable CSRF for a route

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Laravel 11 - Disable CSRF for a route

In Laravel 11, the architecture surrounding CSRF protection has shifted significantly from previous versions. If you are maintaining a legacy webhook endpoint that previously relied on adding exceptions to the $except property within App\Http\Middleware\VerifyCsrfToken, you will immediately hit a wall when upgrading. That specific middleware class no longer exists in the default kernel configuration for Laravel 11, and the mechanism for disabling CSRF protection has been streamlined into the router itself.

The error code 419 (Throttle: Maximum request attempts exceeded) or similar CSRF failures indicate that Laravel is intercepting your incoming request before it reaches your controller logic. This happens because Laravel defaults to enforcing CSRF validation on all POST, PUT, PATCH, and DELETE requests unless explicitly told otherwise. For a webhook endpoint receiving data from an external service, you generally do not want to enforce this check, as the remote service will not possess your shared secret token.

To resolve this in Laravel 11, you need to register the route with the withoutCsrf() middleware group when defining it in your routes/web.php or routes/api.php file. This approach is more robust than relying on a global exception list because it scopes the exemption strictly to the specific endpoint requiring it.

Here is how you should define your webhook route:

use Illuminate\Support\Facades\Route;

Route::post('/webhook', [WebhookController::class, 'handle'])
    ->withoutCsrf()
    ->name('webhook');

By attaching the withoutCsrf modifier directly to the route definition, you tell Laravel's routing engine to skip the CSRF guard for this specific path. This ensures that when the remote service sends a POST request with a payload, Laravel accepts it immediately without attempting to validate the X-CSRF-TOKEN header or check the _csrf token in your session.

There are important trade-offs and considerations when implementing this pattern. Disabling CSRF protection on an endpoint effectively opens that specific URL to any client making a valid HTTP request. While webhooks are designed for external calls, you must ensure that your application's authentication and authorization logic inside the controller (e.g., checking API keys or signature verification) remains intact. Relying solely on disabling the middleware does not secure the endpoint against malicious actors; it merely removes the automatic token validation layer. If your webhook handler lacks its own security checks, an attacker could trigger your logic simply by sending a POST request to that URL.

Additionally, be mindful of how this interacts with other middleware. The withoutCsrf flag only affects the CSRF guard. Other middleware groups like throttle, auth, or custom logging logic will still apply unless you explicitly exclude them as well. In many webhook scenarios, you might also want to remove rate limiting if the external service sends rapid bursts of data that could otherwise trigger a 429 Too Many Requests error.

Route::post('/webhook', [WebhookController::class, 'handle'])
    ->withoutCsrf()
    ->withoutMiddleware(\Illuminate\Routing\Middleware\ThrottleRequests::class)
    ->name('webhook');

This configuration pattern ensures that your external service can communicate reliably without hitting token validation errors or rate limits. Always verify the behavior of your specific remote service against Laravel's default middleware stack to avoid unexpected failures after an upgrade. For more detailed guidance on securing routes and managing middleware in newer Laravel versions, you might want to consult resources like https://laravelcompany.com to ensure your implementation aligns with best practices for modern framework versions.

Our network