Skip to content

Commit 8e19e05

Browse files
committed
Fix /!/nocache and /!/csrf CSRF exemption on Laravel 13
Laravel 13 renamed the CSRF middleware from ValidateCsrfToken to Illuminate\Foundation\Http\Middleware\PreventRequestForgery. The legacy VerifyCsrfToken and ValidateCsrfToken classes are now @deprecated subclasses of PreventRequestForgery. The route exemptions here use withoutMiddleware([VerifyCsrfToken]), and Laravel's Router::resolveMiddleware excludes via ReflectionClass::isSubclassOf — but PreventRequestForgery is the *parent* of the listed classes, not a subclass, so the check returns false and the exemption is a no-op. The CSRF check fires on the unauthenticated POST and Laravel throws TokenMismatchException, so the client-side nocache bootstrap cannot hydrate regions under full static caching, and /!/csrf cannot refresh the token either. Adding PreventRequestForgery to both lists fixes Laravel 13 while keeping the existing entries for Laravel 10-12 compatibility via the deprecated aliases.
1 parent d5fb7ed commit 8e19e05

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

routes/web.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@
9898

9999
Route::post('nocache', NoCacheController::class)
100100
->middleware(NoCacheLocalize::class)
101-
->withoutMiddleware(['App\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken'])
101+
->withoutMiddleware(['App\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\PreventRequestForgery'])
102102
->name('nocache');
103103

104104
Route::post('csrf', CsrfTokenController::class)
105-
->withoutMiddleware(['App\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken']);
105+
->withoutMiddleware(['App\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken', 'Illuminate\Foundation\Http\Middleware\PreventRequestForgery']);
106106

107107
Statamic::additionalActionRoutes();
108108
});

0 commit comments

Comments
 (0)