Skip to content

Conversation

@michalsn
Copy link
Member

@michalsn michalsn commented Feb 8, 2026

Description
This PR fixes a bug where ContentSecurityPolicy::generateNonces() could corrupt the JSON response body.

The method now detects application/json Content-Type responses and properly escapes double quotes in nonce attribute replacements, preventing malformed JSON.

Fixes #9934

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
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
@michalsn michalsn merged commit a58efe3 into codeigniter4:develop Feb 10, 2026
50 checks passed
@michalsn
Copy link
Member Author

Thank you @paulbalandan and @datamweb

@michalsn michalsn deleted the fix/csp-json-escape branch February 10, 2026 16:56
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: CSP nonce replacement corrupts JSON responses in AJAX requests

3 participants