Skip to content

Website: a Content-Security-Policy for every page, and Dependabot - #18

Merged
AdminGodZ merged 1 commit into
mainfrom
t3/battleship-security-audit
Nov 27, 2026
Merged

AdminGodZ merged 1 commit into
mainfrom
t3/battleship-security-audit

Conversation

@AdminGodZ

@AdminGodZ AdminGodZ commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

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.mjs runs after the build (and after offline.mjs) and writes a policy into every page in dist/, 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 and worker-src blob: for its thread. No 'unsafe-inline'.
  • Why not Astro's security.csp: it hashes only the scripts it bundles, not the is:inline ones the first paint relies on, it places its <meta> after three of them, and the offline file is assembled after Astro has finished.
  • vercel.json adds a header for what a <meta> cannot say: frame-ancestors 'none', plus base-uri, form-action and object-src.
  • The logo and the chart's row letters were styled by style attributes, which a hash policy turns away. They use classes now; the build stops if a style or on… attribute comes back into the markup.

Tests

  • e2e/serve.mjs sends the headers from vercel.json, so the tests run under the same header policy as production.
  • New e2e/csp.spec.ts: on /, /play and /broadside, a script injected into the page is refused.
  • Every existing test already fails on a logged error, and browsers log what a policy blocks, so the whole suite checks that nothing of the site's own is blocked. Confirmed by removing worker-src from 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.
  • Logo colours and axis label positions compared against the live site in Chromium: identical.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test --release: pass (no Rust changes).

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.
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
broadside Ready Ready Preview Nov 27, 2026 8:28am UTC

@AdminGodZ
AdminGodZ merged commit b97fd80 into main Nov 27, 2026
4 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