Skip to content

fix(jellycompat): keep the login token out of Jellyfin stream and subtitle URLs - #2924

Merged
Quick104 merged 5 commits into
mainfrom
fix/jellycompat-token-out-of-stream-urls
Nov 5, 2026
Merged

Quick104 merged 5 commits into
mainfrom
fix/jellycompat-token-out-of-stream-urls

Conversation

@Quick104

@Quick104 Quick104 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2906
Related issue: N/A
Validation tasks: changes #1246 C1

Silo's Jellyfin-compatible API put the device's login token into media URLs it hands to clients. DirectStreamUrl and every subtitle DeliveryUrl carried it as api_key, and the trickplay tiles.m3u8 playlist repeated the caller's token as ApiKey on every sheet line. That token is the device's full credential. It stays valid as long as the Jellyfin login does, and every compat route accepts it as a query parameter, Quick Connect authorization included. So a stream or subtitle URL recorded by a reverse proxy, CDN, or player log gave access to the whole account. With this change those URLs carry only PlaySessionId, which grants GET/HEAD on that one item and source, ends with the play session, and stops working when the device signs out.

Merge after #2922, which raises the play-session lifetime from 6 h to 24 h. PlaySessionId-only URLs expire with the play session, so on its own this change would make subtitles fail 6 h after PlaybackInfo, as HLS already does today.

Approach

  • DirectStreamUrl and subtitle DeliveryUrl drop api_key. Their routes already accepted the PlaySessionId these URLs carry (PlaybackSessionAuth), as the HLS and attachment URLs do.
  • Trickplay: the sheet route moves into the PlaybackSessionAuth group. Its item parameter is renamed to {id} so the grant check reads it. Token auth on sheets works as before. tiles.m3u8 writes the PlaySessionId of the caller's live play that covers that item and source: the one the request names, else the most recent. It writes no credential when there is no such play or the plays can't be read. A sheet request that names a PlaySessionId and no source gets that play's version, and a sheet a PlaySessionId authorized gets only a version that negotiation offered.
  • A grant no longer covers a request whose MediaSourceId spellings (any case, or MediaSourceId[]) name different sources. The grant check and the handler each read that key case-insensitively, and the lookup picks a spelling at random, so they could disagree. This applies to every route in the group.
  • docs/jellycompat-api.md says which credential server-built URLs carry and when a client must send its own token.

Refusing query-string tokens on non-media routes would cut the exposure further. Real clients send ApiKey on many routes, though (Jellyfin Web images, trickplay sheets, the WebSocket), so that needs a client survey first and is not part of this change.

Validation

  • Rebased onto main at 2d5f22e7d and checked again on a sandbox built first from main, then from 354e2acf3. On main, DirectStreamUrl, the subtitle DeliveryUrl, and the tiles.m3u8 sheet lines carried the token. At 354e2acf3 none did. With only PlaySessionId and no auth header, the direct stream (range request), the subtitle, and the sheet listed in tiles.m3u8 succeeded. A stream naming another MediaSourceId and a sheet with no credential got 401, and after Sessions/Logout the stream and subtitle URLs got 401. The jellycompat package passes with a scratch Postgres, and the three tests named under Tests still fail on main. The client runs and the make test-go run below were on commits before the rebase and were not repeated.
  • Reproduced on a Silo dev deployment at main d00462089. PlaybackInfo and tiles.m3u8 returned URLs carrying the token, and that token authorized account routes. Without the token, the stream and subtitle URLs still worked through PlaySessionId.
  • On the same deployment at b031cfbd3, no server-built URL carries the token. With only the URL's PlaySessionId and no auth header, direct stream (range request), subtitle, HLS master, and the trickplay sheet from tiles.m3u8 all succeed. Another source, conflicting MediaSourceId spellings, or no credential get 401.
  • Jellyfin Web 10.11.6 (managed build) played an episode over HLS with an ASS subtitle track and seek-bar previews, before and after. Subtitles render from a DeliveryUrl with no token, and previews load. Jellyfin Web still adds ApiKey to the trickplay and direct-play URLs it builds itself. Direct play inside Jellyfin Web was not exercised, because headless Chromium did not direct-play this MKV there on main either; direct stream was checked at the API instead.
  • Six more Jellyfin clients, on a sandbox at 1e3030cf6: Jellyfin Android TV 0.19.10, Wholphin 1.0.9, Findroid 1.1.0, Jellyfin Android 2.7.3 (integrated and web player), Streamyfin 0.55.2, and Swiftfin built from main (VLC player). Each played an episode, showed an external SRT fetched from the PlaySessionId-only DeliveryUrl, and played again after Stop. Every client that shows trickplay showed it; Streamyfin shows none. Jellyfin Android TV, Jellyfin Android and Streamyfin also played transcoded HLS with the subtitle on. No media request answered 401. Swiftfin's HLS couldn't be tested: Silo answers its fMP4-only transcoding profile with 400, and that code is unchanged here.
  • Trickplay version choice, on a second deployment at main and then at 1e3030cf6, used a movie with two versions, where the same device negotiated the H.264 version and then, more recently, the HEVC one. A sheet request naming the older play's PlaySessionId without a source was refused at main when it carried no token, and got the newer play's HEVC sheet when it carried the token. At 1e3030cf6 both get the named play's H.264 sheet, byte for byte. The fallback when plays can't be listed needs a database fault to show live; a test covers it.
  • Tests: the PlaybackInfo URL test and two trickplay playlist tests fail on main because the URLs carry the token, and pass here. New rows cover the grant's source scope, ambiguous MediaSourceId spellings, a sheet following the play it names (also when the caller's plays can't be listed), and a playlist served when plays can't be listed. The jellycompat package passes with a scratch Postgres, including its database-backed tests.
  • Go build, vet, gofmt, make lint-changed, make lint-router-recovery, the route inventory, and the other contract verifiers pass. make test-go passes except TestRunStatsWithRealFFmpeg in internal/mediasample, which fails the same way on main (local ffmpeg). The web gate was not run; web/ is untouched.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2924/

