diff --git a/src/Compat/StyleWithNonce.php b/src/Compat/StyleWithNonce.php new file mode 100644 index 00000000..f4c71851 --- /dev/null +++ b/src/Compat/StyleWithNonce.php @@ -0,0 +1,25 @@ +nonce === null) { + $this->nonce = version_compare(Version::VERSION, '2.12.0', '>=') + ? Csp::getStyleNonce() ?? '' + : ''; + } + + return parent::getNonce(); + } +} diff --git a/src/Style.php b/src/Style.php index 9c020d74..56479d02 100644 --- a/src/Style.php +++ b/src/Style.php @@ -102,7 +102,7 @@ public function render(): string return (new HtmlElement( 'style', - (new Attributes())->addAttribute(new Attribute('nonce', $this->nonce)), + (new Attributes())->addAttribute(new Attribute('nonce', $this->getNonce())), HtmlString::create($ruleset->renderCss()) ))->render(); }