fix: relax CSP to allow SvelteKit bootstrap and Cloudflare edge scripts#20
Merged
Conversation
The strict default-src 'self' policy blocked three categories of content that cannot be handled with build-time hashes: - SvelteKit's inline bootstrap script in index.html - Scripts injected by Cloudflare at the edge (Web Analytics, etc.) whose content is unknown at build time — once any hash appears in script-src, browsers ignore 'unsafe-inline', so hash mode is not a viable escape hatch - The Cloudflare Insights beacon loaded from static.cloudflareinsights.com - The style="display:contents" attribute SvelteKit emits on its body wrapper Adds explicit script-src and style-src directives with 'unsafe-inline' and the Cloudflare Insights origin/connect-src. The dashboard is already gated by Cloudflare Access, so CSP here is defence-in-depth rather than the primary XSS control. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
script-srcandstyle-srcdirectives to the_headersCSP, replacing the over-broaddefault-src 'self'fallback that was blocking the dashboard from loading'unsafe-inline'inscript-srccovers SvelteKit's inline bootstrap script and any scripts Cloudflare injects at the edge (Web Analytics, Rocket Loader, etc.) — hash mode is not viable here because once a hash is present inscript-src, browsers ignore'unsafe-inline', and edge-injected scripts can't be hashed at build timehttps://static.cloudflareinsights.comadded toscript-srcandhttps://cloudflareinsights.comtoconnect-srcfor the Web Analytics beacon'unsafe-inline'instyle-srccovers thestyle="display:contents"attribute SvelteKit emits on its body wrapper divX-Frame-Options,X-Content-Type-Options,Referrer-Policy,frame-ancestors,base-uri,form-action) are unchangedThe dashboard is gated by Cloudflare Access, so CSP is defence-in-depth rather than the primary XSS control.
Test plan
cloudflareinsights.com)X-Frame-Options: DENYand other security headers are still present in the response🤖 Generated with Claude Code