Skip to content

fix(downloads): carry the profile in a short-lived direct-download link - #2022

Merged
Quick104 merged 18 commits into
Silo-Server:mainfrom
Rhainland:fix/direct-download-profile-link
Oct 7, 2026
Merged

Quick104 merged 18 commits into
Silo-Server:mainfrom
Rhainland:fix/direct-download-profile-link

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

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-Id without 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-download and -proxy accept 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-Id gets 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/downloads advertises direct_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

  • Built on fix(apiv2): require a profile on viewer operations when the account has locked or restricted profiles #1959 merged with 7d4b8318e. The branch predates the main fix for internal/catalog/catalog_resolver.go:2172, so it does not compile on its own; CI builds the merge with main and 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.
  • Focused Go and web tests for link minting, the link on both routes, expired, altered and wrong-file links, the household rule and the web download flow: pass.
  • make test-go and make test-web ran 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.
  • On a running server: a kids profile's link works for an allowed title, is refused for a restricted one, and cannot be reused for another file; an account token alone is refused.
  • Review fix 403522adf: a link whose session cannot be checked because the store is down now gets 503 dependency_unavailable with Retry-After instead of 401 session_expired. A new test case for GET and HEAD on both routes fails before the fix and passes after; go test for internal/apiv2, internal/api/middleware, internal/auth and internal/api/handlers passes.

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/links does not exist on this build):

# direct download of an R-rated file (household has a PG kids profile)
GET /api/v2/direct-download?file_id=<The Matrix>&token=<account token>     -> 206
POST /api/v2/direct-download/links as Kiddo, file <The Matrix>             -> 404 not_found
POST /api/v2/direct-download/links as Kiddo, file <Toy Story>              -> 404 not_found

After:

# direct download of an R-rated file (household has a PG kids profile)
GET /api/v2/direct-download?file_id=<The Matrix>&token=<account token>     -> 422 validation_failed
POST /api/v2/direct-download/links as Kiddo, file <The Matrix>             -> 404 not_found
POST /api/v2/direct-download/links as Kiddo, file <Toy Story>              -> 200
  GET returned url (no Authorization header)                               -> 206

Surface and build: API, before 7d4b8318e (main), after 583d034eb.

Risks

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (running in T3 Code)
  • Tool(s): Claude Code, GitHub CLI, Playwright (evidence capture)
  • Model(s): claude-opus-5-5
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: An independent Claude Code review agent (claude-opus-5-5) checked token confusion in both directions, session revocation, profile and file substitution, proxy parity, the household rule on ?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

  • Adds 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)
  • Direct-download routes now accept a dl query parameter and authenticate link tokens through RequireDirectDownloadAuth (direct_download_link.go)
  • The web DownloadVersionPicker now mints a link, probes it with HEAD, and navigates to the link URL instead of embedding the account token in the URL (directDownloads.ts)
  • Adds a household profile gate middleware: profile-optional viewer routes (v1 and v2) reject requests without X-Profile-Id when the account has a PIN-protected or access-restricted profile (household_profile_gate.go)
  • Behavioral Change: many v1 viewer routes and v2 marker, subtitle, and watch routes now require a profile header for limited households; the gate fails closed when the household middleware is unwired; download capability responses add a direct_download_links field

Macroscope summarized 403522a.

…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.
…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
@Rhainland
Rhainland requested a review from Quick104 as a code owner October 6, 2026 23:01
@coderabbitai

coderabbitai Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dcd15a27-d984-4070-9878-05294a1ab142
📥 Commits

Reviewing files that changed from the base of the PR and between 4bed990 and 403522a.

📒 Files selected for processing (58)
  • contracts/api/v2/fixtures/download_capability.json
  • contracts/api/v2/migration.json
  • contracts/api/v2/migration.schema.json
  • contracts/api/v2/openapi.json
  • contracts/api/v2/route-inventory.json
  • docs/architecture/api-contract.md
  • docs/architecture/v1-scope.md
  • docs/downloads-api.md
  • docs/markers-api.md
  • docs/playback-api.md
  • docs/subtitles-api.md
  • internal/access/household.go
  • internal/access/household_test.go
  • internal/api/handlers/downloads.go
  • internal/api/handlers/household_profile_gate_v1_test.go
  • internal/api/household_profile_gate_routes_test.go
  • internal/api/middleware/direct_download_link.go
  • internal/api/middleware/household_profile_gate.go
  • internal/api/middleware/household_profile_gate_test.go
  • internal/api/middleware/profile.go
  • internal/api/middleware/viewer_access.go
  • internal/api/router.go
  • internal/api/router_v2_household_test.go
  • internal/api/testdata/media_routes.txt
  • internal/apiv2/direct_download.go
  • internal/apiv2/direct_download_link_test.go
  • internal/apiv2/document.go
  • internal/apiv2/download_demo_test.go
  • internal/apiv2/download_registry.go
  • internal/apiv2/gates.go
  • internal/apiv2/household_profile_gate_test.go
  • internal/apiv2/markers.go
  • internal/apiv2/parity_test.go
  • internal/apiv2/raw_registration.go
  • internal/apiv2/registry.go
  • internal/apiv2/router.go
  • internal/apiv2/subtitle_ai_cancel.go
  • internal/apiv2/subtitle_ai_create.go
  • internal/apiv2/subtitle_ai_reads.go
  • internal/apiv2/subtitle_delete.go
  • internal/apiv2/subtitle_download.go
  • internal/apiv2/subtitle_reads.go
  • internal/apiv2/subtitle_sync.go
  • internal/apiv2/subtitle_sync_targets.go
  • internal/apiv2/subtitle_upload.go
  • internal/apiv2/watch.go
  • internal/apiv2/watch_trickplay.go
  • internal/auth/jwt.go
  • internal/auth/jwt_test.go
  • internal/contractledger/ledger_test.go
  • internal/routeinventory/analyze_test.go
  • internal/routeinventory/classify.go
  • web/src/api/v2/directDownloads.test.ts
  • web/src/api/v2/directDownloads.ts
  • web/src/api/v2/operations.ts
  • web/src/api/v2/request.ts
  • web/src/api/v2/schema.ts
  • web/src/components/DownloadVersionPicker-rejection.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Household Profile Access

