spatie/laravel-csp
Add Content Security Policy (CSP) headers to your Laravel app with easy configuration and preset policies. Control which scripts, styles, images, and connections are allowed, reduce XSS/data exfiltration risk, and support reporting and nonces.
Google, Stripe, Hotjar) reduces boilerplate for common integrations, while the ability to define custom presets or directives ensures flexibility for niche use cases.report-uri or Report-To headers, enabling monitoring (e.g., via Report URI) without additional infrastructure.report-only mode before enforcement.nonce_enabled: false) weakens security.unsafe-eval or unsafe-inline fallbacks.unsafe-* directives?report-only mode be used for validation before enforcement?spatie/laravel-honeypot, owasp/csp).report-only mode (report_only_presets) to test policies without enforcement.php artisan vendor:publish --tag=csp-config) and customize presets/directives.Basic preset + Google for analytics, then add custom directives.AddCspHeaders globally or per route/group. Example:
->withMiddleware(AddCspHeaders::class);
@cspMetaTag for meta-based CSP.report-only violations via the configured endpoint.report-only to enforcement mode.AddCspHeaders runs after TrustProxies if behind a proxy.Cache-Control) don’t interfere with dynamic policies.report-only presets and monitor violations.config/csp.php, reducing runtime complexity. Changes require config updates + optional middleware adjustments.report-only mode to debug violations without breaking the app.report-only, gradually tighten policies.@cspNonce in Blade or JS.AddCspHeaders runs after other middleware that might modify headers.## CSP Policy
- **Enforcement**: Enabled globally (except `/admin` routes).
- **Presets**: `Basic`, `Google`, `Stripe`.
- **Reporting**: Violations sent to `https://report-uri.com/...`.
- **Nonces**: Used for dynamic scripts in `resources/js/app.js`.
How can I help you explore Laravel packages today?