Repository navigation
fix(audiobooks): scope login envelope libraries to the authenticated profile - #2793
Conversation
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:
|
|
The ABS Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
The Suggested line: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
Quick104
left a comment
There was a problem hiding this comment.
Review of 5b2b6dc. The fix is correct: /login and /auth/refresh run outside bearerAuth, so the old builder found no principal in the request context and listed every enabled audiobook library. Passing the validated principal into loginEnvelope fixes that on all three paths, and the profile is the one the credentials picked (username#profile, or the account's primary when none is named), the same profile the issued token carries.
Two low-severity findings, both on lines this PR adds. I'm fixing both in a commit on this branch, so there's no need to change them yourself.
Other ABS endpoints have similar gaps that predate this PR: collection entries carry the server's first library ID, three helpers ignore a scope-resolution error and fall back to an unrestricted filter, and listening-session detail checks the account but not the profile. They are filed as #2795 and will get their own PR.
AI disclosure: reviewed with Claude Code (claude-opus-5-5), with an independent review by gpt-6.1-sol through the Codex CLI.
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 review summaryReviewed head: Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green) The fix belongs where it is. Addressed findingsBoth were low severity, introduced by this PR, and fixed in
Verification
Remaining issuesNone in this PR. The independent review and the altitude pass found older gaps of the same kind in other ABS handlers. Collection entries carry the server's first library ID. Three helpers ignore a scope-resolution error and fall back to an unrestricted filter. Listening-session detail checks the account but not the profile. These predate this PR. They are filed as #2795 and fixed separately in #2799. Whether collections and playlists should hide out-of-scope members entirely is a product question, and #2795 notes it. Validated featuresNo passed validation case reaches this code. The Audiobookshelf compatibility task #1247 has not been run yet. Its C2 (restrictions match native enforcement) gets closer to passing with this PR, and #2795 covers the rest. The PR body's User manualThe manual's Audiobookshelf page doesn't describe which libraries a sign-in lists, and this change makes the endpoint follow the profile restrictions the manual already describes. No docs issue is needed for this PR. Apple / Android parityNo change is needed. Native Apple, Android and web clients use the v1/v2 API, and jellycompat's sign-in response has no library list. Review methodClaude Code (claude-opus-5-5) ran three finder passes and a validation-impact pass at medium level. gpt-6.1-sol ran one independent round through the Codex CLI. Every finding was checked against the source. |
Log a failed library-scope lookup in the ABS login envelope at Warn with the error and principal, so an empty library list after a resolver or database failure is visible at the default log level. Add handler-level tests for /login, /auth/refresh and /authorize that give a restricted profile one of two libraries and check the response lists only that one. The builder tests alone would still pass if a handler dropped the profile ID. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8c0d243 to
177370e
Compare
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:
|
|
The Evidence section describes before-and-after Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
…3302) #2919 made the token store refuse tokens issued with no source credential, and #2793 added a login test whose principal carries none. Each passed CI alone; together they fail `go test` on main. Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
Audiobookshelf login and refresh envelopes could list library IDs, names and default-library metadata outside the authenticated profile's resolved scope. The shared builder also discarded access-resolution errors. This change resolves metadata scope from the explicit authenticated account and profile.
Closes #2792
Related issue: N/A
Validation tasks: none of the passed cases are affected; partly unblocks #1247 C2 (not run yet; #2795 covers the remaining ABS scope gaps).
Approach
Reuse the existing access resolver and library predicates for login, refresh and authorize. A resolution error skips the library lookup; a listing error discards partial results. Both retain the existing empty-list/virtual-default response.
Nil and empty allowlists, disabled libraries and source-authorized scope keep their meanings. Response status, cookies and token issuance, persistence and refresh ordering are unchanged. The repair concerns library metadata; no item or media-access impact was established. Inspected native Apple, Android, web and Jellyfin source needs no change, and the manual already describes the intended behavior.
Validation
go test ./internal/audiobooks/...passes against a migrated test database, exceptTestRecordOutcomeClearsTheParkedRetry, which also fails on a fresh database on main.make lint-changedandgo vetare clean.TestTokenHandlers_ScopeLibrariesToAuthenticatedProfiledrives/login,/auth/refreshand/authorizefor a profile allowed one of two libraries; with the profile ID dropped from the login and refresh calls, those subtests fail.Evidence
Before-and-after
/loginand/auth/refreshresponses from the DB-backed check, with the setup and test results.Evidence: https://evidence.siloserver.org/r/silo-server/issue-2792/
Risks
ABS clients get an empty library list, with the virtual default library, when scope resolution or the library query fails; that response shape already existed for an empty listing, and the failure is now logged at Warn. The live check used the legacy scope resolver rather than the policy-system resolver integrated mode uses; this PR changes neither. No ABS client app was run.
Follow-ups
Checklist
AI Disclosure
5b2b6dcc1. The approach review required explicit identity/context, compile adaptations and auth-fixture exclusions; all were adopted. The code rounds reported no actionable findings within their source and saved-evidence coverage. No reviewer subdelegation was used; effective backend effort was unverified. The isolated background PR review at the same head also reported no actionable findings and posted nothing. A later /silo review (Claude Code, claude-opus-5-5, with gpt-6.1-sol through the Codex CLI) found two low-severity issues, both fixed in8c0d24320(Warn-level failure logging, handler-level tests), and filed the pre-existing gaps as [bug] Audiobookshelf collections, playlists and session detail ignore the profile's library scope #2795.Note
Fix
abs.Handler.loginEnvelopeto scope libraries to the authenticated profilectxAuthprincipal from all three callers:completeLogin,handleABSAuthorize, andhandleRefresh(which builds it from validated refresh token claims).AccessResolver, a legacy filter with the parsed user and profile IDs is used.Macroscope summarized 177370e.