From 9c524f9932906f3f780315e69090ef81d3572ba5 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 8 Sep 2023 10:48:41 +0200 Subject: [PATCH 1/2] Style: Use `getNonce()` instead of accessing `$nonce` directly --- src/Style.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); } From f1400c80b522b02f01ea987e815878df13cc3f87 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 8 Sep 2023 10:49:31 +0200 Subject: [PATCH 2/2] Introduce class `ipl\Web\Compat\StyleWithNonce` --- src/Compat/StyleWithNonce.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Compat/StyleWithNonce.php 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(); + } +}