Risks

  • Compatibility: a client that fetches a server-built stream or subtitle URL without sending its own token now gets 401 in three cases where the embedded token used to work: after the play session's lifetime (absolute from PlaybackInfo), after the client reported Sessions/Playing/Stopped, or after a newer negotiation from the same device replaced an unstarted one. Findroid's downloader, per its source, fetches external subtitles from DeliveryUrl without an auth header, so a subtitle download delayed past the play session would fail (not tested).
  • tiles.m3u8 sheet lines carry no credential when the caller has no live play of that source, so a player that fetches them without headers gets 401. Silo's HLS playlists don't advertise tiles.m3u8, and no client we checked requests it; Jellyfin Web and Findroid build sheet URLs themselves.
  • The sheet route now answers a forbidden sa_ admin key with 401 instead of 403, like the other media routes.
  • Multiple API replicas: if PlaybackInfo fails to persist its negotiation, the PlaySessionId resolves only on the replica that created it. The embedded token used to let DirectStreamUrl recover on another replica; HLS already had this dependency. [bug] Jellyfin media requests answer 401 instead of 503 when the play-session store can't be read #2923 tracks the store's error handling.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code, run inside T3 Code
  • Tool(s): Claude Code; Codex CLI (plan review, background review); Claude Code subagents (code review, client testing); Playwright (Jellyfin Web captures); Android emulators and an iOS simulator (client testing)
  • Model(s): claude-opus-5-5; gpt-6.1-sol (plan review, background review); claude-sonnet-5-5 (code review, one finder and the validation check)
  • Involvement: Fully AI-generated; not yet verified by a human
  • Adversarial review: gpt-6.1-sol reviewed the plan before implementation. It led to keeping a sheet request on the play it names, renaming the route parameter in the resolver too, and documenting the limits above. It also raised the store error handling now tracked in [bug] Jellyfin media requests answer 401 instead of 503 when the play-session store can't be read #2923. A code review of the diff (three finders, a sweep, and a validation check) led to the MediaSourceId spelling check, to serving the playlist when plays can't be listed instead of answering 503, and to small cleanups. Kody found that a sheet the grant authorized could fall back to a version the grant didn't cover when the caller's plays couldn't be listed (fixed in a72228d), and that the fix stopped token-authenticated requests from following the play they name (fixed in 1e3030c). A background review by gpt-6.1-sol of b031cfb found nothing new; it confirmed the gap Kody reported, fixed in a72228d.

🤖 Generated with Claude Code

Note

