test(#319): hash-drift guard prefers the built index.html when present
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 9s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 7s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m7s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m14s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Has been skipped
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Has been skipped
Build ErsatzTV Image / Docs update reminder (push) Has been skipped
Build ErsatzTV Image / decisions.md append-only (push) Has been skipped
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 4m33s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 5m19s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 5m14s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 9s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 10s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 7s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 1m7s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 5m14s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 9m36s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (push) Has been skipped
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (push) Has been skipped
Build ErsatzTV Image / Docs update reminder (push) Has been skipped
Build ErsatzTV Image / decisions.md append-only (push) Has been skipped
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (push) Successful in 4m33s
Build ErsatzTV Image / Build & test (.NET) (push) Successful in 5m19s
Build ErsatzTV Image / Build & push image (amd64) (push) Successful in 5m14s
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>
This commit was merged in pull request #323.
This commit is contained in:
@@ -80,10 +80,10 @@ public class SecurityHeadersMiddlewareTests
|
||||
/// <summary>
|
||||
/// Guards <see cref="SecurityHeadersMiddleware.SpaInlineScriptHash" /> against drift from the
|
||||
/// SPA's <c>index.html</c>: every inline <c><script></c> the browser will hash-check must
|
||||
/// be allow-listed by the CSP, or the enforcing policy silently breaks the SPA. Vite copies
|
||||
/// inline scripts into the build verbatim, so hashing the committed source (<c>web/index.html</c>,
|
||||
/// which — unlike the gitignored built <c>wwwroot/app</c> — exists in the CI checkout) matches
|
||||
/// the served bytes.
|
||||
/// be allow-listed by the CSP, or the enforcing policy silently breaks the SPA. Hashes the
|
||||
/// built <c>wwwroot/app/index.html</c> when present (the exact bytes the browser hashes), else
|
||||
/// the committed <c>web/index.html</c> source in a fresh CI checkout where the built artifact is
|
||||
/// gitignored/absent (Vite copies the inline script verbatim, so the two agree).
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Csp_Script_Hash_Should_Match_The_Spa_Index()
|
||||
@@ -131,6 +131,12 @@ public class SecurityHeadersMiddlewareTests
|
||||
{
|
||||
// callerFilePath = <repo>/ErsatzTV.Tests/Middleware/SecurityHeadersMiddlewareTests.cs
|
||||
string repoRoot = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(callerFilePath)!, "..", ".."));
|
||||
return Path.Combine(repoRoot, "web", "index.html");
|
||||
|
||||
// Prefer the built index.html — it is the exact bytes the browser hashes, so a local build
|
||||
// catches any Vite transform of the inline script, not just a source edit. It is gitignored,
|
||||
// though, so in a fresh CI checkout it is absent and we fall back to the committed source
|
||||
// (Vite copies the inline script verbatim, so the two agree today).
|
||||
string built = Path.Combine(repoRoot, "ErsatzTV", "wwwroot", "app", "index.html");
|
||||
return File.Exists(built) ? built : Path.Combine(repoRoot, "web", "index.html");
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -1633,8 +1633,9 @@ camera/microphone/geolocation/payment/usb) and an **enforcing** `Content-Securit
|
||||
`connect-src 'self'`; `object-src 'none'`; `base-uri 'self'`; `frame-ancestors 'none'`; `form-action 'self'`.
|
||||
- **Why each relaxation.** The SPA is a static file, so a per-response nonce is impossible → the one inline
|
||||
theme-bootstrap `<script>` is allow-listed **by hash**; `SecurityHeadersMiddlewareTests.Csp_Script_Hash_Should_
|
||||
Match_The_Spa_Index` hashes the committed `web/index.html` (Vite copies the inline script verbatim, and the
|
||||
built `wwwroot/app` is gitignored/absent in CI) and fails if the two drift. `style-src 'unsafe-inline'` covers
|
||||
Match_The_Spa_Index` hashes the built `wwwroot/app/index.html` when present (else the committed `web/index.html`
|
||||
source, since the built artifact is gitignored/absent in CI — Vite copies the inline script verbatim) and fails
|
||||
if it drifts from the middleware constant. `style-src 'unsafe-inline'` covers
|
||||
React's inline `style=""` attributes (no CSS-in-JS lib to hash). The **Google Fonts** hosts are required — the
|
||||
SPA CSS `@import`s the Geist web font (caught by **live-E2E**, which the static grep missed); self-hosting the
|
||||
font to drop the Google dependency is a follow-on hardening, not this issue. `img-src data: blob:` covers
|
||||
|
||||
Reference in New Issue
Block a user