Skip to content

Commit 9140041

Browse files
committed
fix: CSP header is not emitted when $autoNonce is false
1 parent ca4fde6 commit 9140041

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

system/HTTP/ContentSecurityPolicy.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,10 @@ public function getScriptNonce(): string
300300
*/
301301
public function finalize(ResponseInterface $response)
302302
{
303-
if ($this->autoNonce === false) {
304-
return;
303+
if ($this->autoNonce) {
304+
$this->generateNonces($response);
305305
}
306306

307-
$this->generateNonces($response);
308307
$this->buildHeaders($response);
309308
}
310309

tests/system/HTTP/ContentSecurityPolicyTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@ public function testBodyScriptNonceDisableAutoNonce()
533533
$csp->finalize($response);
534534

535535
$this->assertStringContainsString('{csp-script-nonce}', $response->getBody());
536+
537+
$result = new \CodeIgniter\Test\TestResponse($response);
538+
$result->assertHeader('Content-Security-Policy');
536539
}
537540

538541
public function testBodyStyleNonceDisableAutoNonce()
@@ -549,6 +552,9 @@ public function testBodyStyleNonceDisableAutoNonce()
549552
$csp->finalize($response);
550553

551554
$this->assertStringContainsString('{csp-style-nonce}', $response->getBody());
555+
556+
$result = new \CodeIgniter\Test\TestResponse($response);
557+
$result->assertHeader('Content-Security-Policy');
552558
}
553559

554560
/**

0 commit comments

Comments
 (0)