Repository navigation
fix(api/v1): require a profile on viewer routes when the account has locked or restricted profiles - #1957
fix(api/v1): require a profile on viewer routes when the account has locked or restricted profiles#1957Rhainland wants to merge 7 commits into
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (6)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughSelected v1 viewer routes now require ChangesHousehold Profile Gate
Priority: ➖ Normal Estimated code review effort: 4 (Complex) | ~45 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change makes v1 viewer routes require a profile header on households with restricted profiles. The behavior is documented and tested, and no actionable merge-blocking risk was found. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 76.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 10 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 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:
|
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:
|
Quick104
left a comment
There was a problem hiding this comment.
Code review of 950023a. The main finding is that this closes the profile-less bypass on v1, but the same bypass stays open on several v2 operations, and the PR text says v2 already refuses those requests (see the comment on household_profile_gate.go line 18).
The other comments cover:
- no test that pins which routes carry the gate;
- the API-key exemption's rationale;
- header-less v1 download links;
- marker writes;
- two cleanups.
The profile query cost already has a thread, so I replied there. Comments marked "needs your call" need a decision from the author or a maintainer.
Validation: this change reaches no passed case on the v1.0 board. The PR body's Validation tasks: changes #1250 C4 (Not run) names a case nobody has run yet. That belongs in a separate note; the line itself would be none.
AI disclosure: written by claude-opus-5-5 in Claude Code via T3 Code (/silo code-review). Separate verifier agents checked each finding against the code.
… 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.
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:
|
|
From the review summary: the |
…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.
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's pull request guidance changed today (#2016). A PR that changes what a user sees now needs before-and-after evidence in its Evidence section, and a PR with no visible change says Missing here: Needs the line 'Evidence: none, no user-visible change' (first-party clients already send the profile header), or before-and-after API excerpts if you consider the new 400 visible. The rules are in Show visible changes, and the PR template shows the Evidence section layout. I've converted this PR to draft for now. Mark it ready for review once the Evidence section is filled in. Generated by Claude Code |
|
The item-detail excerpt demonstrates the profile-less 200→400 change for that endpoint, but the evidence does not cover these other visible effects:
The existing surface/build line can identify the additional captures. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
…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.
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:
|
|
Since the earlier evidence comment, the new commit adds the household gate to v1 Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Added representative catalog browse/query, watch, collection, subtitle, metadata, and marker-write comparisons. Direct download with bearer authentication and a token query link changes from 200 media bytes to 400 when the profile header is absent. The current body already includes the newer people-route comparison. Changed unblocks to changes for #1180 C2. |
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
Related issue: N/A
Validation tasks: changes #1180 C2
On the v1 bridge, a device signed into a household account can get past a child profile's limits, and past the parent profile's PIN, by leaving out the
X-Profile-IDheader. v1 viewer reads are profile-optional, and without a profile they resolve to the account's own limits, which have no rating, advisory or profile library restriction. With the account token,GET /api/v1/catalog/items/{id}for a TV-MA series returns 404 with the TV-Y7 profile's header and 200, full detail, with no header. v2 refuses both (422for the missing header,profile_verification_requiredfor a locked profile), and v1 playback start already requires the header.v1 is frozen to critical fixes, and this one is a parental-control and PIN bypass. On an account where any profile has a PIN, a rating ceiling, an advisory-age limit or library restrictions, the affected v1 viewer routes now refuse a request without
X-Profile-ID, using the same400 bad_request"X-Profile-Id header is required" response that v1 playback start returns. Accounts whose profiles are all unrestricted keep today's behaviour.Approach
A middleware runs after
RequireViewerAccesson the profile-optional v1 viewer routes: catalog browse, detail, filters, query and seasons; watch detail; people search, detail and refresh; library collections; marker reads and writes; subtitle reads and writes; item description translation and trailer refresh; and downloads, including direct download. A request that names a profile passes, since the profile and its PIN token were already checked. API keys pass. Marker writes run the gate before theirmarker_editcheck, so a caller without that permission that omits the header now gets 400 instead of 403. The route inventory marks each route with a newhousehold_profile_gatetrait, andcontracts/api/v2/route-inventory.jsonandmigration.jsonwere regenerated.These stay profile-optional, because they either carry their own profile binding or are needed before a profile is chosen:
/profilesand/user/libraries;The people routes are gated too: once #1948 makes them follow the viewer's visibility, leaving out the header would otherwise still list and open hidden people. v2 is unchanged here: #1959 applies the same rule to v2's profile-optional watch, marker and subtitle operations, and #2021 covers v2 direct download (#1958).
Validation
/api/v1/profileswithout the header: 200.make verify-route-inventory,verify-apiv2-openapi,verify-apiv2-contract,verify-offline-routes,verify-migration-ledger,verify-local-paths,make lint-changed,gofmt, and the focused package tests: pass.make test-gowas not run locally.7d4b8318e.mainatca4f71b6edoes not compile (internal/catalog/catalog_resolver.go:2172), so CI fails on that file untilmainis fixed.docs/architecture/v1-scope.mdand indocs/architecture/api-contract.md.Supplementary API evidence covers representative viewer route families, direct media-byte downloads with bearer/token authentication, and marker-write gate precedence.
Evidence: https://evidence.siloserver.org/r/silo-server/pr-1957/
Evidence
Same request both times: the account's access token, no
X-Profile-ID, detail of a TV-MA series.Before
After
Unchanged on both builds: the same request with the Kids profile's
X-Profile-IDanswers404 not_found, andGET /api/v1/profileswithout the header answers 200.Surface and build: native API v1 item detail; before 7d4b831 (main), after ac9c226 (PR head). Test library with fictional titles, on an account with a PIN-protected Adult profile and a TV-Y7 Kids profile.
People routes
v1 people routes with the account token and no
X-Profile-Id, household with a PG kids profile:Before (`7d4b8318e` (main)) and after (`6152bd46f`)
Before:
After:
Surface and build: API, before
7d4b8318e(main), after6152bd46f. First-party clients always send the profile header, so their screens do not change.Risks
X-Profile-IDonce a profile is stored, including from the background download session. The one call it makes before a profile is chosen,/user/libraries, is not gated.?token=, which cannot send the header. v1 gets no profile query parameter for them; v2's byte routes are Direct download ignores the selected profile's limits and PIN #1958.silo_custom.scopeoverride that narrows one profile throughinput.profile_idstill applies to requests naming that profile, but doesn't make the household require one. Requests without a profile kept account scope before this change too. The contract doc says a profile needs a stored limit for the gate to apply.Checklist
AI Disclosure
Note
Add
household_profile_gatemiddleware to require a profile on v1 viewer routesX-Profile-Idor API-key claim bypasses the gate (household_profile_gate.go).ProfileIsLimitedandHouseholdRequiresProfilein household.go.newChiRouterto catalog, people, marker, collection, metadata, subtitle, and download viewer routes; capability, account, profile-selection, and managed-download routes stay profile-optional (router.go).writeProfileHeaderRequiredhelper fromRequireProfileso the gate returns the exact existing denial response (profile.go).router.gonow return 400 for restricted households instead of account-scope answers; the gate fails closed with 500 on store errors when no store provider is configured (TestHouseholdProfileGateWithoutStoreFailsClosed).Macroscope summarized ef3a869.