From 7c10f5d5b3394f777c5991a2de256a50307d12c0 Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Wed, 11 Nov 2026 13:13:06 +0100 Subject: [PATCH 1/2] Assert exact CSP nonce values in controller tests Presence-only checks accepted a script carrying the style nonce and the reverse. Check every script, style and stylesheet link for its own nonce. --- .../Admin/QueuedJobsControllerTest.php | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php index a319ce2b..b48a519d 100644 --- a/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php +++ b/tests/TestCase/Controller/Admin/QueuedJobsControllerTest.php @@ -174,20 +174,36 @@ public function testStats() { } /** - * CakePHP's CspMiddleware stores the nonce as `cspScriptNonce`. + * CakePHP's CspMiddleware stores the nonces as `cspScriptNonce` and `cspStyleNonce`. * * @return void */ public function testStatsUsesCspScriptNonce(): void { Configure::write('Queue.isStatisticEnabled', true); $this->withRequestAttribute('cspScriptNonce', 'core-nonce'); + $this->withRequestAttribute('cspStyleNonce', 'style-nonce'); $this->get(['prefix' => 'Admin', 'plugin' => 'Queue', 'controller' => 'QueuedJobs', 'action' => 'stats']); $this->assertResponseCode(200); $this->assertResponseContains('