harden(421,559): percent-encode access_token in IPTV URLs, redact from logs, no-store on tokened manifests #574

Merged
timothy merged 2 commits from feat/421-559-access-token-hardening into main 2026-07-23 18:31:00 +02:00
Owner

Bundle: access_token transport hardening (#421 + #559) — two concrete fixes on the shared ?access_token= /iptv surface.

#421 — token not quote-safe in M3U/HLS/XMLTV URLs

A token containing "/& could break out of the quoted M3U url-tvg="..."/tvg-logo="..." attributes (or split a query). Now percent-encoded (Uri.EscapeDataString) at every interpolation site: ChannelPlaylist.ToM3U, IptvController.AccessTokenQuery, FFmpegLibraryProcessService.WrapSegmenter, and the XMLTV twin GetChannelGuideHandler (percent-encode then XML-escape). No-op for a normal base64url JWT → M3U/XMLTV goldens byte-identical.

Done-when

  • A token containing " cannot malform M3U output (validated or encoded)
  • Regression test (ChannelPlaylistAccessTokenTests, updated Guide_encodes_and_xml_escapes_access_token)
  • adversarial review passed

#559 — transport hardening (redact from logs + no-store)

  1. Log redaction. Serilog logged the full ?access_token=<jwt> query on any 5xx/Error /iptv request. IncludeQueryInRequestPath = false + new RequestLogScrubber → RequestPathScrubbed (masks token to ***, keeps other params).
  2. no-store. channels.m3u, xmltv.xml, the .m3u8 HLS manifests, and their token-bearing 302 Locations now return Cache-Control: private, no-store.

Done-when

  • A 5xx (and Debug-level) /iptv/...?access_token= request does not write the token to the log
  • Token-bearing dynamic manifests return no-store
  • Covered by a test (log scrub) and a curl assertion (header)
  • docs/decisions/api-auth-security.md updated (folds the deferred-hardening note under security.iptv-browser-token)

Verification

  • Core.Tests 645✓, ErsatzTV.Tests 1832✓, 5 new targeted tests, format gate✓, BOM✓, decisions validator✓.
  • Independent cold security review (2 rounds) — clean verdict; found the XMLTV twin (Finding 1), a TS-redirect no-store gap (Finding 2, fixed), and a documented load-bearing residual (Finding 3, Microsoft: Warning appsettings override — not UI-reachable).
  • Live E2E: no-store on m3u/xmltv/m3u8; url-tvg shows access_token=aa%22bb%26cc (no breakout); request log renders access_token=*** with the raw token absent.

Decision record security.iptv-access-token-transport added.

Closes #421
Closes #559

🤖 Generated with Claude Code

Bundle: **access_token transport hardening** (#421 + #559) — two concrete fixes on the shared `?access_token=` `/iptv` surface. ## #421 — token not quote-safe in M3U/HLS/XMLTV URLs A token containing `"`/`&` could break out of the quoted M3U `url-tvg="..."`/`tvg-logo="..."` attributes (or split a query). Now percent-encoded (`Uri.EscapeDataString`) at every interpolation site: `ChannelPlaylist.ToM3U`, `IptvController.AccessTokenQuery`, `FFmpegLibraryProcessService.WrapSegmenter`, and the XMLTV twin `GetChannelGuideHandler` (percent-encode **then** XML-escape). No-op for a normal base64url JWT → M3U/XMLTV goldens byte-identical. **Done-when** - [x] A token containing `"` cannot malform M3U output (validated or encoded) - [x] Regression test (`ChannelPlaylistAccessTokenTests`, updated `Guide_encodes_and_xml_escapes_access_token`) - [x] adversarial review passed ## #559 — transport hardening (redact from logs + no-store) 1. **Log redaction.** Serilog logged the full `?access_token=<jwt>` query on any 5xx/Error `/iptv` request. `IncludeQueryInRequestPath = false` + new `RequestLogScrubber` → `RequestPathScrubbed` (masks token to `***`, keeps other params). 2. **no-store.** `channels.m3u`, `xmltv.xml`, the `.m3u8` HLS manifests, and their token-bearing 302 Locations now return `Cache-Control: private, no-store`. **Done-when** - [x] A 5xx (and Debug-level) `/iptv/...?access_token=` request does not write the token to the log - [x] Token-bearing dynamic manifests return `no-store` - [x] Covered by a test (log scrub) and a curl assertion (header) - [x] `docs/decisions/api-auth-security.md` updated (folds the deferred-hardening note under `security.iptv-browser-token`) ## Verification - Core.Tests 645✓, ErsatzTV.Tests 1832✓, 5 new targeted tests, format gate✓, BOM✓, decisions validator✓. - **Independent cold security review** (2 rounds) — clean verdict; found the XMLTV twin (Finding 1), a TS-redirect `no-store` gap (Finding 2, fixed), and a documented load-bearing residual (Finding 3, `Microsoft: Warning` appsettings override — not UI-reachable). - **Live E2E:** `no-store` on m3u/xmltv/m3u8; `url-tvg` shows `access_token=aa%22bb%26cc` (no breakout); request log renders `access_token=***` with the raw token absent. Decision record `security.iptv-access-token-transport` added. Closes #421 Closes #559 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timothy added 1 commit 2026-07-23 08:30:51 +02:00
harden(421,559): percent-encode access_token in IPTV URLs, redact from logs, no-store on tokened manifests
PR Gates / decisions lifecycle (pull_request) Failing after 12s
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 21s
PR Gates / Docs update reminder (pull_request) Successful in 21s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m24s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 22s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 19s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m25s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 15m51s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
a372742eb0
#421 — a token containing a double-quote/ampersand could break out of the quoted M3U
`url-tvg="..."`/`tvg-logo="..."` attributes or split the query. Percent-encode
(`Uri.EscapeDataString`) at every site the token is interpolated into an M3U/HLS/XMLTV
URL: `ChannelPlaylist.ToM3U`, `IptvController.AccessTokenQuery`,
`FFmpegLibraryProcessService.WrapSegmenter`, and the XMLTV twin
`GetChannelGuideHandler` (percent-encode then XML-escape). No-op for a normal base64url
JWT, so the M3U/XMLTV goldens are byte-identical.

#559 — (1) Serilog logged the full `?access_token=<jwt>` query on any 5xx/Error `/iptv`
request. `IncludeQueryInRequestPath = false` + a new `RequestLogScrubber` enriching
`RequestPathScrubbed` (masks the token to `***`, keeps other params) that the message
template now references. (2) Token-bearing dynamic manifests (`channels.m3u`,
`xmltv.xml`, the `.m3u8` HLS manifests, and their token-bearing 302 Locations) now return
`Cache-Control: private, no-store`.

Independent cold review (2 rounds) clean. Live-E2E verified: no-store header on
m3u/xmltv/m3u8, token percent-encoded in url-tvg, and the request log rendering
`access_token=***` with the raw token absent. Decision record
`security.iptv-access-token-transport` added; resolves the deferred-hardening note under
`security.iptv-browser-token`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
timothy added 1 commit 2026-07-23 08:33:09 +02:00
docs(decisions): [decisions-edit] authorize the #552 record prose edit
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 12s
PR Gates / Docs update reminder (pull_request) Successful in 13s
PR Gates / decisions lifecycle (pull_request) Successful in 22s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 16s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 17s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 6m3s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 15m43s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 20m26s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
26ec6ac5d8
The prior commit updated the "deferred hardening" bullet of the
`security.iptv-browser-token` (#552) record — marking it RESOLVED and pointing to the new
`security.iptv-access-token-transport` record — plus its Rule/Signals lines. That is a
rationale-prose edit of an existing decision (exactly what #559's done-when asked for:
"fold into the deferred-hardening note under security.iptv-browser-token"), so it needs
the [decisions-edit] marker for the lifecycle validator. No record heading renamed, no
record removed; the #552 key/status/heading are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
Owner

Review-verdict: ✅ clean — head 26ec6ac5

Two independent cold review rounds (adversarial, LSP-verified, no implementation context):

  • Round 1 traced every access_token interpolation site and manifest endpoint; found the XMLTV twin (Finding 1), a TS-redirect no-store gap (Finding 2), and a documented load-bearing residual (Finding 3, Microsoft: Warning appsettings suppressor — not UI-reachable).
  • Round 2 (fix re-review) confirmed all three CONFIRMED-FIXED with no new defects: XMLTV layering SecurityElement.Escape(Uri.EscapeDataString(token)) round-trips correctly; TS redirect no-store complete; Finding 3 documentation disposition reasonable.

The only change since the reviewed a372742e is an empty [decisions-edit] authorization commit (26ec6ac5) — nothing reviewable.

Done-when: all boxes ticked (see description). CI: all 8 jobs green on 26ec6ac5 (Build & test, EF migration integrity, Functional E2E, Formatting, decisions lifecycle, API docs, PR gates; image-push skipped for PR). Live-E2E: no-store on m3u/xmltv/m3u8, url-tvg percent-encoded, request log access_token=***.

**Review-verdict:** ✅ clean — head `26ec6ac5` Two independent cold review rounds (adversarial, LSP-verified, no implementation context): - **Round 1** traced every `access_token` interpolation site and manifest endpoint; found the XMLTV twin (Finding 1), a TS-redirect `no-store` gap (Finding 2), and a documented load-bearing residual (Finding 3, `Microsoft: Warning` appsettings suppressor — not UI-reachable). - **Round 2** (fix re-review) confirmed all three CONFIRMED-FIXED with no new defects: XMLTV layering `SecurityElement.Escape(Uri.EscapeDataString(token))` round-trips correctly; TS redirect `no-store` complete; Finding 3 documentation disposition reasonable. The only change since the reviewed `a372742e` is an empty `[decisions-edit]` authorization commit (`26ec6ac5`) — nothing reviewable. **Done-when:** all boxes ticked (see description). **CI:** all 8 jobs green on `26ec6ac5` (Build & test, EF migration integrity, Functional E2E, Formatting, decisions lifecycle, API docs, PR gates; image-push skipped for PR). **Live-E2E:** no-store on m3u/xmltv/m3u8, url-tvg percent-encoded, request log `access_token=***`.
timothy merged commit 0c063c23fb into main 2026-07-23 18:31:00 +02:00
timothy deleted branch feat/421-559-access-token-hardening 2026-07-23 18:31:01 +02:00
Sign in to join this conversation.