From cdc7106ff8c40ce9556ee78f0b92f2ebabfc0800 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sun, 1 Feb 2026 19:13:06 +0800 Subject: [PATCH] fix: ensure CSP nonces are Base64 encoded --- system/HTTP/ContentSecurityPolicy.php | 4 ++-- tests/system/CommonFunctionsTest.php | 4 ++-- tests/system/HTTP/ContentSecurityPolicyTest.php | 14 ++++++++------ tests/system/Helpers/HTMLHelperTest.php | 2 +- tests/system/Helpers/URLHelper/MiscUrlTest.php | 2 +- tests/system/Honeypot/HoneypotTest.php | 2 +- tests/system/View/ParserPluginTest.php | 2 +- user_guide_src/source/changelogs/v4.6.5.rst | 1 + 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/system/HTTP/ContentSecurityPolicy.php b/system/HTTP/ContentSecurityPolicy.php index a6a2b26a71fc..4767face673e 100644 --- a/system/HTTP/ContentSecurityPolicy.php +++ b/system/HTTP/ContentSecurityPolicy.php @@ -303,7 +303,7 @@ public function enabled(): bool public function getStyleNonce(): string { if ($this->styleNonce === null) { - $this->styleNonce = bin2hex(random_bytes(12)); + $this->styleNonce = base64_encode(random_bytes(12)); $this->styleSrc[] = 'nonce-' . $this->styleNonce; } @@ -316,7 +316,7 @@ public function getStyleNonce(): string public function getScriptNonce(): string { if ($this->scriptNonce === null) { - $this->scriptNonce = bin2hex(random_bytes(12)); + $this->scriptNonce = base64_encode(random_bytes(12)); $this->scriptSrc[] = 'nonce-' . $this->scriptNonce; } diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index bc09ef6e9f57..d84378e01dc9 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -731,7 +731,7 @@ public function testDWithCSP(): void $cliDetection = Kint::$cli_detection; Kint::$cli_detection = false; - $this->expectOutputRegex('/