Repository navigation
fix(access): take admin reach on profile routes from the acting profile - #2370
Conversation
Routes outside the admin groups granted admin powers from the account's admin role, so a child profile on an admin account could read and cancel every account's media requests (and see their download-server details), delete other accounts' downloaded subtitles, see on-disk file paths, read any admin job, add admin-only home sections, and receive administrator events on the v1 socket. The admin routes already refuse that profile. Add apimw.ActingAdmin, which answers with the same decider the acting-admin gate uses (installed by ProvideActingAdmin) and only counts a profile the viewer gate verified. Use it on those routes in v1 and v2. The v2 job polls now run the viewer gate so a declared profile is verified; the v1 events socket decides on its ticket's profile and rechecks the decision while it holds the admin channels. Co-Authored-By: Claude Opus 5.5 <[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:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The change limits admin reach on profile routes to the acting profile and fails closed on errors. No concrete merge-blocking risk is established from the supplied context. Pre-merge checks ·
|
Quick104
left a comment
There was a problem hiding this comment.
Adversarial review (gpt-6.1-sol, reviewed 4d4891f)
Two findings in the v1 events socket's authority recheck. Focused acting-admin, HTTP-route, PIN-token and socket tests pass; the new v1 recheck test exercises a false decision but does not exercise PIN-revision invalidation or a decider error.
| if claims.Role == models.RoleAdmin { | ||
| stillActingAdmin = apimw.ActingAdmin | ||
| if apimw.GetProfileID(r.Context()) == "" && boundProfileID != "" { | ||
| stillActingAdmin = func(ctx context.Context) (bool, error) { return apimw.ActingAdminAs(ctx, boundProfileID) } |
There was a problem hiding this comment.
[P1] Revalidate primary-profile PIN proof during socket checks
Open a v1 administrator socket with a ticket minted for the primary profile, then set or change that profile's PIN while the login session stays active. Every recheck calls ActingAdminAs with only the profile ID; the router's primary checker reads IsPrimary, and neither the ticket nor this callback retains the PIN proof or revision. The decision therefore remains allowed after the old proof has been invalidated, and the socket keeps administrator channels and other accounts' events indefinitely. The header-based path has the same problem because ActingAdmin reads the handshake's unchanged ProfileVerified scope. CheckProfileToken rejects a changed PIN revision, and the v2 socket re-resolves that proof on each check. Retain session-bound profile proof in the v1 ticket and re-resolve viewer verification at the handshake and each interval; close when it no longer verifies. Cover a real PIN-revision change in the socket test.
There was a problem hiding this comment.
The mechanism is real, but this PR does not introduce it, so I am leaving it out of this change. On main, the v1 socket gives the administrator channels to every profile on an admin account and never looks at profile proof. A PIN change could not narrow it before, and this PR only narrows it further. Rechecking the proof on v1 needs new plumbing on the frozen bridge: the viewer resolver in the events handler, plus the PIN token kept with the ticket, which the v1 ticket store does not carry today. The v2 socket already re-resolves the proof on each check, and current clients use v2. I will raise it with the maintainer as a follow-up rather than widen this bridge fix.
There was a problem hiding this comment.
Filed as #2383, confirmed against main and this branch. The fix needs the profile token kept with the v1 ticket, plus changes to the recheck this PR rewrites, so it should land after this PR. The related v2 events-socket gap from the Risks section is #2384. It is narrower than the Risks line says: only the events socket is open to new profile-less admin sessions, admin-logs only for sockets opened before the household changed, and playback control and Watch Together not at all.
A v1 events connection holding the administrator channels kept them while the acting-admin decision could not be made (profile store or policy evaluation down). Treat a failed recheck as lost authority, like the HTTP routes do, so the client reconnects and is decided afresh. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ture ProvideActingAdmin only makes the acting-admin decision available to handlers and admits nothing, so it belongs with the base stack. Without it every route carried an unclassified_middleware trait and the migration ledger disagreed with the inventory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| actingAdmin, _ := apimw.ActingAdmin(r.Context()) | ||
| writeJSON(w, http.StatusAccepted, adminJobToResponseFor(r, job, nil, actingAdmin)) |
There was a problem hiding this comment.
Administrator visibility leak in internal/api/handlers/admin.go occurs because discarding the apimw.ActingAdmin error accepts the legacy decider’s (true, err) result when a profile-less household lookup fails, exposing the unsanitized item-refresh request, including scan_path and canonical_root_path, instead of failing closed. Set actingAdmin to false on any lookup error here and in internal/apiv2/admin_catalog_item_metadata.go:86, while still returning the already-created job.
actingAdmin, adminErr := apimw.ActingAdmin(r.Context())
if adminErr != nil {
actingAdmin = false
}
writeJSON(w, http.StatusAccepted, adminJobToResponseFor(r, job, nil, actingAdmin))Prompt for LLM
File internal/api/handlers/admin.go:
Line 1627 to 1628:
Administrator visibility leak in `internal/api/handlers/admin.go` occurs because discarding the `apimw.ActingAdmin` error accepts the legacy decider’s `(true, err)` result when a profile-less household lookup fails, exposing the unsanitized item-refresh request, including `scan_path` and `canonical_root_path`, instead of failing closed. Set `actingAdmin` to false on any lookup error here and in `internal/apiv2/admin_catalog_item_metadata.go:86`, while still returning the already-created job.
Suggested Code:
actingAdmin, adminErr := apimw.ActingAdmin(r.Context())
if adminErr != nil {
actingAdmin = false
}
writeJSON(w, http.StatusAccepted, adminJobToResponseFor(r, job, nil, actingAdmin))
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
The mechanism is real, but production doesn't hit it. I'm fixing it in a commit on this branch, so there's no need to change it yourself.
- Trigger: the legacy decider (
NewActingAdminDecider) returns!refused, err. When the household-profile lookup fails for a profile-less admin session, that comes back as(true, err).ActingAdminAspasses the pair through, and the two refresh handlers keep thetrue. - Reach: the router installs the legacy decider only without a policy system, which means proxy and test wiring. Production API modes use
NewPolicyActingAdminDecider, which returnsfalseon every error. On v2,adminTaskJobOfalready leaves request payloads and paths out of an item-refresh result, whatever the flag says. - Repair: make
ActingAdminAsreturnfalsewhenever the decider errors. Its doc comment already says callers fail closed, and the two "narrow on error" call sites then do what their comments say. A test case will have the decider return(true, err).
There was a problem hiding this comment.
Agreed—the mechanism is valid, but my original critical-severity framing and v2 payload-exposure claim were overstated given the wiring and serialization behavior you describe:
- The
(true, err)result is reachable through the legacy decider in proxy/test wiring, not the production policy decider. - v2’s
adminTaskJobOfalready omits item-refresh request payloads and paths regardless of the flag.
Fixing ActingAdminAs centrally is preferable to adding defensive checks in both handlers: return (false, err) whenever the decider errors, preserving the error while enforcing the helper’s fail-closed contract. The regression test should assert both that a decider returning (true, err) produces false and that the original error remains available.
That also preserves the intended behavior: return the already-created job with restricted visibility rather than fail the response.
I’ll leave the branch changes to you.
There was a problem hiding this comment.
Fixed in 5609deb. ActingAdminAs now returns false whenever the decider errors, so both refresh handlers narrow the response as their comments say. TestActingAdminFailsClosed now asserts false for a (true, err) decider and for the real legacy decider with a failing household lookup. It fails on the previous head with ActingAdmin = true, profile store down. Middleware, events, request, job and section tests pass, and make lint-changed reports 0 issues.
There was a problem hiding this comment.
Thanks—based on your description, 5609deb66 addresses this finding at the right boundary.
Making ActingAdminAs return false whenever the decider errors enforces the fail-closed contract centrally. Both refresh handlers can still return the already-created job, but with restricted visibility; no handler-specific workaround is needed.
The regression coverage targets the original failure mode:
- A decider returning
(true, err). - The real legacy decider with a failing household lookup.
The reported failure on the previous head confirms the test catches the bug. With the focused tests and lint passing as reported, I have no further changes to suggest for this finding.
Quick104
left a comment
There was a problem hiding this comment.
Review of 10d5ba3: one new finding (below), plus a reply in the existing thread on admin.go confirming the (true, err) fail-open. Both are low severity, and I'm fixing both in commits on this branch. A summary with scores follows once the fixes are pushed.
ActingAdminAs passed the decider's result through unchanged, and the legacy decider returns (true, err) when a profile-less session's household lookup fails. The two item-refresh handlers that narrow on error kept the true. ActingAdminAs now answers false whenever the decider errors, as its doc comment promises. Also correct the v1 events ticket comment and realtime doc: a rejected ticket now also decides an admin account's channels, since the connection is judged as acting with no profile. Co-Authored-By: Claude Opus 5.5 <[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:
|
…ile-routes # Conflicts: # docs/architecture/v1-scope.md
Review summaryFit: 9/10 · Readiness: 9/10 — ready Reviewed head: 1c9a964. The review covered 10d5ba3; after it came the fix commit 5609deb and a merge of Addressed
Checked and not changed
Follow-ups filed (pre-existing, not in this PR)
Validated featuresNo passed case on the v1.0 board is reached. Branding (#1227, #1228, #1229 C1) goes through the refactored acting-admin gate with the same decision, so behaviour doesn't change. Calendar and person cases share no code with the diff. The #1179 multi-profile cases and #1202 C1 have not run. User manualNo change needed. I checked the Requests, Profiles, Subtitles and Home sections pages. The only related statement, that "a server administrator" can manage profiles, is already tracked in Silo-Server/siloserver.org#114 for #2019. No page describes admin reach over other accounts' requests, subtitles or file paths. Apple and AndroidNo client change needed. Both apps use the v2 admin approval queue, which has been behind the acting-admin gate since #2019. A child profile's own request list now shows only its account's requests. Scores
Review methodMulti-agent review at high effort: three finders, a validation-impact check and a verification pass, using claude-opus-5-5 and claude-sonnet-5-5. One cross-provider round with gpt-6.1-sol at xhigh reported no findings that this diff introduces. Focused Go tests for 🤖 Generated with Claude Code |
Resolve conflicts with current main: - internal/auth/permissions_test.go: Silo-Server#2817 kept tests for HasEffectivePermission, which this branch removes; keep the branch's PolicyPermissions table and drop the default-permissions test as Silo-Server#2817 did. - internal/api/handlers/items.go: Silo-Server#2370 added a secondary-admin file-path check through HasAssignedPermission. A secondary admin now falls through to the shared masked check; groups never mask an admin, so it still needs metadata_curation assigned to the account. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Related issue: #1179
Validation tasks: none
Not run: #1202 C1 (request permissions) has no recorded result; it now treats a non-primary profile on an admin account as a regular requester. The #1179 cases have not run.
On an admin account, a child profile, or any profile other than the primary one, still gets admin powers on routes outside the admin groups. #2019 stopped the admin role from standing in for the primary profile on the admin routes, so the admin request queue refuses that profile. But the ordinary routes still read the account's role. As the child profile, a caller can:
This affects admin households whose primary profile has a PIN, which is the setup the earlier fix protects.
Approach
apimw.ActingAdminanswers whether a request may use admin powers. It uses the same decision the acting-admin gate makes: the primary profile (with its PIN proof), an admin API key, or a profile-less login session while no profile on the account has a PIN or a limit. The router builds that decider once and hands it to both the gate andProvideActingAdmin, so a route outside the admin groups can't drift from the gate. The helper counts a declared profile only after the viewer gate has verified it, and it answers false when no decider is installed. Routes that widen what an admin sees or does now call it instead of readingclaims.Role, on v1 and v2:A household profile still sees its own account's requests, as before.
Some surfaces needed more than the call swap:
X-Profile-Idon the handshake. It rechecks the decision with its existing session check, as the v2 socket already does.getAdminJobandgetLibraryJobmove fromauthenticatedtoprofile_scopedwith an optional profile, so the viewer gate verifies a declared profile. The contract change is additive: an optionalX-Profile-Id/X-Profile-Tokenand a 403.canViewFilePaths; fix(auth): require marker grants for secondary admin profiles #2177 changes the non-admin branch.The v1 change is a critical bridge fix and is recorded in
docs/architecture/v1-scope.md. jellycompat already reports every user as a non-administrator and grants admin reach only to unscoped admin API keys. The Audiobookshelf layer doesn't read the role. Neither needs a change.Validation
main. The child profile read another account's request on v1 and v2 (200, withlast_error). The admin queue refused its cancel (403). It then cancelled the request throughPOST /api/v1/requests/{id}/canceland v2cancelRequest(200,cancelled). After rebuilding with this branch, all five calls return 403, the requests stay active, and the PIN-verified primary profile still reads them.main(child reads and cancels another account's request) and passes here. The new v2 request, job-poll, events-socket and home-section tests also fail on the old checks.internal/api/...,internal/apiv2/...,internal/requests/...andinternal/policy/...on Linux with a test database: pass, exceptTestAdminSubtitleListPageDBandTestCatalogTransferPersistsJobsAndSignedLink, which fail the same way onmain.make test-goon Linux: the remaining failures are database tests in packages this change doesn't touch. The failing set changes between runs onmainand on this branch, and the branch-only ones pass when run serially.go build,gofmt,go vet,make lint-changed(0 issues), and the OpenAPI, contract diff (additive only), route inventory, migration ledger, scenario catalog, offline route, settings binding, playback fixture, fixture, web types and local path checks: pass. The web types typecheck.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2370/
No screen changes for the primary profile or regular accounts. A child profile on an admin account no longer gets the curator view (file paths and metadata actions) in item detail, because the server now reports
viewer_curates: falsefor it. The curation routes behind those actions already refused it. The evidence page has the API calls before and after.Risks
GET /api/v2/admin/jobs/{id}orGET /api/v2/library-jobs/{job_id}while naming a PIN-protected profile now needsX-Profile-Token, as on every other profile-scoped operation. The web client sends it.Checklist
AI Disclosure
ActingAdminAspassed on a decider's(true, err), which the legacy decider returns when a household lookup fails, and that the v1 ticket comment no longer matched the code. Both are fixed in 5609deb.🤖 Generated with Claude Code