Completes the CSP the #279 baseline-headers middleware deferred, and adds Permissions-Policy. Surfaced by the #314 ZAP baseline scan (missing-header WARNs) — a #197 security-posture exit item.
An enforcingContent-Security-Policy on every response except/docs (Scalar) and /openapi — those rely on inline bootstrap scripts/styles a strict policy would break (they keep the baseline nosniff/frame/referrer headers; hardening that admin surface is a #197 follow-up).
No 'unsafe-inline'/'unsafe-eval' in script-src (the real XSS win) — the one inline script is allow-listed by hash.
Notable
Google Fonts allowance caught by live-E2E: the SPA CSS @imports the Geist web font (fonts.googleapis.com + fonts.gstatic.com); the static recon missed it, the browser run caught the CSP violation. Self-hosting the font to drop the Google dependency is a future hardening, not this issue.
Hash-drift guard test: Csp_Script_Hash_Should_Match_The_Spa_Index hashes the committed web/index.html inline script and fails if it drifts from the middleware constant. (The built wwwroot/app is gitignored/absent in CI; Vite copies the inline script verbatim, so the source hash == the served hash.)
Verification
SecurityHeadersMiddlewareTests 4/4 pass; full test project builds clean; dotnet format --verify-no-changes clean on touched files.
Live-E2E (headless): SPA renders fully under the enforcing CSP — logo image, theme switcher (inline script executed via hash), Geist font, same-origin /api fetches — zero CSP violations (only expected pre-login 401s).
curl: CSP + Permissions-Policy present on /app, /, /api; absent on /docs + /openapi (baseline headers still present there).
Docs
docs/decisions.md — new entry (CSP policy + why enforce-not-report-only + the /docs exclusion).
## What
Completes the CSP the #279 baseline-headers middleware deferred, and adds `Permissions-Policy`. Surfaced by the #314 ZAP baseline scan (missing-header WARNs) — a **#197 security-posture exit item**.
`SecurityHeadersMiddleware` now also sets:
- `Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()` (deny-all)
- An **enforcing** `Content-Security-Policy` on every response **except** `/docs` (Scalar) and `/openapi` — those rely on inline bootstrap scripts/styles a strict policy would break (they keep the baseline nosniff/frame/referrer headers; hardening that admin surface is a #197 follow-up).
CSP: `default-src 'self'; script-src 'self' '<sha256 of the SPA inline theme-bootstrap script>'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'`.
No `'unsafe-inline'`/`'unsafe-eval'` in `script-src` (the real XSS win) — the one inline script is allow-listed by hash.
## Notable
- **Google Fonts allowance caught by live-E2E**: the SPA CSS `@import`s the Geist web font (`fonts.googleapis.com` + `fonts.gstatic.com`); the static recon missed it, the browser run caught the CSP violation. Self-hosting the font to drop the Google dependency is a future hardening, not this issue.
- **Hash-drift guard test**: `Csp_Script_Hash_Should_Match_The_Spa_Index` hashes the committed `web/index.html` inline script and fails if it drifts from the middleware constant. (The built `wwwroot/app` is gitignored/absent in CI; Vite copies the inline script verbatim, so the source hash == the served hash.)
## Verification
- `SecurityHeadersMiddlewareTests` 4/4 pass; full test project builds clean; `dotnet format --verify-no-changes` clean on touched files.
- **Live-E2E** (headless): SPA renders fully under the enforcing CSP — logo image, theme switcher (inline script executed via hash), Geist font, same-origin `/api` fetches — **zero CSP violations** (only expected pre-login 401s).
- **curl**: CSP + Permissions-Policy present on `/app`, `/`, `/api`; **absent** on `/docs` + `/openapi` (baseline headers still present there).
## Docs
- `docs/decisions.md` — new entry (CSP policy + why enforce-not-report-only + the `/docs` exclusion).
fixes #319
Completes the CSP the #279 baseline-headers middleware deferred. Surfaced by
the #314 ZAP baseline (missing CSP/Permissions-Policy WARNs); a #197 exit item.
SecurityHeadersMiddleware now also sets Permissions-Policy (deny-all for
camera/mic/geolocation/payment/usb) and an enforcing Content-Security-Policy on
every response EXCEPT /docs (Scalar) and /openapi — those rely on inline
bootstrap scripts/styles a strict policy would break (baseline headers still
apply; hardening that admin surface is a #197 follow-up).
CSP: default-src 'self'; script-src 'self' + the hash of the SPA's inline
theme-bootstrap script (no 'unsafe-inline'/'unsafe-eval'); style-src adds
'unsafe-inline' (React inline styles) + fonts.googleapis.com; font-src adds
fonts.gstatic.com; img-src adds data:/blob:; object-src 'none'; base-uri 'self';
frame-ancestors 'none'; form-action 'self'.
The Google Fonts allowance (the SPA CSS @imports the Geist web font) was caught
by live-E2E, which the static recon missed. A guard test hashes the committed
web/index.html inline script and fails if it drifts from the middleware constant
(the built wwwroot/app is gitignored/absent in CI, and Vite copies the inline
script verbatim). Verified: full test pass, live-E2E (SPA renders clean, zero
CSP violations), curl (CSP present on /app + /api, absent on /docs + /openapi).
Docs: docs/decisions.md entry.
fixes#319
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses the cold-review LOW: the guard hashed only the committed source
web/index.html, so a hypothetical future Vite transform of the inline script
would leave the test green while the deployed CSP silently broke the SPA. It now
hashes the built wwwroot/app/index.html when it exists (the exact bytes the
browser hashes — full coverage on any local build), falling back to the source
only in a fresh CI checkout where the built artifact is gitignored/absent. Vite
copies the inline script verbatim today, so the two agree. Doc comments +
decisions.md synced. Test-and-docs only; no production code change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Independent adversarial review (cold, zero-context fork) over the diff: cleared the substance — script-src is genuinely strict (no 'unsafe-inline'/'unsafe-eval'), the /docs+/openapi exclusion is whole-segment (no over-exclusion of a /docsomething SPA route) and keeps baseline headers, base-path/UsePathBase handling is correct, no /iptv//artwork//api regression, the drift-guard test is non-vacuous, and decisions.md matches the code. Two non-blockers: a LOW (guard hashed source not built artifact) and a NIT (no report-uri).
The LOW is now fixed in 6537697f — the guard prefers the built wwwroot/app/index.html when present, falling back to source only in CI. That follow-up is test + docs only, no production-code change, so the production surface is byte-identical to the reviewed 873b3e54; independent re-review skipped per the rubric (pure test/docs leaf, no server-state effect). The report-uri NIT is deferred (no report collector exists).
**Independent adversarial review** (cold, zero-context fork) over the diff: cleared the substance — `script-src` is genuinely strict (no `'unsafe-inline'`/`'unsafe-eval'`), the `/docs`+`/openapi` exclusion is whole-segment (no over-exclusion of a `/docsomething` SPA route) and keeps baseline headers, base-path/`UsePathBase` handling is correct, no `/iptv`/`/artwork`/`/api` regression, the drift-guard test is non-vacuous, and `decisions.md` matches the code. Two non-blockers: a LOW (guard hashed source not built artifact) and a NIT (no `report-uri`).
The LOW is now fixed in `6537697f` — the guard prefers the built `wwwroot/app/index.html` when present, falling back to source only in CI. That follow-up is **test + docs only, no production-code change**, so the production surface is byte-identical to the reviewed `873b3e54`; independent re-review skipped per the rubric (pure test/docs leaf, no server-state effect). The `report-uri` NIT is deferred (no report collector exists).
Review-verdict: MERGEABLE @ 6537697f
timothy
merged commit 6537697fe5 into main2026-07-12 22:52:50 +02:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
Completes the CSP the #279 baseline-headers middleware deferred, and adds
Permissions-Policy. Surfaced by the #314 ZAP baseline scan (missing-header WARNs) — a #197 security-posture exit item.SecurityHeadersMiddlewarenow also sets:Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()(deny-all)Content-Security-Policyon every response except/docs(Scalar) and/openapi— those rely on inline bootstrap scripts/styles a strict policy would break (they keep the baseline nosniff/frame/referrer headers; hardening that admin surface is a #197 follow-up).CSP:
default-src 'self'; script-src 'self' '<sha256 of the SPA inline theme-bootstrap script>'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; img-src 'self' data: blob:; font-src 'self' data: https://fonts.gstatic.com; connect-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'.No
'unsafe-inline'/'unsafe-eval'inscript-src(the real XSS win) — the one inline script is allow-listed by hash.Notable
@imports the Geist web font (fonts.googleapis.com+fonts.gstatic.com); the static recon missed it, the browser run caught the CSP violation. Self-hosting the font to drop the Google dependency is a future hardening, not this issue.Csp_Script_Hash_Should_Match_The_Spa_Indexhashes the committedweb/index.htmlinline script and fails if it drifts from the middleware constant. (The builtwwwroot/appis gitignored/absent in CI; Vite copies the inline script verbatim, so the source hash == the served hash.)Verification
SecurityHeadersMiddlewareTests4/4 pass; full test project builds clean;dotnet format --verify-no-changesclean on touched files./apifetches — zero CSP violations (only expected pre-login 401s)./app,/,/api; absent on/docs+/openapi(baseline headers still present there).Docs
docs/decisions.md— new entry (CSP policy + why enforce-not-report-only + the/docsexclusion).fixes #319
Independent adversarial review (cold, zero-context fork) over the diff: cleared the substance —
script-srcis genuinely strict (no'unsafe-inline'/'unsafe-eval'), the/docs+/openapiexclusion is whole-segment (no over-exclusion of a/docsomethingSPA route) and keeps baseline headers, base-path/UsePathBasehandling is correct, no/iptv//artwork//apiregression, the drift-guard test is non-vacuous, anddecisions.mdmatches the code. Two non-blockers: a LOW (guard hashed source not built artifact) and a NIT (noreport-uri).The LOW is now fixed in
6537697f— the guard prefers the builtwwwroot/app/index.htmlwhen present, falling back to source only in CI. That follow-up is test + docs only, no production-code change, so the production surface is byte-identical to the reviewed873b3e54; independent re-review skipped per the rubric (pure test/docs leaf, no server-state effect). Thereport-uriNIT is deferred (no report collector exists).Review-verdict: MERGEABLE @
6537697f