Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions system/HTTP/ContentSecurityPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ public function getScriptNonce(): string
*/
public function finalize(ResponseInterface $response)
{
if ($this->autoNonce === false) {
return;
if ($this->autoNonce) {
$this->generateNonces($response);
}

$this->generateNonces($response);
$this->buildHeaders($response);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/system/HTTP/ContentSecurityPolicyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CodeIgniter\HTTP;

use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\TestResponse;
use Config\App;
use Config\ContentSecurityPolicy as CSPConfig;

Expand Down Expand Up @@ -533,6 +534,9 @@ public function testBodyScriptNonceDisableAutoNonce()
$csp->finalize($response);

$this->assertStringContainsString('{csp-script-nonce}', $response->getBody());

$result = new TestResponse($response);
$result->assertHeader('Content-Security-Policy');
}

public function testBodyStyleNonceDisableAutoNonce()
Expand All @@ -549,6 +553,9 @@ public function testBodyStyleNonceDisableAutoNonce()
$csp->finalize($response);

$this->assertStringContainsString('{csp-style-nonce}', $response->getBody());

$result = new TestResponse($response);
$result->assertHeader('Content-Security-Policy');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion user_guide_src/source/changelogs/v4.2.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ none.
Bugs Fixed
**********

none.
- Fixed a bug that prevents CSP headers from being sent when ``Config\ContentSecurityPolicy::$autoNonce`` is false.

See the repo's `CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_ for a complete list of bugs fixed.