From b9cf74847a761928e363520bd4516ca5861cd70c Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Wed, 21 Feb 2024 14:03:17 +0100 Subject: [PATCH] StyleWithNonce: Don't use `nonce` for cli commands --- src/Compat/StyleWithNonce.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Compat/StyleWithNonce.php b/src/Compat/StyleWithNonce.php index f4c71851..8c1be31c 100644 --- a/src/Compat/StyleWithNonce.php +++ b/src/Compat/StyleWithNonce.php @@ -2,6 +2,7 @@ namespace ipl\Web\Compat; +use Icinga\Application\Icinga; use Icinga\Application\Version; use Icinga\Util\Csp; use ipl\Web\Style; @@ -15,9 +16,10 @@ class StyleWithNonce extends Style public function getNonce(): ?string { if ($this->nonce === null) { - $this->nonce = version_compare(Version::VERSION, '2.12.0', '>=') - ? Csp::getStyleNonce() ?? '' - : ''; + $this->nonce = ''; + if (version_compare(Version::VERSION, '2.12.0', '>=') && Icinga::app()->isWeb()) { + $this->nonce = Csp::getStyleNonce() ?? ''; + } } return parent::getNonce();