M3U: access_token value not quote-safe in url-tvg="..." attribute #421

Closed
opened 2026-07-17 19:09:21 +02:00 by timothy · 3 comments
Owner

Follow-up from #376 (PR #419) cold review — a distinct, out-of-scope observation deferred from the XMLTV escaping fix.

Problem

ChannelPlaylist.ToM3U (ErsatzTV.Core/Iptv/ChannelPlaylist.cs:40-41) interpolates the HTTP-request-derived access_token value into a quoted M3U attribute (url-tvg="...&access_token=<token>"). M3U is not XML, so #376's SecurityElement.Escape correctly does not apply here. But a token containing a literal double-quote (") could still terminate the quoted url-tvg attribute early for strict M3U parsers.

Severity

Low. Access tokens are operator-generated opaque strings that don't normally contain ", and an attacker can't set another user's token (same threat model as #376). Tracked for completeness.

Proposed fix

Reject/validate tokens containing " (and other M3U-structural chars) at the token-generation/validation boundary, or percent-encode the token where it's placed into M3U URLs. Confirm which M3U attributes actually consume the token and whether Jellyfin/clients percent-decode.

Done-when

  • A token containing " cannot malform M3U output (validated or encoded)
  • Regression test
  • adversarial review passed
Follow-up from #376 (PR #419) cold review — a distinct, out-of-scope observation deferred from the XMLTV escaping fix. ## Problem `ChannelPlaylist.ToM3U` (`ErsatzTV.Core/Iptv/ChannelPlaylist.cs:40-41`) interpolates the HTTP-request-derived `access_token` value into a quoted M3U attribute (`url-tvg="...&access_token=<token>"`). M3U is not XML, so #376's `SecurityElement.Escape` correctly does **not** apply here. But a token containing a literal double-quote (`"`) could still terminate the quoted `url-tvg` attribute early for strict M3U parsers. ## Severity Low. Access tokens are operator-generated opaque strings that don't normally contain `"`, and an attacker can't set another user's token (same threat model as #376). Tracked for completeness. ## Proposed fix Reject/validate tokens containing `"` (and other M3U-structural chars) at the token-generation/validation boundary, or percent-encode the token where it's placed into M3U URLs. Confirm which M3U attributes actually consume the token and whether Jellyfin/clients percent-decode. ## Done-when - [x] A token containing `"` cannot malform M3U output (validated or encoded) - [x] Regression test - [x] adversarial review passed
timothy added the bugpriority: low labels 2026-07-17 19:09:22 +02:00
Author
Owner

🔗 Session bundle — access_token transport hardening: #421, #559

Both harden the access_token-in-URL surface (from the #376/#552 arc): #421 (M3U token not quote-safe in the url-tvg="..." attribute) and #559 (redact the /iptv ?access_token= from request logs + no-store on tokened manifests). Security-adjacent, same token transport.

When you claim any member, check this cluster for co-workable siblings and sweep the disjoint set in one session (per docs/handoffs/chicorytv-issue-queue.md → bundles).

🔗 **Session bundle — access_token transport hardening:** #421, #559 Both harden the `access_token`-in-URL surface (from the #376/#552 arc): #421 (M3U token not quote-safe in the url-tvg="..." attribute) and #559 (redact the /iptv `?access_token=` from request logs + no-store on tokened manifests). Security-adjacent, same token transport. When you claim any member, check this cluster for co-workable siblings and sweep the disjoint set in one session (per docs/handoffs/chicorytv-issue-queue.md → bundles).
timothy added the in-progress label 2026-07-23 07:59:37 +02:00
Author
Owner

Claiming this as part of the access_token transport hardening bundle (#421 + #559) in one session — both harden the access_token-in-URL surface. Working in a worktree off origin/main.

Claiming this as part of the **access_token transport hardening** bundle (#421 + #559) in one session — both harden the `access_token`-in-URL surface. Working in a worktree off `origin/main`.
Author
Owner

Closing record

Outcome: Merged in #574 (squash). access_token is percent-encoded (Uri.EscapeDataString) at every M3U/HLS/XMLTV URL interpolation site (ChannelPlaylist.ToM3U, IptvController.AccessTokenQuery, FFmpegLibraryProcessService.WrapSegmenter, GetChannelGuideHandler).
Root cause: the request-derived token was interpolated raw into quoted M3U attributes / query strings; a "/& could break out. Pre-existing, low-severity/defense-in-depth (opaque operator tokens don't normally contain these).
Decisions/conventions changed: added security.iptv-access-token-transport; [decisions-edit] on security.iptv-browser-token.
Reusable knowledge: Uri.EscapeDataString is a no-op for base64url JWTs (all chars RFC 3986 unreserved) → M3U/XMLTV goldens byte-identical. The XMLTV twin needed BOTH percent-encode + XML-escape: SecurityElement.Escape (from #376) guards XML well-formedness, not URL correctness, so a token & still truncated the query after XML-unescape.
Verification: Core.Tests 645 + ErsatzTV.Tests 1832 + new ChannelPlaylistAccessTokenTests/updated guide test; 2-round adversarial cold review; CI green; live-E2E (url-tvg shows access_token=aa%22bb%26cc, no breakout).
Deferred: none.
Docs updated: docs/decisions/api-auth-security.md.

## Closing record **Outcome:** Merged in #574 (squash). `access_token` is percent-encoded (`Uri.EscapeDataString`) at every M3U/HLS/XMLTV URL interpolation site (`ChannelPlaylist.ToM3U`, `IptvController.AccessTokenQuery`, `FFmpegLibraryProcessService.WrapSegmenter`, `GetChannelGuideHandler`). **Root cause:** the request-derived token was interpolated raw into quoted M3U attributes / query strings; a `"`/`&` could break out. Pre-existing, low-severity/defense-in-depth (opaque operator tokens don't normally contain these). **Decisions/conventions changed:** added `security.iptv-access-token-transport`; `[decisions-edit]` on `security.iptv-browser-token`. **Reusable knowledge:** `Uri.EscapeDataString` is a no-op for base64url JWTs (all chars RFC 3986 unreserved) → M3U/XMLTV goldens byte-identical. The XMLTV twin needed BOTH percent-encode + XML-escape: `SecurityElement.Escape` (from #376) guards XML well-formedness, not URL correctness, so a token `&` still truncated the query after XML-unescape. **Verification:** Core.Tests 645 + ErsatzTV.Tests 1832 + new `ChannelPlaylistAccessTokenTests`/updated guide test; 2-round adversarial cold review; CI green; live-E2E (url-tvg shows `access_token=aa%22bb%26cc`, no breakout). **Deferred:** none. **Docs updated:** `docs/decisions/api-auth-security.md`.
timothy removed the in-progress label 2026-07-23 18:32:32 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#421