Skip to content

fix(secure-headers): keep CSP callbacks scoped to their header - #5147

Merged
yusukebe merged 3 commits into
honojs:mainfrom
lasder-ca:fix/secure-headers-csp-callbacks
Jul 24, 2026
Merged

fix(secure-headers): keep CSP callbacks scoped to their header#5147
yusukebe merged 3 commits into
honojs:mainfrom
lasder-ca:fix/secure-headers-csp-callbacks

Conversation

@lasder-ca

Copy link
Copy Markdown
Contributor

Using a nonce in one CSP mode currently breaks when both contentSecurityPolicy and contentSecurityPolicyReportOnly are set.

getCSPDirectives() returns a callback that handles both CSP headers. If the other policy is static, its value has already been turned into a string, so that callback reaches clone.join() with a string and the request ends in a 500 response.

This change gives each callback the header name it belongs to and leaves the other CSP header alone. The added tests cover a static enforced policy with a report-only nonce, and nonce callbacks in both policies.

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.07%. Comparing base (cadff88) to head (c3fbfbf).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5147      +/-   ##
==========================================
+ Coverage   79.04%   79.07%   +0.03%     
==========================================
  Files         154      154              
  Lines       10779    10777       -2     
  Branches     2256     2254       -2     
==========================================
+ Hits         8520     8522       +2     
+ Misses       2259     2255       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yusukebe
yusukebe merged commit 402eb3a into honojs:main Jul 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants