Skip to content

fix(web): enforce the content security policy - #124

Merged
Glory42 merged 2 commits into
masterfrom
fix/csp-enforce
Nov 17, 2026
Merged

Glory42 merged 2 commits into
masterfrom
fix/csp-enforce

Conversation

@Glory42

@Glory42 Glory42 commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the last slice of #94: the report-only CSP becomes the enforced one.

 Content-Security-Policy:
-  frame-ancestors 'none'; base-uri 'self'; object-src 'none'; form-action 'self'
+  default-src 'self'; script-src 'self' 'unsafe-inline' data: https://static.cloudflareinsights.com;
+  style-src …; font-src …; img-src …; media-src …; connect-src 'self' <api> https://cloudflareinsights.com;
+  frame-src 'none'; frame-ancestors 'none'; base-uri 'self'; object-src 'none'; form-action 'self'
-Content-Security-Policy-Report-Only: <the same source list, minus data:>

The one addition is data: in script-src: Astro's ClientRouter appends <script type="module" src="data:application/javascript,"> on client-side navigation (astro/dist/transitions/router.js:88) whenever the page has an inline module script. 'unsafe-inline' was already allowed, so this adds no real exposure.

A new smoke test fails the e2e run on any CSP console error, so a new font/analytics/API origin can't ship unnoticed. astro dev serves scripts as files, so it can't reproduce the data: case; the unit test pins that.

Evidence

Headless Chromium against the live site, with its CSP header rewritten to the enforced policy: 17 list pages and tabs, race / race-story / telemetry / sprint / driver / team / circuit / prediction detail pages, the search palette and sidebar client navigation.

  • Before (the report-only policy, enforced):
    client-nav Loading the script 'data:application/javascript,' violates … "script-src 'self' 'unsafe-inline' https://static.cloudflareinsights.com"
    After (this PR's policy): CLEAN, and the client fetches still go through: 200 /api/search, 200 /api/drivers/222?year=2026, 200 /api/drivers/221?year=2026.
  • Unit: securityHeaders.test.ts 6/6 (enforced, no report-only header, script-src has data:, connect-src has the API).
  • E2E: security.spec.ts 3/3 against the fixture server.

Merge Danger

Door: two-way

Revert the commit to go back to report-only.

Blast Radius: site-wide

A source the policy misses gets blocked in the browser on every page. The live sweep found none, but anything loaded only on a page or interaction the sweep didn't reach would break until it's added to securityHeaders.ts. Prerendered /docs and static assets don't get these headers.

A week report-only showed one violation: Astro's ClientRouter appends an
empty data: module script on client-side navigation, so script-src allows
data:. Every other page, tab and client fetch on the live site was clean.
Catches a new third-party origin before it ships. astro dev serves scripts
as files, so the ClientRouter data: case is covered by the unit test.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying f1-prediction-platform-web with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6647b6e
Status: ✅  Deploy successful!
Preview URL: https://56099fd8.f1-prediction-platform-web.pages.dev
Branch Preview URL: https://fix-csp-enforce.f1-prediction-platform-web.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
f1-prediction-platform-api 6647b6e Nov 17 2026, 02:53 PM

@Glory42
Glory42 merged commit 930099d into master Nov 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant