fix(security): strict CSP with SRI — script-src 'self' without unsafe-inline - #311
Merged
Conversation
…-inline Enable Next.js experimental Subresource Integrity (SRI) to generate SHA-256 hashes for all JS bundles at build time. Browsers verify file integrity via the integrity attribute, so the CSP can use script-src 'self' without 'unsafe-inline' — any attacker-injected inline script is blocked. Upgrade the CSP from the previous frame-ancestors-only policy to a full directive set: default-src, script-src, style-src, img-src, font-src, connect-src, object-src, base-uri, form-action, frame-ancestors, and upgrade-insecure-requests. Development adds 'unsafe-eval' (React DevTools); production has neither 'unsafe-inline' nor 'unsafe-eval' for scripts. SRI preserves static generation, ISR, and CDN caching — no nonce or dynamic rendering required, zero performance impact. This closes the audit V2 finding: the wallet stores posting keys in localStorage and active/owner keys in Redux memory, so a strict script-src is critical defense-in-depth against XSS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes audit V2 finding V2-14 (Low): the app had no
script-srcCSP — onlyframe-ancestors 'none'. For a wallet that stores posting keys inlocalStorageand active/owner keys in Redux memory, any XSS = key exfiltration with no CSP backstop.Approach: Subresource Integrity (SRI)
Next.js experimental SRI generates SHA-256 hashes for all JS bundles at build time. Browsers verify integrity via
<script integrity="sha256-...">attributes, soscript-src 'self'suffices — nounsafe-inlineneeded.Why SRI over nonce-based CSP:
next.config.tssrc/proxy.ts, but SRI avoids the dynamic-rendering penaltyChanges (
next.config.tsonly)experimental.sri.algorithm: 'sha256'frame-ancestors 'none'to full policy:'unsafe-eval'(React DevTools); production has neither.Verification
<script>tag in build output hasintegrity="sha256-..."attributeTrade-offs
frame-ancestors-only policy with no regressionTest plan
pnpm type-check— cleanpnpm lint— 0 errorspnpm test— 477 passedpnpm build— succeeds, SRI integrity attributes present in output