The config/csp.php file allows you to define presets, global directives, reporting endpoints, and nonce settings.
Key configuration options include:
presets: An array of classes implementing Spatie\Csp\Preset that determine which headers are set.directives: Global CSP directives to add to the policy.report_only_presets: Presets used for a report-only policy (useful for testing without breaking functionality).report_uri: The URL where violations are reported (e.g., via https://report-uri.com/).enabled: Boolean to enable or disable CSP headers globally.nonce_enabled: Boolean to enable/disable automatic nonce generation.
return [
'presets' => [
Spatie\Csp\Presets\Basic::class,
],
'directives' => [
// [Directive::SCRIPT, [Keyword::UNSAFE_EVAL, Keyword::UNSAFE_INLINE]],
],
'report_only_presets' => [],
'report_only_directives' => [],
'report_uri' => env('CSP_REPORT_URI', ''),
'report_only_uri' => env('CSP_REPORT_ONLY_URI', ''),
'report_to' => env('CSP_REPORT_TO', ''),
'report_only_to' => env('CSP_REPORT_ONLY_TO', ''),
'reporting_endpoints' => [],
'enabled' => env('CSP_ENABLED', true),
'enabled_while_hot_reloading' => env('CSP_ENABLED_WHILE_HOT_RELOADING', false),
'nonce_generator' => Spatie\Csp\Nonce\RandomString::class,
'nonce_enabled' => env('CSP_NONCE_ENABLED', true),
];