Layer / File(s) Summary
Household profile requirement and middleware
internal/access/household.go, internal/access/household_test.go, internal/api/middleware/household_profile_gate.go, internal/api/middleware/household_profile_gate_test.go, internal/api/middleware/profile.go, internal/api/handlers/household_profile_gate_v1_test.go, internal/api/household_profile_gate_routes_test.go
Profile PINs, active maturity limits, and enabled library restrictions determine whether a household requires profile selection. The middleware checks profile-less requests, while tests cover response behavior and v1 route coverage.
Gate selected viewer routes and declare operation metadata
internal/api/router.go, internal/apiv2/gates.go, internal/apiv2/registry.go, internal/apiv2/router.go, internal/apiv2/raw_registration.go, internal/apiv2/markers.go, internal/apiv2/subtitle_*.go, internal/apiv2/watch*.go, internal/apiv2/document.go, internal/routeinventory/*, internal/apiv2/household_profile_gate_test.go, internal/apiv2/parity_test.go
V1 route groups and declared V2 operations use the household gate. Operation metadata records the gate, and tests check gate order, coverage, exemptions, and generated header documentation.
Household profile API contract and documentation
contracts/api/v2/migration.schema.json, contracts/api/v2/openapi.json, web/src/api/v2/schema.ts, docs/architecture/api-contract.md, docs/architecture/v1-scope.md, docs/markers-api.md, docs/playback-api.md, docs/subtitles-api.md
Contracts and documentation describe when a profile header is required, the missing-header response, and the API-key exemption. The route inventory adds the household_profile_gate trait.

Direct Download Links

Layer / File(s) Summary
Mint and validate profile-bound links
internal/auth/jwt.go, internal/api/handlers/downloads.go, internal/api/middleware/direct_download_link.go, internal/api/middleware/viewer_access.go, internal/apiv2/direct_download.go, internal/apiv2/gates.go, internal/api/router.go, internal/apiv2/router.go
The server creates five-minute tokens bound to a login session, profile, and file. The download routes validate the token, file match, and active session before resolving access under the token’s profile.
Verify link issuance and delivery behavior
internal/auth/jwt_test.go, internal/apiv2/direct_download_link_test.go, internal/contractledger/ledger_test.go, internal/api/testdata/media_routes.txt
Tests cover token claims, link minting, authorization, ranged and HEAD delivery, session failures, invalid links, and media-route classification.
Expose link creation and use it in the web client
contracts/api/v2/openapi.json, contracts/api/v2/fixtures/download_capability.json, internal/apiv2/download_registry.go, internal/apiv2/download_demo_test.go, web/src/api/v2/schema.ts, web/src/api/v2/operations.ts, web/src/api/v2/request.ts, web/src/api/v2/directDownloads.ts, web/src/api/v2/directDownloads.test.ts, web/src/components/DownloadVersionPicker-rejection.test.tsx, docs/downloads-api.md
The API contracts add link creation, the direct_download_links capability, and the dl query credential. The web picker mints and probes a link, then navigates only while its captured profile context remains current.

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
Loading

Suggested reviewers: quick104

Merge Risk: 🔵 Low · up to 40352

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)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The direct-download changes support #1958. The PR also adds unrelated household gates for v1 catalog, people, library, subtitle, managed-download, and direct-download routes in `internal/api/router.go… 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 …
Docstring Coverage ❓ Inconclusive 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… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed For #1958, the PR adds the profile-scoped POST /api/v2/direct-download/links endpoint. The link binds the account, session, profile, and file. The download and proxy routes validate the link, requir…
Title check ✅ Passed The title clearly describes the primary change: profile-bound, short-lived direct-download links.
Description check ✅ Passed The description directly explains the direct-download security problem, implementation, behavioral changes, validation, risks, and user-visible impact.
Full details: Out of Scope Changes check

Explanation

The direct-download changes support #1958. The PR also adds unrelated household gates for v1 catalog, people, library, subtitle, managed-download, and direct-download routes in internal/api/router.go. It marks v2 watch, marker, and subtitle operations with HouseholdProfileGate. #1958 defines its scope as v2 direct downloads and states that the v2 watch, marker, and subtitle gaps are fixed separately. These route changes are not required to implement the linked issue.

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 Coverage

Explanation

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.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@silo-kody

silo-kody Bot commented Oct 6, 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 6, 2026

Copy link
Copy Markdown

visible change: evidence is incomplete.

  • internal/api/router.go now requires a profile for profile-less v1 viewer requests on limited households, changing catalog/search/detail, people, collection, subtitle, marker, and ephemeral-download responses. The Evidence section only shows direct-download requests; add before/after API response excerpts for the affected v1 browse and item-action requests.
  • The HouseholdProfileGate operations in internal/apiv2/gates.go and the watch, marker, and subtitle registrations change profile-less responses to 422 on limited households. Add before/after API response excerpts for these v2 operations; the current excerpts cover direct downloads only.
  • web/src/api/v2/directDownloads.ts changes the browser flow to mint a link, probe it with HEAD, and then navigate to it. The API excerpts do not show this web flow; add a short recording of the download interaction with the surface and build/commit, or explain why it could not be captured.

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

@macroscopeapp

macroscopeapp Bot commented Oct 6, 2026

Copy link
Copy Markdown

The validation line overstates the record: #1180 C2 is Not run, not failed or blocked. Issue #1958 was found during #1250 C4, but that case is also Not run; neither qualifies as an unblocks result. The diff changes the access/download paths these cases will exercise.

Suggested fix: Replace the PR-body line with Validation tasks: changes #1180 C2; changes #1250 C4.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs/downloads-api.md Resolved
Comment thread internal/auth/jwt.go
// 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Keep five minutes and document that a resume after it needs a new click.
  2. 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.
  3. Accept an expired link only on a Range request whose If-Range matches the file's validator. This needs more work, and browsers don't always send If-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

silo-kody Bot commented Oct 7, 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 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review summary

Reviewed head: 403522adf (the PR's commits on top of #1959, 68365b3a0..403522adf). The household-rule commits from #1957 and #1959 are reviewed on those PRs.

Fit: 8/10 · Readiness: 7/10 — conditional

Addressed in this review

  • Store outage answered as a revoked session (medium): a link whose session couldn't be checked got 401 session_expired with no Retry-After. It now gets 503 dependency_unavailable, matching RequireAuth. The fix and a GET/HEAD test on both routes are in 403522adf; the test fails on 8ff5404c4.
  • dl + token docs (low): docs/downloads-api.md said this is always 422, but an invalid link is checked first and stays 401. It also now lists the 503.
  • PR body: Validation tasks: named Multi-profile / PIN / kids — Server #1180 C2 as unblocked, but that case and Series — Server #1250 C4 are recorded as Not run. The line now reads none, with those two noted as changed. The note that CI would fail on catalog_resolver.go is updated: CI builds the merge with main and passes.

Still open

Checked and not a problem

  • A link token can't be used as a credential anywhere else: every ValidateToken caller (v1/v2 auth, media grants, current authority, plugin routes) checks the token type, and the tests cover ?token= and bearer misuse.
  • The link's profile replaces any X-Profile-Id/X-Profile-Token header, and the profile's current limits are re-checked when the link is used.
  • Native request and activity logs record only the path, so dl doesn't reach Silo's logs. The proxy redirect is built from a stream token and doesn't carry dl.
  • The web picker only renders under RequireProfile, so the new "no profile → stale context" path can't silently swallow a click.

Validated features

The board API wasn't readable from here (read:project scope), so I checked the validation task bodies directly. This PR's commits touch no passed case: API keys (#1190) keep calling direct download with their own credential and can't mint links (403). Admin impersonation (#1199, #1200) carries the impersonator through the link unchanged. The cases this changes, #1180 C2 and #1250 C4, are not run yet.

Validation status

CI passes on 403522adf. Locally, go test for internal/apiv2, internal/api/middleware, internal/auth and internal/api/handlers passed; gofmt and go vet are clean. I didn't run a sandbox: the fix only changes the status of a store-error response, which the test covers.

User manual

No 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 Android

Neither app calls /api/v2/direct-download on main, so no follow-up is needed. jellycompat downloads go through its own profile-bound session and don't need dl.

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.

@Quick104
Quick104 merged commit aebcf08 into Silo-Server:main Oct 7, 2026
24 checks passed
Quick104 added a commit to Rhainland/silo-server that referenced this pull request Oct 7, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Direct download ignores the selected profile's limits and PIN

2 participants