Repository navigation
Website: a Content-Security-Policy for every page, and Dependabot - #18
Merged
Merged
Conversation
Each built page gets its own policy as a <meta> first in the head (site/scripts/csp.mjs, after the build): every inline script and stylesheet by its hash, the site's own files, WebAssembly and the engine's worker, and nothing else. vercel.json sends what a <meta> cannot say (frame-ancestors) as a header. The logo and the chart's row letters are styled by class instead of style attributes, which the policy doesn't allow; the build stops if one comes back. The end-to-end server now sends vercel.json's headers, and a new test checks that a script injected into a page is turned away. .github/dependabot.yml: monthly grouped updates for npm, GitHub Actions and Cargo.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
From a security audit of the site. Nothing exploitable was found; this adds the defence in depth that was missing.
Content-Security-Policy
site/scripts/csp.mjsruns after the build (and afteroffline.mjs) and writes a policy into every page indist/, as a<meta>first in the head:default-src 'none', each inline script and stylesheet by its SHA-256 hash, the site's own files,'wasm-unsafe-eval'for the engine andworker-src blob:for its thread. No'unsafe-inline'.security.csp: it hashes only the scripts it bundles, not theis:inlineones the first paint relies on, it places its<meta>after three of them, and the offline file is assembled after Astro has finished.vercel.jsonadds a header for what a<meta>cannot say:frame-ancestors 'none', plusbase-uri,form-actionandobject-src.styleattributes, which a hash policy turns away. They use classes now; the build stops if astyleoron…attribute comes back into the markup.Tests
e2e/serve.mjssends the headers fromvercel.json, so the tests run under the same header policy as production.e2e/csp.spec.ts: on/,/playand/broadside, a script injected into the page is refused.worker-srcfrom a built page: the game test then fails on the blocked worker.Dependabot
.github/dependabot.yml: one grouped pull request a month each for npm (/site), GitHub Actions and Cargo.Checked locally
npm run check: 0 errors.npm run build: 3 pages get a policy.npm run test:e2e: Chromium, WebKit and the phone profile pass (62 passed, 1 skipped as before). Firefox does not launch on my machine (the browser exits with "Could not find profile folder" before any test runs), so the 21 Firefox tests are verified by CI here, not locally.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test --release: pass (no Rust changes).