CSP in Laravel: From Zero to Nonce-Based in 30 Minutes

Laravel is one of the easier frameworks to add CSP to, thanks to its middleware system and Blade templating. You can have a working nonce-based CSP policy in about 30 minutes — I’ve done it multiple times and it really is that straightforward. Here are two approaches: using the spatie package (fastest setup) and custom middleware (more control). Option 1: The spatie/laravel-csp Package If you want something that works out of the box: ...

March 29, 2026 · 4 min · headertest.com