Skip to content

fix: Hardcoded CSP Nonce Tags in ResponseTrait#9937

Open
patel-vansh wants to merge 5 commits intocodeigniter4:developfrom
patel-vansh:fix/hardcoded-csp-tags
Open

fix: Hardcoded CSP Nonce Tags in ResponseTrait#9937
patel-vansh wants to merge 5 commits intocodeigniter4:developfrom
patel-vansh:fix/hardcoded-csp-tags

Conversation

@patel-vansh
Copy link
Contributor

Description
This PR fixes #9935.

Created one method in system/HTTP/ContentSecurityPolicy.php to clear all nonce placeholders.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 8, 2026
Copy link
Member

@paulbalandan paulbalandan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests don't make sense. You should be testing instead the behavior when the response is sent when CSP is not enabled.

$this->{$this->directives[$directive]} = [];
}

public function clearNoncePlaceholders(string $text): string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This can go instead in the generateNonces method in the preg_replace_callback so that if $CSPEnabled is false it just returns ''.
  • In buildHeaders, if CSP is disabled, just return
  • In ResponseTrait, remove the conditional and retain the finalize call.

$this->assertNotContains('report-to default', $directives);
}

public function testClearNoncePlaceholdersWithDefaultTags(): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these tests down and replace with the ones you have in ResponseTest but tailor it to be like in the majority of the tests here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Hardcoded CSP Nonce Tags in ResponseTrait

3 participants