Allow for the usage of {style_nonce} in the custom CSP-Header setting

This commit is contained in:
Alexander Rieß 2026-03-12 13:18:24 +01:00
parent 4586f2fc9e
commit f692db5387

View file

@ -157,12 +157,26 @@ class Csp
{
$config = Config::app();
if ($config->get('security', 'use_custom_csp', 'y') === 'y') {
return $config->get('security', 'custom_csp', '');
return self::getCustomContentSecurityPolicy();
}
return self::getAutomaticContentSecurityPolicy();
}
public static function getCustomContentSecurityPolicy(): ?string
{
$csp = static::getInstance();
if (empty($csp->styleNonce)) {
throw new RuntimeException('No nonce set for CSS');
}
$config = Config::app();
$raw = $config->get('security', 'custom_csp');
$formated = str_replace('{style_nonce}', "'nonce{$csp->styleNonce}'", $raw);
return $formated;
}
/**
* Get the automatically generated Content-Security-Policy.
*