Repository navigation
fix(downloads): carry the profile in a short-lived direct-download link - #2022
Conversation
…ocked or restricted profiles The v1 viewer routes that run RequireViewerAccess without RequireProfile resolved a request without X-Profile-Id to the account's own limits. On a household with a child profile (rating, advisory or library limits) or a PIN-locked parent profile, any device signed into the account could read past those limits, or the PIN, by omitting the header. A new HouseholdProfileGate refuses such requests with the existing v1 400 bad_request "X-Profile-Id header is required" when any profile on the account has a PIN, a rating ceiling, an advisory-age limit or a library restriction. Accounts without one keep account scope, and API keys are exempt. The gate is mounted on catalog browse/search/detail, watch and work detail, library collections, markers, subtitle media-file actions, item translate/trailer actions, ephemeral downloads and direct downloads. Profile selection, capability probes, account and admin routes and the session-bound stream routes are unchanged, as is v2. The route inventory records the gate as the household_profile_gate trait; the migration ledger is refreshed to match. The behaviour change is recorded in v1-scope.md and api-contract.md.
…cked or restricted profiles The v2 operations registered profile-optional for v1 parity resolved a request without X-Profile-Id to the account's own limits. On a household with a PIN-locked parent profile and a TV-Y7 child profile, the account's token read a TV-MA episode's watch detail, markers and subtitles by omitting the header, while the child's header got 404. Operations now declare HouseholdProfileGate, and the gate chain runs the household gate from the v1 bridge fix right after viewer access. When any profile on the account has a PIN, a rating ceiling, an advisory-age limit or a library restriction, a request without the header (or with an empty one) gets the 422 validation_failed problem at header.x-profile-id that profile-required operations answer. Unrestricted households keep account scope and API keys are exempt. An operation declaring the gate fails closed when it is not wired. Gated: getWatchState, getWatchTrickplay, the marker reads and writes, and the subtitle operations that act on one media file or stored subtitle (listing, search, download, upload, AI job create/read/list/cancel, sync, timing, stored metadata and delete). Capability probes, the AI quota, language detection, listUserLibraries, the recipe gallery, profile and account operations, playback delivery and direct downloads are unchanged. The X-Profile-Id description of the gated operations states the rule; 422 was already documented on all of them. The markers, subtitles, playback and API contract docs describe the change.
… store Add a route-inventory test that fails when a v1 route runs viewer access without a profile and neither carries the household gate nor is listed as exempt with a reason. Group the gated subtitle, download, direct-download and library-collection routes so the gated set is visible in router.go. The gate now refuses with 500 when it has no store, and the router mounts it only where it wires viewer access. ProfileIsLimited reuses MaturityLimits.Active. The gate comment no longer claims v2 refuses the same requests or that only admins hold API keys, and the contract docs cover the marker writes and their 403-to-400 change.
…e-optional-viewer-reads # Conflicts: # docs/architecture/v1-scope.md
…d gate Add a test that fails when a profile-optional or permission-gated operation neither declares HouseholdProfileGate nor is listed as exempt with a reason, so a new operation cannot inherit account scope by copying ProfileOptional. Document X-Profile-Id through one profileHeaderFor helper shared by structured and raw registration. The contract docs and the v1 scope row now name the gated v2 watch, marker and subtitle operations and say that v2 direct downloads still keep account scope, tracked in Silo-Server#1958.
…-gated operations
…ts only Say that a custom scope policy keyed on one profile does not make the household require a profile, and that ?token= download links get the same 400 on such an account.
…r' into fix/v2-profile-optional-viewer-reads
…olds
v1 GET /people, GET /people/{id} and POST /people/{id}/refresh were left
out of the household profile gate because their handlers applied no viewer
limits. Once person reads follow the viewer's visibility, a device on a
household with a PIN-locked or restricted profile could still read hidden
people at account scope by omitting X-Profile-Id. The three routes now sit
behind the same gate as the other v1 viewer reads.
# Conflicts: # docs/architecture/v1-scope.md
A device on a household with a PIN-locked or restricted profile could download any file by calling direct download with only the account token, because the browser starts the download by navigation and cannot send profile headers. createDirectDownloadLink, a profile-scoped operation, checks the file against the profile's access and returns a five-minute signed link bound to the session, profile and file. The direct-download routes accept that link as the credential and apply the profile's limits; on households with limited profiles they refuse an account token without a profile. The web app mints a link before each download.
# Conflicts: # internal/contractledger/ledger_test.go
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (58)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe change adds household profile gates to selected viewer operations and introduces short-lived, profile-bound direct-download links. It updates server routing, API contracts, web download behavior, capability reporting, documentation, and tests for these changes. ChangesHousehold Profile Access
Direct Download Links
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~60 minutes Change: Bug fix · Severity of issue fixed: Medium Sequence Diagram(s)sequenceDiagram
participant Picker as DownloadVersionPicker
participant API as Direct-download API
participant Handler as DownloadHandler
participant JWT as JWTService
participant Middleware as Direct-download auth middleware
participant Session as Session store
Picker->>API: POST link request with file and profile
API->>Handler: Authorize file and create link
Handler->>JWT: Sign session-, profile-, and file-bound token
JWT-->>Picker: Return link and expiry
Picker->>API: HEAD request to minted URL
API->>Middleware: Validate token and requested file
Middleware->>Session: Check active session
Session-->>Middleware: Session status
Suggested reviewers: Merge Risk: 🔵 Low · up to Direct-download links expire after five minutes, so a browser resume after that window will fail and the user must start the download again. This looks acceptable but should be documented or decided before merge. 🚥 Pre-merge checks | ✅ 3 | ❌ 1 | ❓ 1❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
Full details: Out of Scope Changes checkExplanation The direct-download changes support Resolution Remove the unrelated v1 viewer gates and the v2 watch, marker, and subtitle household-gate changes from this PR, or move them to separate PRs linked to their corresponding issues. Keep the household gate required for the v2 direct-download routes and their link flow. Full details: Docstring CoverageExplanation Docstring coverage is 56.06% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 66 functions across 45 files. (11 skipped: 10 unsupported, 1 too large.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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:
|
|
visible change: evidence is incomplete.
Suggested fix: No diff — add the requested API excerpts and web-flow recording, or state why the evidence could not be captured. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
# Conflicts: # internal/apiv2/parity_test.go
|
The validation line overstates the record: #1180 C2 is Suggested fix: Replace the PR-body line with Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Quick104
left a comment
There was a problem hiding this comment.
Review of the commits this PR adds on top of #1959 (68365b3a0..8ff5404c4). The link design holds up: a link token is refused everywhere else because every ValidateToken caller checks the token type, the proxy redirect does not carry dl, native request logs record only the path, and the link's profile replaces any header the caller sends. Three findings below: one defect, one doc correction, and one decision for you.
AI-generated review: Claude Code (claude-opus-5-5) with read-only finder subagents, plus a cross-provider review by Codex (gpt-6.1-sol). Each finding was checked against the source; the first was reproduced with a failing test.
| // DirectDownloadLinkTTL bounds how long a direct-download link may start a | ||
| // transfer. It is checked when the request arrives; a transfer that started in | ||
| // time may run longer. | ||
| const DirectDownloadLinkTTL = 5 * time.Minute |
There was a problem hiding this comment.
Needs your call: a dropped download can only be resumed for five minutes.
The link is checked on every request, including a browser's resume. When Chrome or Firefox resumes a failed or paused download, it re-requests the same URL with Range. Before this PR that URL carried the access token, which lives 8 hours by default (auth.access_token_expiry). Now a resume more than five minutes after the click gets 401 invalid_token, and for a multi-GB original the user starts over. The docs only promise that "a transfer that started in time may run longer"; a resume is a new request.
Options:
- Keep five minutes and document that a resume after it needs a new click.
- Lengthen the TTL (for example one hour, or the access-token expiry). The link is already narrow: one file, one profile, revoked with its session, and the profile's limits are re-checked on every request. The cost is a longer life for a URL that a proxy or browser history might keep.
- Accept an expired link only on a
Rangerequest whoseIf-Rangematches the file's validator. This needs more work, and browsers don't always sendIf-Range.
I'd lean towards 2, but it's a product decision, so I've left it alone.
… 503 A direct-download link whose session could not be checked was answered 401 session_expired, the same as a revoked session, with no Retry-After. Send the lookup error to the 503 dependency_unavailable response that RequireAuth and the Apple display token already use, and keep 401 for a session the store reports inactive. The download API doc now lists the 503 and says that a link sent with token is checked first, so only a valid link reaches the 422. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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:
|
Review summaryReviewed head: Fit: 8/10 · Readiness: 7/10 — conditional Addressed in this review
Still open
Checked and not a problem
Validated featuresThe board API wasn't readable from here ( Validation statusCI passes on User manualNo change needed for this PR: the manual doesn't describe direct downloads, and the web download button looks and behaves the same. The household rule from #1957/#1959 makes the "Act as a profile" section of the developer API page incomplete ("The request above works at the account level"), so that belongs on those PRs. I found no open siloserver.org issue or PR covering it. Apple and AndroidNeither app calls Scores
AI-generated review: Claude Code (claude-opus-5-5) with read-only finder subagents, plus a cross-provider round with Codex (gpt-6.1-sol), which independently found the store-outage defect and nothing else. |
Resolve the conflicts with Silo-Server#2022, which landed Silo-Server#1957 and Silo-Server#1959: keep main's direct-download gating and this branch's household-management rules.
Problem
Closes #1958
Related issue: #1179
Validation tasks: none (this changes #1180 C2 and #1250 C4, which are not run yet)
On a household with a PIN-protected or restricted profile, any device signed into the account can download a file the selected profile may not see, and get past the parent's PIN, by calling direct download with the account token and no profile. A kids profile's device downloaded an R-rated movie this way. The web app starts downloads by browser navigation, which cannot send profile headers, so the route could not simply require
X-Profile-Idwithout breaking web downloads.Merge order: after #1957 and #1959. This branch contains their commits; review the commits that are not in #1959.
Approach
A new profile-scoped operation,
POST /api/v2/direct-download/links, checks the file against the profile's access (and its PIN proof, like any profile-scoped operation) and returns a link that is valid for five minutes. The link carries a JWT signed with the session signing key, naming the account, login session, profile and one file.GET /api/v2/direct-downloadand-proxyaccept it as the only credential: the session must still be active, the file must match, and the request is resolved as that profile with its current limits. The token is refused as a bearer credential anywhere else.The download routes now apply #1959's household rule: on a household with a limited profile, a request with neither a link nor
X-Profile-Idgets the same 422 as other profile-required operations. Unrestricted households, API keys and clients that send the header behave as before, and the 200/206 responses are unchanged.GET /api/v2/capabilities/downloadsadvertisesdirect_download_links. The web app mints a link before each download and no longer puts the access token in the URL. Apple and Android do not call this route.Validation
7d4b8318e. The branch predates themainfix forinternal/catalog/catalog_resolver.go:2172, so it does not compile on its own; CI builds the merge withmainand passes.go build,gofmt,go vet,make lint-changed(0 issues), OpenAPI, web types, fixtures, contract (no breaking changes), route inventory, migration ledger and local path checks: pass. Web lint, format, build and bundle budget: pass.make test-goandmake test-webran on a tree combining this PR with the other profile-validation PRs: see the combined results in fix(access): give household and admin powers only to the primary profile #2019.403522adf: a link whose session cannot be checked because the store is down now gets503 dependency_unavailablewithRetry-Afterinstead of401 session_expired. A new test case for GET and HEAD on both routes fails before the fix and passes after;go testforinternal/apiv2,internal/api/middleware,internal/authandinternal/api/handlerspasses.Evidence
The web download button looks the same; what changes is who can fetch the file. Same requests on both builds, household with a PG kids profile:
Before (`7d4b8318e` (main)) and after (`583d034eb`)
Before (
/direct-download/linksdoes not exist on this build):After:
Surface and build: API, before
7d4b8318e(main), after583d034eb.Risks
?token=on a restricted household now gets 422 and has to sendX-Profile-Idor use a link.?token=download links keep fix(api/v1): require a profile on viewer routes when the account has locked or restricted profiles #1957's 400 on such households; v1 gets no link support.Checklist
AI Disclosure
?token=requests, log redaction of the link and the web flow's staleness guards. It found no defects.Note
Add profile-bound short-lived direct-download links to the download API
POST /api/v2/direct-download/links, which mints a JWT download token bound to one session, one profile, and one file, valid for five minutes (direct_download.go, jwt.go)dlquery parameter and authenticate link tokens throughRequireDirectDownloadAuth(direct_download_link.go)DownloadVersionPickernow mints a link, probes it with HEAD, and navigates to the link URL instead of embedding the account token in the URL (directDownloads.ts)X-Profile-Idwhen the account has a PIN-protected or access-restricted profile (household_profile_gate.go)direct_download_linksfieldMacroscope summarized 403522a.