Repository navigation
feat(game): enforce the Content-Security-Policy - #306
Merged
Merged
Conversation
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.
What and why
The site sent its Content-Security-Policy as
Content-Security-Policy-Report-Only, so an injected script would still run. It now sendsContent-Security-Policy, the same value from the Worker (security-headers.ts) and frompublic/_headers. The policy text did not change, except that'unsafe-inline'inscript-srcnow has a comment saying why it stays: the server-rendered pages carry inline scripts without a nonce. A nonce or hash rewrite is out of scope.e2e/support/test.ts: every spec'stestnow fails when a page firessecuritypolicyviolationor prints a CSP error in the console, in every context including a second player's.e2e/csp.spec.ts: checks the enforced header on a page and a build asset, that the guard catches a refused request, and that no spec importstestfrom@playwright/testdirectly.connect-srcandimg-src(plus itsws://form forconnect-src) whenVITE_BACKEND_URLis set. Production does not set it, so its policy is the static one andpublic/_headersstill matches.Violations the guard found with the policy enforced (Chromium, whole suite): the e2e backend origin in
connect-src(nearly every spec, from/api/v1/auth/get-session,/events/game, sign-up, sign-in and invite links) and inimg-src(avatar.spec.ts, avatar images). No script, style, font or eval violations.How to verify
pnpm test:e2eon both projects: 1009 passed, 219 skipped, 0 failed (Chromium + WebKit, guard on).pnpm typecheck,pnpm biome:checkand the scoped game build pass.https://static.cloudflareinsights.com/beacon.min.jswith no violation (the request was stubbed locally).curl -sI https://abalone.tudu.dev/and one/assets/*.jsshowcontent-security-policy, and no report-only header.