Remove login token from Jellyfin playback and subtitle URLs, authorize via PlaySessionId

  • PlaybackInfo media-source and subtitle URLs no longer embed the caller's api_key. The compatibility-token parameter is removed from mediaSourceDTO, subtitleDeliveryURL, and related helpers in handlers_playback.go
  • PlaybackSessionAuth in auth.go now attaches the playback negotiation that authorized a request to the request context, and grant matching requires the route item and any named MediaSourceId to match the negotiation
  • Trickplay playlist sheet URLs in handlers_trickplay.go carry a matching PlaySessionId grant instead of the caller's token, and version selection only serves files offered by the authorizing negotiation; trickplay routes now use the {id} parameter
  • Updates tests across internal/jellycompat for the token-free mediaSourceDTO signature and documents the new auth model in jellycompat-api.md
  • Behavioral Change: direct-stream, transcoding, and subtitle URLs now rely on PlaySessionId grants rather than embedded tokens; check subtitleDeliveryURL and HandleTrickplayPlaylist if clients depended on api_key query params, and check testdata/media_routes.txt for the trickplay {itemId} → {id} route change

Macroscope summarized 354e2ac.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 22, 2026
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e1080369-a050-47b5-8d5b-186f28ae0860
Commits

Reviewing files that changed from the base of the PR and between 2d5f22e and 354e2ac.

Files selected for processing: 17

  • docs/jellycompat-api.md
  • internal/jellycompat/audio_v2_routes_test.go
  • internal/jellycompat/auth.go
  • internal/jellycompat/handlers_playback.go
  • internal/jellycompat/handlers_sessions.go
  • internal/jellycompat/handlers_trickplay.go
  • internal/jellycompat/hevc_routes_test.go
  • internal/jellycompat/playback_contract_test.go
  • internal/jellycompat/playback_hevc_encoding_test.go
  • internal/jellycompat/playback_hevc_remux_test.go
  • internal/jellycompat/playback_info_source_id_test.go
  • internal/jellycompat/playback_subtitle_auth_test.go
  • internal/jellycompat/router.go
  • internal/jellycompat/routing_policy_test.go
  • internal/jellycompat/subtitle_selection_test.go
  • internal/jellycompat/testdata/media_routes.txt
  • internal/jellycompat/trickplay_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-kody

silo-kody Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 22, 2026
Comment thread internal/jellycompat/auth.go Resolved
Comment thread internal/jellycompat/router.go Resolved
@silo-kody

silo-kody Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-kody

silo-kody Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@macroscopeapp

macroscopeapp Bot commented Oct 22, 2026

Copy link
Copy Markdown

Two trickplay preview-selection cases lack before-and-after evidence:

  • internal/jellycompat/handlers_trickplay.go: A grant-authorized sheet request without MediaSourceId now uses the version from its play; the description says no live check exercised this case and cites a test.
  • internal/jellycompat/handlers_trickplay.go: A token-authenticated sheet request naming an older PlaySessionId now uses that play's version rather than the newer play's; the description cites a regression test but no live capture.

Please add paired sheet captures for these requests to the linked evidence page so reviewers can verify the returned preview versions. Suggested fix: No diff — add those captures to the evidence page.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@Quick104

Copy link
Copy Markdown
Contributor Author

Added paired captures for both cases to the evidence page (section "Trickplay: which version a named play gets"). A movie with two versions is negotiated twice by one device, the H.264 version first and then the HEVC one. A sheet request names the older play's PlaySessionId without a MediaSourceId. At main, the request without a token is refused and the request with the token gets the newer play's HEVC sheet. At 1e3030cf6, both get the named play's H.264 sheet, matched byte for byte against that version's own sheet. The fallback when the caller's plays can't be listed needs a database fault to reproduce live; TestTrickplayPlaylistGrantsSheetsByPlaySession covers it.

Quick104 and others added 5 commits November 4, 2026 21:54
…rickplay URLs

PlaybackInfo wrote the device's compat token into DirectStreamUrl and every
subtitle DeliveryUrl as api_key, and the trickplay tiles.m3u8 playlist
repeated the caller's token as ApiKey on each sheet line. That token is
the device's full login credential and is accepted as a query parameter on
every compat route, so a URL recorded by a proxy, CDN, or player log
granted the whole account for as long as the login lasted.

These URLs now carry only PlaySessionId, which PlaybackSessionAuth already
accepts for GET/HEAD on the negotiated item and source until the play
session ends or the device signs out. The trickplay sheet route moves into
the PlaybackSessionAuth group (its item parameter is renamed to {id} so
the grant check sees it), tiles.m3u8 writes the PlaySessionId of the
caller's latest live play of that item and source (or no credential when
there is none), and a sheet request that names a PlaySessionId stays on
that play's version.

