Skip to content

fix(security): cover inline scripts with CSP nonces and hashes - #662

Open
Mainnet-ops wants to merge 1 commit into
SmartDropLabs:mainfrom
works-days-101010:fix/csp-inline-script-nonces-hashes
Open

Mainnet-ops wants to merge 1 commit into
SmartDropLabs:mainfrom
works-days-101010:fix/csp-inline-script-nonces-hashes

Conversation

@Mainnet-ops

Copy link
Copy Markdown

Inline scripts were not covered by the Content-Security-Policy:

  • Server mode: the middleware generated a nonce but only forwarded it as x-nonce. Next.js reads the nonce from the request's Content-Security-Policy header, so its own inline scripts (RSC payload, bootstrap) were emitted without a nonce. The middleware now forwards the CSP on the request headers.
  • Static export: the CSP from next.config.ts had a bare script-src 'self' with no nonce or hash for any inline script. A new post-build step (scripts/csp-hash-inline-scripts.mjs, run by npm run build when NEXT_EXPORT=true) hashes every inline <script> in each exported page and adds its 'sha256-…' source to that page's meta CSP.

The policy is now built in one place (src/config/csp.ts) and used by both next.config.ts and the middleware, so the two can't drift apart. 'unsafe-inline' is never allowed for scripts.

Closes #640
Closes #641
Closes #643
Closes #644

Inline scripts were not covered by the Content-Security-Policy:

- Server mode: the middleware generated a nonce but only forwarded it as
  `x-nonce`. Next.js reads the nonce from the request's
  Content-Security-Policy header, so its own inline scripts (RSC payload,
  bootstrap) were emitted without a nonce. The middleware now forwards the
  CSP on the request headers.
- Static export: the <meta> CSP from next.config.ts had a bare
  `script-src 'self'` with no nonce or hash for any inline script. A new
  post-build step (scripts/csp-hash-inline-scripts.mjs, run by
  `npm run build` when NEXT_EXPORT=true) hashes every inline <script> in
  each exported page and adds its 'sha256-…' source to that page's meta CSP.

The policy is now built in one place (src/config/csp.ts) and used by both
next.config.ts and the middleware, so the two can't drift apart.
'unsafe-inline' is never allowed for scripts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@Mainnet-ops Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@netlify

netlify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for spiffy-melomakarona-eb1e8a failed.

Name Link
🔨 Latest commit 3b9702b
🔍 Latest deploy log https://app.netlify.com/projects/spiffy-melomakarona-eb1e8a/deploys/6ad3af05b68f0e44a5a67e4f

@netlify

netlify Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

❌ Deploy Preview for smart-drop failed.

Name Link
🔨 Latest commit 3b9702b
🔍 Latest deploy log https://app.netlify.com/projects/smart-drop/deploys/6ad3af059a970e3fc94347f9

This branch has not been deployed

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

Labels

None yet

Projects

None yet

1 participant