Skip to content

chore: Enable experimental CSP support#204

Open
cleptric wants to merge 15 commits intomainfrom
chore-enable-csp
Open

chore: Enable experimental CSP support#204
cleptric wants to merge 15 commits intomainfrom
chore-enable-csp

Conversation

@cleptric
Copy link
Member

@cleptric cleptric commented Feb 18, 2026

Enable Astro's experimental Content Security Policy support for the site.

The is:inline directive on the theme toggle script is removed so Astro
can hash it and include it in the CSP header. Inline scripts bypass
Astro's CSP pipeline and would be blocked by the policy.

See https://docs.astro.build/en/reference/experimental-flags/csp/

<meta http-equiv="content-security-policy" content="script-src 'self' 'sha256-N1rr5W+ifZ0kn31Hxuo/d4/f6/5OUySJqjco32RMIRc=' 'sha256-BF0290pkb3jxQsE7z00xR8Imp8X34FLC88L0lkMnrGw=' 'sha256-QzWFZi+FLIx23tnm9SBU4aEgx4x8DsuASP07mfqol/c=' 'sha256-0chmwFk0zaA528yFfGV7J9ppIpdfTPPULncDF3WG7Zs=' 'sha256-eIXWvAmxkr251LJZkjniEK5LcPF3NkapbJepohwYRIc=' 'sha256-Q2BPg90ZMplYY+FSdApNErhpWafg2hcRRbndmvxuL/Q='; style-src 'self' 'sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=';">

@vercel
Copy link

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sentry-engineering Ready Ready Preview, Comment Feb 20, 2026 0:25am

Request Review

Enable Astro's experimental Content Security Policy support and remove
the `is:inline` directive from the theme toggle script so Astro can
generate a hash for it. Inline scripts bypass Astro's CSP pipeline
and would be blocked by the policy.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@geoffg-sentry geoffg-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the best here, but I think we some scripts might get blocked when we throw on CSP. I think we gotta allow google fonts, probably some twitter resources too like

  csp: {
    styleDirective: {
      resources: ["https://fonts.googleapis.com","https://platform.twitter.com"]
    }

There's a script in BaseLayout.astro that is:inline so that's likely going to be blocked, but I don't think we can just remove it. Searching quickly and I think we add the hash ourselves with https://docs.astro.build/en/reference/experimental-flags/csp/#cspinsertscripthash

And I saw <script define:vars={{ listId }}> in PostList.astro but I'm not sure how to fix this one.

Replace Google Fonts with self-hosted JetBrains Mono woff2 files to
avoid CSP style-src violations. Restore Plausible analytics and
configure CSP to allow plausible.io as a script and connect source.

Co-Authored-By: Claude <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/gIeOoKPtmvSR20aB5W9-5CwyNa8a0It-59Kkq7yGAP0
Restore apple-touch-icon and manifest from main, remove nonexistent
dark favicon.

Co-Authored-By: Claude <noreply@anthropic.com>
Remove variable extraction for Plausible and footer color changes
that were not part of the CSP work.

Co-Authored-By: Claude <noreply@anthropic.com>
Scripts with is:inline bypass Astro's CSP hash generation, causing
them to be blocked by the browser. Remove the directive so Astro
can hash them properly.

Co-Authored-By: Claude <noreply@anthropic.com>
The theme init script must run synchronously before paint to prevent
a flash of wrong theme. Restore is:inline and add its SHA-256 hash
to the CSP config so the browser allows it.

Co-Authored-By: Claude <noreply@anthropic.com>
cleptric and others added 3 commits February 20, 2026 01:13
Astro drops processed scripts and ignores template conditionals for
non-inline scripts. Keep all scripts as is:inline and add their
SHA-256 hashes to the CSP config manually.

Co-Authored-By: Claude <noreply@anthropic.com>
Astro drops processed scripts and ignores template conditionals for
non-inline scripts. Keep all scripts as is:inline and add their
SHA-256 hashes to the CSP config manually.

Co-Authored-By: Claude <noreply@anthropic.com>

Agent transcript: https://claudescope.sentry.dev/share/isudgKIPBCXKIyb63mFw83EiI1AoyMqGjXa-Vsww7ks
Co-Authored-By: Claude <noreply@anthropic.com>
Replace inline style attribute with class:list/hidden to avoid
style-src-attr CSP violation. Replace define:vars with data
attribute and is:inline script to produce a stable hash.

Co-Authored-By: Claude <noreply@anthropic.com>
Shiki syntax highlighting generates inline style attributes on code
tokens which cannot be individually hashed. Add unsafe-inline to
style-src. Restrict img-src to self.

Co-Authored-By: Claude <noreply@anthropic.com>
No default-src is set, so omitting img-src leaves images
unrestricted. The restriction would break external images in
blog posts without meaningful security benefit.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments