The posture-independent, low-risk subset of the #197 cold API security review — the clear-cut fixes that don't depend on the bigger fail-closed / CORS / versioning posture decisions (those are designed in the #197 roadmap and land as follow-on gate PRs).
Changes
Constant-time API-key comparison [S10] — ApiKeyAuthorizationFilter now compares X-Api-Key with CryptographicOperations.FixedTimeEquals instead of ordinal string.Equals, closing the response-timing oracle on the write key.
Clamp playout pagination [S8] — GET /api/playouts and GET /api/playouts/{id}/items passed the raw client pageSize straight to EF Take(). Now clamped Math.Clamp(pageSize, 1, 100) + Math.Max(0, pageNum), matching the documented api-conventions §1 convention every other paged endpoint already follows (removes the unbounded-materialization DoS).
Baseline security headers [S10] — new SecurityHeadersMiddleware emits X-Content-Type-Options: nosniff, X-Frame-Options: DENY, Referrer-Policy: strict-origin-when-cross-origin on every response. nosniff is the backstop for the artwork content-type MIME-sniffing risk. CSP + HSTS are deliberately deferred to the #197 posture design (CSP needs validation against the SPA's inline assets; HSTS is proxy/TLS-owned).
The load-bearing posture work — fail-closed write default (S1), SortController//account/logout non-/api bypass (S2), sensitive-read auth tier (S3/S5), upload byte-validation + serve-side de-reflection (S4/S9), CORS lockdown (S6), API versioning (C1) and the OpenAPI security/error-contract transformers (C2/C4/C5/C6) — is being dispatched as separate review issues with a phased plan.
Tests
ApiKeyAuthorizationFilterTests (existing behavior preserved under the constant-time swap).
New clamp tests on PlayoutControllerTests (huge/negative page params → clamped GetPagedPlayouts/GetFuturePlayoutItemsById).
New SecurityHeadersMiddlewareTests.
Full ErsatzTV.Tests suite green locally (1414 passed).
No contract change → no OpenAPI regen needed (paging params already existed; headers/compare are internal).
The posture-independent, low-risk subset of the #197 cold API security review — the clear-cut fixes that don't depend on the bigger fail-closed / CORS / versioning posture decisions (those are designed in the #197 roadmap and land as follow-on gate PRs).
## Changes
- **Constant-time API-key comparison** [S10] — `ApiKeyAuthorizationFilter` now compares `X-Api-Key` with `CryptographicOperations.FixedTimeEquals` instead of ordinal `string.Equals`, closing the response-timing oracle on the write key.
- **Clamp playout pagination** [S8] — `GET /api/playouts` and `GET /api/playouts/{id}/items` passed the raw client `pageSize` straight to EF `Take()`. Now clamped `Math.Clamp(pageSize, 1, 100)` + `Math.Max(0, pageNum)`, matching the documented `api-conventions §1` convention every other paged endpoint already follows (removes the unbounded-materialization DoS).
- **Baseline security headers** [S10] — new `SecurityHeadersMiddleware` emits `X-Content-Type-Options: nosniff`, `X-Frame-Options: DENY`, `Referrer-Policy: strict-origin-when-cross-origin` on every response. `nosniff` is the backstop for the artwork content-type MIME-sniffing risk. CSP + HSTS are deliberately **deferred** to the #197 posture design (CSP needs validation against the SPA's inline assets; HSTS is proxy/TLS-owned).
## Not in scope (tracked in the #197 roadmap)
The load-bearing posture work — fail-closed write default (S1), `SortController`/`/account/logout` non-`/api` bypass (S2), sensitive-read auth tier (S3/S5), upload byte-validation + serve-side de-reflection (S4/S9), CORS lockdown (S6), API versioning (C1) and the OpenAPI security/error-contract transformers (C2/C4/C5/C6) — is being dispatched as separate `review` issues with a phased plan.
## Tests
- `ApiKeyAuthorizationFilterTests` (existing behavior preserved under the constant-time swap).
- New clamp tests on `PlayoutControllerTests` (huge/negative page params → clamped `GetPagedPlayouts`/`GetFuturePlayoutItemsById`).
- New `SecurityHeadersMiddlewareTests`.
- Full `ErsatzTV.Tests` suite green locally (1414 passed).
No contract change → no OpenAPI regen needed (paging params already existed; headers/compare are internal).
Refs #197.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Posture-independent safe hardening from the #197 cold API security review
(the clear-cut fixes that don't depend on the fail-closed/CORS/versioning
posture design, which is tracked separately):
- ApiKeyAuthorizationFilter: compare X-Api-Key with
CryptographicOperations.FixedTimeEquals instead of ordinal string.Equals
(removes the response-timing oracle on the write key). [S10]
- PlayoutController: clamp pageNum/pageSize on GET /api/playouts and
/api/playouts/{id}/items to Math.Clamp(_, 1, 100), matching the documented
api-conventions §1 convention every other paged endpoint already follows —
these two were passing the raw value straight to EF Take(). [S8]
- SecurityHeadersMiddleware: emit X-Content-Type-Options: nosniff,
X-Frame-Options: DENY, Referrer-Policy: strict-origin-when-cross-origin on
every response (nosniff backstops the artwork content-type MIME-sniffing
risk). CSP/HSTS deferred to the #197 posture design (CSP needs SPA
validation; HSTS is proxy/TLS-owned). [S10]
Refs #197.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
The posture-independent, low-risk subset of the #197 cold API security review — the clear-cut fixes that don't depend on the bigger fail-closed / CORS / versioning posture decisions (those are designed in the #197 roadmap and land as follow-on gate PRs).
Changes
ApiKeyAuthorizationFilternow comparesX-Api-KeywithCryptographicOperations.FixedTimeEqualsinstead of ordinalstring.Equals, closing the response-timing oracle on the write key.GET /api/playoutsandGET /api/playouts/{id}/itemspassed the raw clientpageSizestraight to EFTake(). Now clampedMath.Clamp(pageSize, 1, 100)+Math.Max(0, pageNum), matching the documentedapi-conventions §1convention every other paged endpoint already follows (removes the unbounded-materialization DoS).SecurityHeadersMiddlewareemitsX-Content-Type-Options: nosniff,X-Frame-Options: DENY,Referrer-Policy: strict-origin-when-cross-originon every response.nosniffis the backstop for the artwork content-type MIME-sniffing risk. CSP + HSTS are deliberately deferred to the #197 posture design (CSP needs validation against the SPA's inline assets; HSTS is proxy/TLS-owned).Not in scope (tracked in the #197 roadmap)
The load-bearing posture work — fail-closed write default (S1),
SortController//account/logoutnon-/apibypass (S2), sensitive-read auth tier (S3/S5), upload byte-validation + serve-side de-reflection (S4/S9), CORS lockdown (S6), API versioning (C1) and the OpenAPI security/error-contract transformers (C2/C4/C5/C6) — is being dispatched as separatereviewissues with a phased plan.Tests
ApiKeyAuthorizationFilterTests(existing behavior preserved under the constant-time swap).PlayoutControllerTests(huge/negative page params → clampedGetPagedPlayouts/GetFuturePlayoutItemsById).SecurityHeadersMiddlewareTests.ErsatzTV.Testssuite green locally (1414 passed).No contract change → no OpenAPI regen needed (paging params already existed; headers/compare are internal).
Refs #197.
🤖 Generated with Claude Code