Closes #2906

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A PlaySessionId grant now refuses a request whose MediaSourceId spellings
name different sources, since the grant check and the handler could each
pick a different one. The trickplay playlist prefers the play the request
names and still serves, without a grant, when plays cannot be listed.
Subtitle streams append into the caller's slice, and the session listing
reuses activePlayLister.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The grant check now reads the bracket spelling MediaSourceId[] that the
handlers fall back to, ignores empty values instead of treating them as a
second source, and a sheet request naming a play that has not selected a
file gets the default version rather than another play's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A trickplay sheet request that a PlaySessionId authorized without naming a
source took its version from a separate listing of the caller's plays.
When that listing failed or missed the play, the request fell back to the
item's default version, which the grant might not cover.
PlaybackSessionAuth now passes the authorizing negotiation through the
request context, and the sheet resolver uses that negotiation's selected
file and serves only a version it offered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…play

A trickplay request authenticated by a token that names a PlaySessionId
without a MediaSourceId took the version of the token's most recent play
instead of the named one. The resolver now looks up the named play
directly, for the caller's own token and item, before falling back to the
most recent play.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/jellycompat-token-out-of-stream-urls branch from 1e3030c to 354e2ac Compare November 5, 2026 03:13
@silo-kody

silo-kody Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 77a1fe4 into main Nov 5, 2026
22 checks passed
@Quick104
Quick104 deleted the fix/jellycompat-token-out-of-stream-urls branch November 5, 2026 16:03
rangoDJ added a commit to rangoDJ/silo-server that referenced this pull request Nov 5, 2026
…ill passes

Silo-Server#2924 removed mediaSourceDTO's token parameter; the test Silo-Server#3522 added
afterwards still passed it, so main's jellycompat tests don't build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104 added a commit that referenced this pull request Nov 5, 2026
)

The Android TV playback test added in #3522 passes a token to
mediaSourceDTO, but #2924 removed that parameter, so the jellycompat
tests no longer compile on main.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Quick104 pushed a commit that referenced this pull request Nov 6, 2026
* fix(jellycompat): answer NoCompatibleStream when no route fits

When every version is readable but none can direct play, direct stream
or transcode, PlaybackInfo now answers as Jellyfin does: 200 with an
empty MediaSources list and ErrorCode NoCompatibleStream, so a client
shows an error instead of hanging on a failed request. A source over
the server's bitrate cap keeps the documented PlaybackUnavailable.

Streamyfin on a phone that decodes AV1 lists only fMP4 HLS, which takes
no H.264 encode here, so without HEVC encoding a lowered quality had no
route. The found-no-route log line now records the profile's HLS
transcoding containers and whether HEVC encoding is allowed.

Related to #3215

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(jellycompat): blame the bitrate cap only when it removes the routes

PlaybackInfo answered 400 PlaybackUnavailable whenever a server bitrate
cap was set and no route fit, even when a lower client limit or the
profile was what ruled the routes out. Streamyfin with a 4 Mbps limit, a
20 Mbps cap and its fMP4-only profile then froze on the 400 this branch
is meant to replace with NoCompatibleStream.

The no-route branch now builds the versions again without the cap. Only
when some version then has a route does it keep the 400 and say the
stream exceeds the cap; otherwise it answers NoCompatibleStream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(jellycompat): finish uncapped sources before blaming the bitrate cap

The check that keeps 400 PlaybackUnavailable for the server's bitrate
cap rebuilt each version without the cap but skipped the checks the
negotiation loop applies afterwards, so a version with no route for
another reason, such as a sidecar subtitle the profile takes only
embedded, looked playable and the cap was blamed. Apply the same
subtitle delivery, tone-map availability and HEVC-executor fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(jellycompat): keep tone-map lookup failures retryable in the cap check

When the check without the server's bitrate cap is the first to need the
tone-map policy or capabilities and the lookup fails for a version with
no direct route, answer 503 as the negotiation loop does, rather than
NoCompatibleStream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(jellycompat): cover a failed tone-map policy lookup in the cap check

Under a server cap too low for any encode, the capped pass never loads
the tone-map policy, so the check without the cap is the first to. When
that lookup fails, PlaybackInfo answers 503 PlaybackUnavailable rather
than NoCompatibleStream; before the previous commit it answered 200
NoCompatibleStream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(jellycompat): drop the token argument #3522's test still passes

#2924 removed mediaSourceDTO's token parameter; the test #3522 added
afterwards still passed it, so main's jellycompat tests don't build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Jellyfin stream and subtitle URLs carry the device's login token

1 participant