Repository navigation
fix(auth): check scoped API keys against the path the router serves - #3307
Conversation
A scoped API key was checked against the decoded, cleaned request path, while chi routes on the escaped path when one is set and never cleans it. An encoded-slash or dot-segment spelling could therefore pass the scope check as an allowlisted route and reach a different handler. Scoped keys are now refused any path that is escaped or not already clean, the same rule remote-playback sessions already follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The scoped-key API behavior is visible: ambiguous or encoded paths now return Posted via Macroscope — Visible change evidence |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Validate paths before allowlist matching internal/api/middleware/api_key_scopes.go, internal/api/middleware/remote_playback.go, internal/api/middleware/api_key_scopes_test.go, docs/api-keys-api.md |
Scoped-key requests require an unambiguous path before scope-route matching; unscoped keys remain allowed. Remote playback applies the same path check before allowlist matching. Tests cover ambiguous paths and chi routing. The documentation lists path forms that receive 403 responses. |
Estimated code review effort: 2 (Simple) | ~15 minutes
Change: Bug fix
Possibly related PRs
- Silo-Server/silo-server#3242: Adds a route to the scoped-key allowlist, which now receives only unambiguous paths.
- Silo-Server/silo-server#3187: Adds an API-key events route to the scoped-key allowlist, which is subject to the changed path admission.
- Silo-Server/silo-server#3184: Adds API-key-scoped routes whose access follows the changed path admission rules.
Suggested labels: bug, documentation, go, api-v2, impact: security, priority: P1, size/M, needs-review
Suggested reviewers: rhainland
Merge Risk: 
Minimal · up to 78303
-
No actionable merge-blocking issue was established. Scoped keys and remote-playback sessions reject ambiguous paths while the intended unscoped-key behavior remains unchanged.
Security architecture risk: 
Low · up to 78303
-
The change restricts ambiguous requests rather than granting additional access. No introduced security defect was identified. Remaining uncertainty concerns production request transformations and compatibility with clients that send noncanonical paths.
Retained concerns
No architecture-level concerns identified.Security review details
-
Security Blast Radius
- inferred — The relevant attacker holds a scoped API key and controls the request method and path. For an administrator-owned key, interpretation disagreement could cross from permitted account-management routes into administrative settings on the same server. Owner-role enforcement remains a separate limiting boundary; this PR narrows that exposure rather than adding authority.
Security Findings and Attack Paths
- inferred — The reported attack uses encoded separators or dot segments so authorization judges a normalized users route while dispatch selects a settings route. The head rejects those spellings before allowlist matching. Regression source asserts 403 and no handler reachability through a root mux and through direct chi dispatch; these assertions were inspected, not executed. No introduced or worsened attack path was established.
Trust Boundaries and Controls
- observed — Current-authority revalidation continues to check captured credential identity, current key scopes, live session authority, bound profile, and enabled owner state. Its production progress callers construct operation paths. The new helper does not introduce a new credential source or replace captured identity.
Resilience and Maintainability Implications
- inferred — The changed admission step adds no persistent reservation or multi-step state transition. Rejected paths terminate before narrowing mutations, and successful authentication uses request-local claims. Existing revocation and expiry checks remain unchanged. No new partial-failure or retry path that widens authority was identified; concurrent execution was not experimentally validated.
-
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main change: scoped API key checks now use the path chi routes on, so escaped or unclean paths are refused. It matches the changeset in the middleware and its tests, and the fix(auth) prefix follows the usual convention. The title is 67 characters, which is acceptable.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 3 files. (1 skipped: 1 unsupported.)
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
|
Added a "Surface and build" line under Evidence: the native API ( 🤖 T3 Code / Claude Agent (claude-opus-5-5) |
|
Major change — #1190 C2 (Server; build 807 · Suggested fix: No code diff; record the post-merge C2 re-validation. Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
|
Recorded #1190 C2 as a major authorization change in the PR's Risks. The new After merge and a published build, C2 needs re-validation of plain allowed and forbidden routes, an ambiguous path, and rotation/revocation. A Done task should return to Ready with that hand-off. 🤖 T3 Code / Codex (gpt-6.1-sol) |
Problem
Related issue: N/A
Validation tasks: changes #1190 C2
A scoped API key could reach routes outside its scopes by spelling the path in a way the scope check and the router read differently. The scope check decoded and cleaned the path, but chi routes on the escaped path when there is one and never cleans it. For example, an
admin:userskey sendingPUT /api/v1/admin/settings/..%2Fusers%2F1passed the check as/api/v1/admin/users/1, and chi then ran the admin settings handler, which saved a setting named..%2Fusers%2F1. The same trick works on/api/v2, and with literal..segments when a request reaches the API router directly. It affects servers where an administrator has issued scoped keys to integrations: admin-only routes still required the owner to be an administrator, but the key was not held to the routes its scopes list.This change checks scoped keys against the path chi routes, and refuses with
403any path where the two could differ.Approach
apiKeyScopesAllownow matches the allowlist againstr.URL.Pathonly whenr.URL.RawPathis empty and the path is already clean (no.or..segments, doubled slashes or trailing slash). In that case the string the allowlist reads is the string chi routes on. Any other spelling is refused, not normalized. Remote-playback sessions already followed this rule, so the check is now one helper used by both. Remote-playback behavior is unchanged.Unscoped keys and login sessions are unchanged. Legitimate scoped-key paths don't need escaping: the allowlisted routes take numeric user and access-group IDs and UUID playback session IDs, and query strings (such as
?identity=with an encoded@) don't affect the check.docs/api-keys-api.mdnow states the rule. jellycompat, plugin routes and media grants already refuse scoped keys outright, so they need no change. The Apple and Android apps don't use API keys, so neither app needs a follow-up. The user manual leaves scope details todocs/api-keys-api.mdand already lists a key's scopes as a reason for403, so it needs no issue.The settings handlers still accept unknown setting keys. That is separate defense in depth and is not part of this change.
Validation
http.ServeMux, a chi router andRequireAuthand checks which handler ran. Both fail on the parent commit (the settings handler is reached with200) and pass with the change.PUT /api/v1/admin/settings/..%2Fusers%2F1returned200and wrote the row. After the change it returns403, as do the v2 and..variants. In-scope v1 and v2 user reads, the encoded identity query and a UUID session terminate behave the same before and after.go build ./...,gofmt -l .,go vet ./...,make lint-changed,make lint-router-recovery: passmake test-go: failures ininternal/httpstream,internal/jellycompat,internal/metadata/nfo,internal/playback,internal/scannerandinternal/subtitles/subsyncon the macOS machine used (case-insensitive filesystem, timing, real FFmpeg and media-tool cases). Only jellycompat depends on the changed package, and its two failures also fail with the base middleware. All other packages pass.pnpm install --frozen-lockfile,lint,format:check,build,budget:check,make test-web): install, lint, build and budget pass.format:checkfailed onsrc/pages/ItemDetail/detailLayout.css, which fix(web): format detailLayout.css so the Prettier check passes #3306 has since fixed onmain, and fourmake test-webfiles fail. This change touches no web files, so both come from the base.make verify-route-inventory, which could not type-check cgo files ininternal/imageutilandinternal/netadminon this machine, andmake verify-prometheus-rules, which did not run because the image pull failed on DNS.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3307/
API response excerpts for the same requests on the full router, with an
admin:userskey:PUT /api/v1/admin/settings/..%2Fusers%2F1200 {"key":"..%2Fusers%2F1","value":"probe"}403 API key scopes do not permit this routeGET /api/v2/settings/values/..%2F..%2Fadmin%2Fusers%2F1422(passed auth)403 permission_deniedGET /api/v1/admin/settings/../users/1404(passed auth)403GET /api/v2/admin/users/1200200Surface and build: native API (
/api/v1and/api/v2) on the full API router built locally. Before:271a4c87d, whose auth middleware and v2 gates are identical to this PR's base5a205566a. After:783036af8, this PR's head.Risks
A scoped-key integration that sends a trailing slash, a doubled slash or an unnecessary percent-escape on an allowlisted route now gets
403where the scope check used to pass. chi wouldn't have served the trailing- or doubled-slash forms as the allowlisted route anyway. No first-party client uses scoped keys. Validation task #1190 C2 passed on build 807 ·d4e35ba9. This is a major change to its authorization path: encoded or unclean spellings that could bypass scopes now return403. The change preserves C2's requirement that forbidden operations are denied, but the earlier pass does not cover this path. After merge and publication in a build, C2 needs re-validation of plain allowed and forbidden routes, an ambiguous path, and rotated/revoked credentials. If the task is Done, it should return to Ready with the validation hand-off.Checklist
AI Disclosure
🤖 Generated with Claude Code