Skip to content

fix(api/v1): require a profile on viewer routes when the account has locked or restricted profiles - #1957

Closed
Rhainland wants to merge 7 commits into
Silo-Server:mainfrom
Rhainland:fix/v1-profile-scope-without-header
Closed

Rhainland wants to merge 7 commits into
Silo-Server:mainfrom
Rhainland:fix/v1-profile-scope-without-header

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

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-ID header. 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 (422 for the missing header, profile_verification_required for 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 same 400 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 RequireViewerAccess on 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 their marker_edit check, so a caller without that permission that omits the header now gets 400 instead of 403. The route inventory marks each route with a new household_profile_gate trait, and contracts/api/v2/route-inventory.json and migration.json were regenerated.

These stay profile-optional, because they either carry their own profile binding or are needed before a profile is chosen:

  • stream and transcode media routes, whose session was started with a verified profile;
  • /profiles and /user/libraries;
  • capability probes and account routes.

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

  • Black-box against a local server, on an account with a PIN-protected parent and a TV-Y7 child:
    • v1 catalog and item detail without the header: 400;
    • the same detail with the child's header: 404;
    • /api/v1/profiles without the header: 200.
    • On a second account whose only profile is unrestricted, v1 reads without the header still work, and account library limits still apply.
  • Tests cover which profiles count as restricted, the middleware for restricted and unrestricted households, header present, API key, lookup failures and a missing store, and a v1 route through the production policy resolver. A route-inventory test fails when a v1 route runs viewer access without a profile and is neither gated nor listed as exempt with a reason.
  • Series — Server #1250 C4 covers this behaviour but has not been run yet.
  • 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-go was not run locally.
  • People routes: a test drives them through viewer access and the gate (400 without the header on a restricted household, 200/202 with the child's header or on an unrestricted household); checked on a running server, see Evidence.
  • Merged with 7d4b8318e. main at ca4f71b6e does not compile (internal/catalog/catalog_resolver.go:2172), so CI fails on that file until main is fixed.
  • The change is recorded in the pre-lock table in docs/architecture/v1-scope.md and in docs/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

GET https://<server>/api/v1/catalog/items/{harborLightsId}
Authorization: Bearer <account token>

HTTP/1.1 200 OK
{
  "type": "series",
  "title": "Harbor Lights",
  "year": 2019,
  "overview": "A fishing town keeps its secrets after a storm.",
  "content_rating": "TV-MA",
  "cast": [{ "name": "Marlow Quint", "character": "Harbor Master", "person_id": "9001" }]
}

After

GET https://<server>/api/v1/catalog/items/{harborLightsId}
Authorization: Bearer <account token>

HTTP/1.1 400 Bad Request
{
  "error": "bad_request",
  "message": "X-Profile-Id header is required"
}

Unchanged on both builds: the same request with the Kids profile's X-Profile-ID answers 404 not_found, and GET /api/v1/profiles without 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:

# v1 people routes, account token with no X-Profile-Id (household has a PG kids profile)
GET /api/v1/people?q=Cranston                                              -> 200 ['Bryan Cranston']
GET /api/v1/people/<Bryan Cranston>                                        -> 200 name="Bryan Cranston"

After:

# v1 people routes, account token with no X-Profile-Id (household has a PG kids profile)
GET /api/v1/people?q=Cranston                                              -> 400 X-Profile-Id header is required
GET /api/v1/people/<Bryan Cranston>                                        -> 400 bad_request: X-Profile-Id header is required

Surface and build: API, before 7d4b8318e (main), after 6152bd46f. First-party clients always send the profile header, so their screens do not change.

Risks

  • Clients:
    • silo-android makes no v1 calls to the gated routes.
    • silo-apple still uses v1 for catalog, subtitles and downloads, and sends X-Profile-ID once 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.
    • A third-party v1 client that never sends a profile now gets 400 on accounts with locked or restricted profiles. This includes download links that pass the token as ?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.
  • Custom scope policies: the gate decides from the profiles' stored PIN, rating, advisory and library limits. A custom silo_custom.scope override that narrows one profile through input.profile_id still 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.
  • Cost: each gated request without the header makes two indexed reads: the account's profiles and their allowed libraries.

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); Codex harness in T3 Code (review cleanup)
  • Tool(s): Claude Code, GitHub CLI
  • Model(s): claude-opus-5-5; gpt-6.1-sol
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: n/a

Note

Add household_profile_gate middleware to require a profile on v1 viewer routes

  • Adds a new middleware that rejects profile-less v1 viewer requests with 400 bad_request when any account profile has a PIN, maturity limit, or enabled library restriction. A present X-Profile-Id or API-key claim bypasses the gate (household_profile_gate.go).
  • Classifies limited profiles via new predicates ProfileIsLimited and HouseholdRequiresProfile in household.go.
  • Applies the gate in newChiRouter to catalog, people, marker, collection, metadata, subtitle, and download viewer routes; capability, account, profile-selection, and managed-download routes stay profile-optional (router.go).
  • Extracts the shared writeProfileHeaderRequired helper from RequireProfile so the gate returns the exact existing denial response (profile.go).
  • Updates the migration contract, schema, route inventory, and docs for the new middleware.
  • Risk: Behavioral Change — profile-less requests to the newly gated routes in router.go now 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.

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

coderabbitai Bot commented Oct 4, 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: 1065f1c3-05ce-4d6b-9d21-2409ab21ab2f
📥 Commits

Reviewing files that changed from the base of the PR and between ac9c226 and 6152bd4.

📒 Files selected for processing (6)
  • contracts/api/v2/migration.json
  • contracts/api/v2/route-inventory.json
  • docs/architecture/v1-scope.md
  • internal/api/handlers/household_profile_gate_v1_test.go
  • internal/api/household_profile_gate_routes_test.go
  • internal/api/router.go

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


📝 Walkthrough

Walkthrough

Selected v1 viewer routes now require X-Profile-Id when an account has a profile PIN, maturity limit, or library restriction. The change adds household checks and middleware, wires the gate to routes, updates route inventory records, and documents route behavior and exemptions.

Changes

Household Profile Gate

Layer / File(s) Summary
Determine and enforce profile requirements
internal/access/household.go, internal/access/household_test.go, internal/api/middleware/household_profile_gate*, internal/api/middleware/profile.go
Household checks treat PINs, active maturity limits, and library restrictions as profile limitations. Middleware checks the household when a request has no profile header. Missing headers receive the shared 400 bad_request response when a profile is required. Tests cover the checks, middleware outcomes, and response consistency.
Wire the gate into v1 routes and inventory
internal/api/router.go, internal/api/handlers/household_profile_gate_v1_test.go, internal/api/household_profile_gate_routes_test.go, internal/routeinventory/*, contracts/api/v2/*, docs/architecture/*
Selected viewer routes use the gate, while documented exempt routes remain outside it. Route inventory records the household_profile_gate trait and updated middleware chains. Tests check route coverage and selected handler behavior. The schema and architecture documents record the trait and gate rules.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to 6152b

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: requiring profiles on affected v1 viewer routes for accounts with locked or restricted profiles.
Description check ✅ Passed The description directly explains the problem, implementation, affected and exempt routes, validation, evidence, and risks. It is fully related to the changeset.
Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 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 4, 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 4, 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 ❌
⚠️ 1 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers

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

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.

Comment thread internal/api/router.go Resolved
Comment thread internal/access/household.go Resolved
Comment thread internal/api/router.go Resolved
Comment thread internal/api/router.go Resolved
Comment thread internal/access/household.go Resolved
… 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

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

@Rhainland Rhainland changed the title fix(api/v1): require a profile on viewer reads when the account has locked or restricted profiles fix(api/v1): require a profile on viewer routes when the account has locked or restricted profiles Oct 5, 2026
@Rhainland

Copy link
Copy Markdown
Contributor Author

From the review summary: the Validation tasks: line now reads none, and the note that #1250 C4 covers this behaviour but has not been run yet is in the Validation section.

…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

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 ❌

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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 Evidence: none, no user-visible change. This PR was opened before the rule existed, so it hasn't had a chance to meet it yet.

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

@Quick104
Quick104 marked this pull request as draft October 6, 2026 19:19
@Rhainland
Rhainland marked this pull request as ready for review October 6, 2026 19:50
@macroscopeapp

macroscopeapp Bot commented Oct 6, 2026

Copy link
Copy Markdown

The item-detail excerpt demonstrates the profile-less 200→400 change for that endpoint, but the evidence does not cover these other visible effects:

  • internal/api/router.go: profile-less requests to the other gated route families (catalog browse/query, watch/work, library collections, subtitles, and metadata actions) are also changed. Add before-and-after API excerpts from representative routes in these families.
  • internal/api/router.go: download and direct-download requests, including ?token= links, now fail without a profile header. Add before-and-after excerpts for a byte-download route; the item-detail JSON example does not show this behavior.
  • internal/api/router.go: marker writes run the gate before marker_edit, so a caller lacking that permission now gets 400 instead of 403. Add before-and-after marker-write responses showing this status change.

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

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

Since the earlier evidence comment, the new commit adds the household gate to v1 /people, /people/{id}, and /people/{id}/refresh (internal/api/router.go). On restricted households, profile-less calls now return 400, but the Evidence section still says /people is not gated and has no before-and-after API excerpt for this route family. Please add same-request before-and-after excerpts for this behavior and identify the surface and current build/commit.

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

Posted via Macroscope — Visible change evidence

@Rhainland

Copy link
Copy Markdown
Contributor Author

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.

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

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.
@Rhainland

Copy link
Copy Markdown
Contributor Author

Closing as superseded. These changes landed on main through #2022 (squash commit aebcf08), which was built on this branch. Merging main into this branch leaves an empty diff.

@Rhainland Rhainland closed this Oct 9, 2026
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.

2 participants