Repository navigation
fix(jellycompat): keep the login token out of Jellyfin stream and subtitle URLs - #2924
Conversation
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
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. View limit details
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Two trickplay preview-selection cases lack before-and-after evidence:
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 |
|
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 |
…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]>
1e3030c to
354e2ac
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…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]>
) 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]>
* 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]>
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.
DirectStreamUrland every subtitleDeliveryUrlcarried it asapi_key, and the trickplaytiles.m3u8playlist repeated the caller's token asApiKeyon 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 onlyPlaySessionId, 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 afterPlaybackInfo, as HLS already does today.Approach
DirectStreamUrland subtitleDeliveryUrldropapi_key. Their routes already accepted thePlaySessionIdthese URLs carry (PlaybackSessionAuth), as the HLS and attachment URLs do.PlaybackSessionAuthgroup. Its item parameter is renamed to{id}so the grant check reads it. Token auth on sheets works as before.tiles.m3u8writes thePlaySessionIdof 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 aPlaySessionIdand no source gets that play's version, and a sheet aPlaySessionIdauthorized gets only a version that negotiation offered.MediaSourceIdspellings (any case, orMediaSourceId[]) 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.mdsays 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
ApiKeyon 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
mainat2d5f22e7dand checked again on a sandbox built first frommain, then from354e2acf3. Onmain,DirectStreamUrl, the subtitleDeliveryUrl, and thetiles.m3u8sheet lines carried the token. At354e2acf3none did. With onlyPlaySessionIdand no auth header, the direct stream (range request), the subtitle, and the sheet listed intiles.m3u8succeeded. A stream naming anotherMediaSourceIdand a sheet with no credential got 401, and afterSessions/Logoutthe stream and subtitle URLs got 401. The jellycompat package passes with a scratch Postgres, and the three tests named under Tests still fail onmain. The client runs and themake test-gorun below were on commits before the rebase and were not repeated.maind00462089.PlaybackInfoandtiles.m3u8returned URLs carrying the token, and that token authorized account routes. Without the token, the stream and subtitle URLs still worked throughPlaySessionId.b031cfbd3, no server-built URL carries the token. With only the URL'sPlaySessionIdand no auth header, direct stream (range request), subtitle, HLS master, and the trickplay sheet fromtiles.m3u8all succeed. Another source, conflictingMediaSourceIdspellings, or no credential get 401.DeliveryUrlwith no token, and previews load. Jellyfin Web still addsApiKeyto 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 onmaineither; direct stream was checked at the API instead.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 frommain(VLC player). Each played an episode, showed an external SRT fetched from thePlaySessionId-onlyDeliveryUrl, 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.mainand then at1e3030cf6, 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'sPlaySessionIdwithout a source was refused atmainwhen it carried no token, and got the newer play's HEVC sheet when it carried the token. At1e3030cf6both 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.PlaybackInfoURL test and two trickplay playlist tests fail onmainbecause the URLs carry the token, and pass here. New rows cover the grant's source scope, ambiguousMediaSourceIdspellings, 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.make lint-changed,make lint-router-recovery, the route inventory, and the other contract verifiers pass.make test-gopasses exceptTestRunStatsWithRealFFmpegininternal/mediasample, which fails the same way onmain(local ffmpeg). The web gate was not run;web/is untouched.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2924/
Risks
PlaybackInfo), after the client reportedSessions/Playing/Stopped, or after a newer negotiation from the same device replaced an unstarted one. Findroid's downloader, per its source, fetches external subtitles fromDeliveryUrlwithout an auth header, so a subtitle download delayed past the play session would fail (not tested).tiles.m3u8sheet 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 advertisetiles.m3u8, and no client we checked requests it; Jellyfin Web and Findroid build sheet URLs themselves.sa_admin key with 401 instead of 403, like the other media routes.PlaybackInfofails to persist its negotiation, thePlaySessionIdresolves only on the replica that created it. The embedded token used to letDirectStreamUrlrecover 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
AI Disclosure
MediaSourceIdspelling 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
PlaySessionIdapi_key. The compatibility-token parameter is removed frommediaSourceDTO,subtitleDeliveryURL, and related helpers in handlers_playback.goPlaybackSessionAuthin auth.go now attaches the playback negotiation that authorized a request to the request context, and grant matching requires the route item and any namedMediaSourceIdto match the negotiationPlaySessionIdgrant instead of the caller's token, and version selection only serves files offered by the authorizing negotiation; trickplay routes now use the{id}parameterinternal/jellycompatfor the token-freemediaSourceDTOsignature and documents the new auth model in jellycompat-api.mdPlaySessionIdgrants rather than embedded tokens; checksubtitleDeliveryURLandHandleTrickplayPlaylistif clients depended onapi_keyquery params, and checktestdata/media_routes.txtfor the trickplay{itemId}→{id}route changeMacroscope summarized 354e2ac.