statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
4.12k stars 540 forks source link

419 errors using the nocache tag #10068

Closed robdekort closed 6 months ago

robdekort commented 6 months ago

Bug description

On two v5 sites where I use the nocache tag I get 419 console errors on the /!/nocache route. This leads to the content not being rendered on production sites.

How to reproduce

Use nocache with static caching

Logs

No response

Environment

Environment
Laravel Version: 11.7.0
PHP Version: 8.2.18
Composer Version: 2.7.6
Environment: staging
Debug Mode: OFF
Maintenance Mode: OFF

Cache
Config: CACHED
Events: NOT CACHED
Routes: CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: redis
Session: file

Livewire
Livewire: v3.4.12

Statamic
Addons: 8
Sites: 1
Stache Watcher: Disabled
Static Caching: full
Version: 5.0.2 PRO

Statamic Addons
jacksleight/statamic-bard-mutator: 2.3.1
jonassiewertsen/statamic-livewire: 3.3.1
rias/statamic-color-swatches: 2.3.0
stillat/relationships: 2.2.0
studio1902/statamic-peak-browser-appearance: 3.4.0
studio1902/statamic-peak-commands: 8.3.0
studio1902/statamic-peak-seo: 8.13.2
studio1902/statamic-peak-tools: 6.0.0

Installation

Starter Kit using via CLI

Additional details

No response

duncanmcclean commented 6 months ago

I've opened a PR to fix the issue which should hopefully be released soon. In the meantime, you can add this to your bootstrap/app.php file:

->withMiddleware(function (Middleware $middleware) {
    $middleware->validateCsrfTokens(except: [
        '!/nocache',
    ]);
})
robdekort commented 6 months ago

Amazing. Thanks for this. The workaround works.