Add Cross-Origin-Resource-Policy header (ZAP #314 authenticated-scan Low) #330

Closed
opened 2026-07-13 08:27:46 +02:00 by timothy · 3 comments
Owner

From the #314 authenticated ZAP deep scan (2026-07-13, against :latest = 682dceec). The scan was otherwise clean (0 High/Medium/Critical across all 160 /api/v1 endpoints). Only actionable finding:

Low — Cross-Origin-Resource-Policy header missing (ZAP 90004), observed on /openapi/v1.json (and applies to the general response posture). #319 added CSP / nosniff / X-Frame-Options / Referrer-Policy / Permissions-Policy to SecurityHeadersMiddleware but not CORP (a Spectre-era cross-origin-embedding defense).

Proposed

Add Cross-Origin-Resource-Policy: same-origin in SecurityHeadersMiddleware (the established home, #319), and extend SecurityHeadersMiddlewareTests. Verify first it doesn't regress:

  • the opt-in cross-origin CORS machine-client path (Api:CorsAllowedOrigins) — CORP gates no-cors/embedding, not cors-mode fetches, so it should be safe, but confirm;
  • /iptv/* (Jellyfin is a server-side HTTP client — CORP is browser-enforced, so unaffected) and /artwork/* (<img> is same-origin);
  • whether /openapi (currently excluded from the middleware) should also carry it.

Triage

Low / backlog — defense-in-depth header hygiene, not go-live-blocking (behind auth + LAN proxy today; the API surface itself passed the authenticated active scan clean). Extends #319. Refs #314 #197 #319.

Done-when

  • Cross-Origin-Resource-Policy set by SecurityHeadersMiddleware (value verified safe for the CORS + /iptv + /artwork paths)
  • SecurityHeadersMiddlewareTests covers it
  • adversarial review passed
From the #314 **authenticated** ZAP deep scan (2026-07-13, against `:latest` = `682dceec`). The scan was otherwise clean (**0 High/Medium/Critical** across all 160 `/api/v1` endpoints). Only actionable finding: **Low — `Cross-Origin-Resource-Policy` header missing** (ZAP 90004), observed on `/openapi/v1.json` (and applies to the general response posture). #319 added CSP / `nosniff` / `X-Frame-Options` / `Referrer-Policy` / `Permissions-Policy` to `SecurityHeadersMiddleware` but not CORP (a Spectre-era cross-origin-embedding defense). ## Proposed Add `Cross-Origin-Resource-Policy: same-origin` in `SecurityHeadersMiddleware` (the established home, #319), and extend `SecurityHeadersMiddlewareTests`. **Verify first** it doesn't regress: - the opt-in cross-origin **CORS** machine-client path (`Api:CorsAllowedOrigins`) — CORP gates *no-cors*/embedding, not cors-mode fetches, so it should be safe, but confirm; - `/iptv/*` (Jellyfin is a server-side HTTP client — CORP is browser-enforced, so unaffected) and `/artwork/*` (`<img>` is same-origin); - whether `/openapi` (currently excluded from the middleware) should also carry it. ## Triage **Low / backlog** — defense-in-depth header hygiene, not go-live-blocking (behind auth + LAN proxy today; the API surface itself passed the authenticated active scan clean). Extends #319. Refs #314 #197 #319. ## Done-when - [x] `Cross-Origin-Resource-Policy` set by `SecurityHeadersMiddleware` (value verified safe for the CORS + `/iptv` + `/artwork` paths) - [x] `SecurityHeadersMiddlewareTests` covers it - [x] adversarial review passed
timothy added the priority: lowreviewsecurity labels 2026-07-13 08:28:08 +02:00
timothy added the in-progress label 2026-07-13 21:03:04 +02:00
Author
Owner

claiming — session started 2026-07-13T19:03:04.762Z

claiming — session started 2026-07-13T19:03:04.762Z
Author
Owner

Recon complete. SecurityHeadersMiddleware is registered first (before CORS and the /iptv branch) and already supplies path-independent baseline headers; only CSP is excluded on /docs + /openapi. Per the Fetch CORP algorithm, CORP is enforced for opaque/no-cors browser loads, so same-origin does not break an API request that succeeds through the configured CORS allowlist. Server-side clients such as Jellyfin/curl/.NET ignore CORP, and the SPA consumes relative same-origin artwork URLs. The deliberate compatibility effect is that direct cross-origin browser embedding of ErsatzTV artwork/media is blocked.

Implementation is therefore the proposed global Cross-Origin-Resource-Policy: same-origin, including /docs and /openapi, plus representative middleware coverage for API, artwork, IPTV, docs, and OpenAPI. Focused middleware suite is green (9/9). Full verification and independent review still pending. Live-E2E is not required: no mutating handler or SPA behavior changes.

Recon complete. `SecurityHeadersMiddleware` is registered first (before CORS and the `/iptv` branch) and already supplies path-independent baseline headers; only CSP is excluded on `/docs` + `/openapi`. Per the [Fetch CORP algorithm](https://fetch.spec.whatwg.org/#cross-origin-resource-policy-header), CORP is enforced for opaque/`no-cors` browser loads, so `same-origin` does not break an API request that succeeds through the configured CORS allowlist. Server-side clients such as Jellyfin/curl/.NET ignore CORP, and the SPA consumes relative same-origin artwork URLs. The deliberate compatibility effect is that direct cross-origin browser embedding of ErsatzTV artwork/media is blocked. Implementation is therefore the proposed global `Cross-Origin-Resource-Policy: same-origin`, including `/docs` and `/openapi`, plus representative middleware coverage for API, artwork, IPTV, docs, and OpenAPI. Focused middleware suite is green (9/9). Full verification and independent review still pending. Live-E2E is not required: no mutating handler or SPA behavior changes.
Author
Owner

Done

What was done: Added Cross-Origin-Resource-Policy: same-origin to the global SecurityHeadersMiddleware, including CSP-exempt /docs and /openapi, with representative API/artwork/IPTV/docs/OpenAPI tests. PR #341 fast-forwarded to main at 2609b4ce.

Root cause: #319 added the CSP and Permissions-Policy security posture but omitted CORP, leaving cross-origin browser embedding less constrained than intended.

Files changed: ErsatzTV/Middleware/SecurityHeadersMiddleware.cs; ErsatzTV.Tests/Middleware/SecurityHeadersMiddlewareTests.cs; docs/decisions.md.

Verification: Focused middleware suite 9/9; full UTC solution restore/build/test green (build 0 warnings/errors); pre-push generated-API drift, ESLint, TypeScript typecheck, and Vite build green; PR CI green across .NET, SQLite/MySQL migrations, formatting, docs, decisions, and API drift.

Deferred: Live-E2E was not required because no mutating handler or SPA behavior changed. Direct cross-origin browser embedding is intentionally blocked; supported CORS-mode machine clients and native/server-side Kodi/Dispatcharr/Jellyfin remain unaffected.

Follow-up issues: #340 tracks an optional advertised IPTV base URL (backlog / Medium). timothy/server-management#501 now holds the separate Kodi/Dispatcharr URL diagnosis. No external GitHub issue was created.

Docs updated: Appended the global CORP posture and compatibility rationale to docs/decisions.md.

Reviewer-facing summary: Cold independent security review found no issues and returned MERGEABLE for exact head 2609b4ce593eeaf7203fb50c78feec030638984f; nothing was deferred from review.

## Done **What was done**: Added `Cross-Origin-Resource-Policy: same-origin` to the global `SecurityHeadersMiddleware`, including CSP-exempt `/docs` and `/openapi`, with representative API/artwork/IPTV/docs/OpenAPI tests. PR #341 fast-forwarded to `main` at `2609b4ce`. **Root cause**: #319 added the CSP and Permissions-Policy security posture but omitted CORP, leaving cross-origin browser embedding less constrained than intended. **Files changed**: `ErsatzTV/Middleware/SecurityHeadersMiddleware.cs`; `ErsatzTV.Tests/Middleware/SecurityHeadersMiddlewareTests.cs`; `docs/decisions.md`. **Verification**: Focused middleware suite 9/9; full UTC solution restore/build/test green (build 0 warnings/errors); pre-push generated-API drift, ESLint, TypeScript typecheck, and Vite build green; PR CI green across .NET, SQLite/MySQL migrations, formatting, docs, decisions, and API drift. **Deferred**: Live-E2E was not required because no mutating handler or SPA behavior changed. Direct cross-origin browser embedding is intentionally blocked; supported CORS-mode machine clients and native/server-side Kodi/Dispatcharr/Jellyfin remain unaffected. **Follow-up issues**: #340 tracks an optional advertised IPTV base URL (backlog / Medium). `timothy/server-management#501` now holds the separate Kodi/Dispatcharr URL diagnosis. No external GitHub issue was created. **Docs updated**: Appended the global CORP posture and compatibility rationale to `docs/decisions.md`. **Reviewer-facing summary**: Cold independent security review found no issues and returned `MERGEABLE` for exact head `2609b4ce593eeaf7203fb50c78feec030638984f`; nothing was deferred from review.
timothy removed the in-progress label 2026-07-13 21:34:22 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#330