Add CSP and security headers#6
Open
rawritude wants to merge 1 commit into
Open
Conversation
Adds a Content-Security-Policy plus X-Content-Type-Options, X-Frame-Options, Referrer-Policy and Permissions-Policy to all routes. The key protection is script-src 'self' (no unsafe-inline, no external scripts), so injected script cannot execute on a site that signs wallet transactions; object-src 'none', base-uri 'self' and frame-ancestors 'none' close the common bypasses. Validated locally by serving the production build under this exact policy: every route renders clean, the wallet modal opens, and connecting a wallet and signing a transaction both work. connect-src/frame-src are kept permissive (https:/wss:) so wallet backends and popups are unaffected.
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.
Adds security headers, including a Content-Security-Policy, via Cloudflare Pages
static/_headers.Why
The site signs wallet transactions, so the highest-value hardening is preventing injected script from manipulating a transaction.
script-src 'self'(no'unsafe-inline', no external scripts) means an injected<script>— or a markup-injection bug in a dependency — cannot execute.object-src 'none',base-uri 'self'andframe-ancestors 'none'close the common bypasses and clickjacking. The other four headers are low-risk hardening.Headers (applied to
/*)Content-Security-Policy(below)X-Content-Type-Options: nosniffX-Frame-Options: DENYReferrer-Policy: no-referrerPermissions-Policydisabling unused browser featuresValidation
Built the site and served it through this exact policy locally:
The one adjustment needed was allowing
data:fonts (the bundled CSS embeds them).connect-src/frame-srcare kept permissive (https:/wss:) so wallet backends, WalletConnect relays and popups are unaffected — the protection comes fromscript-src.If you prefer a cautious rollout, rename the header to
Content-Security-Policy-Report-Onlyfirst to collect violation reports from real traffic before enforcing.