XMLTV: access_token query value interpolated raw into guide (pre-existing XML-injection) #376

Closed
opened 2026-07-16 21:13:17 +02:00 by timothy · 2 comments
Owner

Problem

GetChannelGuideHandler builds {AccessTokenUri} as ?v={mtime}&amp;access_token={request.AccessToken} and substitutes it raw into the pre-built XMLTV cache fragments (which are written unescaped). The access_token value (request.AccessToken, taken from the ?access_token= query string) is not XML-escaped, so a token containing &, <, >, or " would emit invalid XML and malform the entire guide.

This is pre-existing — the same code shipped before #340 — and the value is HTTP-request-derived, not the new iptv.base_url config surface. Surfaced by the independent review of #340 (PR #374) as an explicitly out-of-scope, non-blocking observation.

Proposed fix

XML-escape the token value where it is interpolated into {AccessTokenUri} (e.g. SecurityElement.Escape on the token, consistent with how #340 escaped {RequestBase}), or validate/reject tokens containing XML-special characters. The M3U path (ChannelPlaylist.ToM3U) also interpolates the access token but M3U is not XML, so that side is likely fine — confirm.

Notes

Low severity: access tokens are typically operator-generated opaque strings without XML-special characters, and an attacker cannot set another user's token. Tracked for completeness.

Done-when

  • Access token value is XML-safe in the XMLTV guide output (escaped or validated)
  • Regression test with an XML-special-char token
  • adversarial review passed
## Problem `GetChannelGuideHandler` builds `{AccessTokenUri}` as `?v={mtime}&amp;access_token={request.AccessToken}` and substitutes it **raw** into the pre-built XMLTV cache fragments (which are written unescaped). The `access_token` **value** (`request.AccessToken`, taken from the `?access_token=` query string) is not XML-escaped, so a token containing `&`, `<`, `>`, or `"` would emit invalid XML and malform the entire guide. This is **pre-existing** — the same code shipped before #340 — and the value is HTTP-request-derived, not the new `iptv.base_url` config surface. Surfaced by the independent review of #340 (PR #374) as an explicitly out-of-scope, non-blocking observation. ## Proposed fix XML-escape the token value where it is interpolated into `{AccessTokenUri}` (e.g. `SecurityElement.Escape` on the token, consistent with how #340 escaped `{RequestBase}`), or validate/reject tokens containing XML-special characters. The M3U path (`ChannelPlaylist.ToM3U`) also interpolates the access token but M3U is not XML, so that side is likely fine — confirm. ## Notes Low severity: access tokens are typically operator-generated opaque strings without XML-special characters, and an attacker cannot set another user's token. Tracked for completeness. ## Done-when - [x] Access token value is XML-safe in the XMLTV guide output (escaped or validated) - [x] Regression test with an XML-special-char token - [x] adversarial review passed
timothy added the bugpriority: low labels 2026-07-16 21:13:27 +02:00
timothy added priority: medium and removed priority: low labels 2026-07-17 00:25:08 +02:00
timothy added the in-progress label 2026-07-17 18:57:38 +02:00
Author
Owner

Claiming — XML-escaping the access_token value where it is interpolated into {AccessTokenUri} in GetChannelGuideHandler, consistent with how #340 escaped {RequestBase} (SecurityElement.Escape). Will confirm the M3U path needs no change (M3U isn't XML) and add a regression test with an XML-special-char token.

Claiming — XML-escaping the `access_token` value where it is interpolated into `{AccessTokenUri}` in `GetChannelGuideHandler`, consistent with how #340 escaped `{RequestBase}` (`SecurityElement.Escape`). Will confirm the M3U path needs no change (M3U isn't XML) and add a regression test with an XML-special-char token.
timothy removed the in-progress label 2026-07-17 19:34:54 +02:00
Author
Owner

Done — merged in PR #419

What was done: XML-escaped the access_token value where GetChannelGuideHandler appends it to {AccessTokenUri}, using SecurityElement.Escape (consistent with how #340 escaped {RequestBase} one line above). A token containing &, <, >, or " no longer malforms the XMLTV guide.

Root cause: the token is HTTP-request-derived (?access_token=) and was interpolated raw into pre-built XMLTV cache fragments that are written unescaped. Pre-existing (predates #340); surfaced as an out-of-scope observation by the #340/PR #374 independent review.

Files changed:

  • ErsatzTV.Application/Channels/Queries/GetChannelGuideHandler.cs — escape the token value.
  • ErsatzTV.Core.Tests/Iptv/ChannelGuideGoldenTests.cs — regression test Guide_xml_escapes_access_token (drives the real handler with a &<>" token; verified non-vacuous — fails with the escape reverted). Full ErsatzTV.Core.Tests green (549).

M3U path: ChannelPlaylist.ToM3U also interpolates the token but M3U is not XML, so escaping there is neither needed nor correct — left unchanged (confirmed).

Deferred / follow-up: cold review noted a distinct, out-of-scope M3U-quoting concern (a literal " in a token could break the url-tvg="..." attribute for strict parsers). Filed as #421 (priority: low).

Review: cold-context adversarial review → MERGEABLE, no blocking findings. Docs: none required — no convention/route/endpoint change (read-path fix + test).

## Done — merged in PR #419 **What was done:** XML-escaped the `access_token` value where `GetChannelGuideHandler` appends it to `{AccessTokenUri}`, using `SecurityElement.Escape` (consistent with how #340 escaped `{RequestBase}` one line above). A token containing `&`, `<`, `>`, or `"` no longer malforms the XMLTV guide. **Root cause:** the token is HTTP-request-derived (`?access_token=`) and was interpolated raw into pre-built XMLTV cache fragments that are written unescaped. Pre-existing (predates #340); surfaced as an out-of-scope observation by the #340/PR #374 independent review. **Files changed:** - `ErsatzTV.Application/Channels/Queries/GetChannelGuideHandler.cs` — escape the token value. - `ErsatzTV.Core.Tests/Iptv/ChannelGuideGoldenTests.cs` — regression test `Guide_xml_escapes_access_token` (drives the real handler with a `&<>"` token; verified non-vacuous — fails with the escape reverted). Full `ErsatzTV.Core.Tests` green (549). **M3U path:** `ChannelPlaylist.ToM3U` also interpolates the token but M3U is not XML, so escaping there is neither needed nor correct — left unchanged (confirmed). **Deferred / follow-up:** cold review noted a distinct, out-of-scope M3U-quoting concern (a literal `"` in a token could break the `url-tvg="..."` attribute for strict parsers). Filed as #421 (`priority: low`). **Review:** cold-context adversarial review → MERGEABLE, no blocking findings. **Docs:** none required — no convention/route/endpoint change (read-path fix + test).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#376