Skip to content

fix(audiobooks): scope Audiobookshelf collections, playlists and session detail to the profile - #2799

Merged
Quick104 merged 2 commits into
mainfrom
fix/abs-profile-scope-gaps
Oct 21, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/abs-profile-scope-gaps

Conversation

@Quick104

@Quick104 Quick104 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2795
Related issue: N/A
Validation tasks: unblocks #1247 C2

Several Audiobookshelf-compatible endpoints returned data outside the signed-in profile's scope. Collection entries carried the server's first audiobook library as libraryId, even for a profile that can't see that library. When access resolution failed, collection, playlist and library filter responses fell back to an empty access filter, which means no restriction. And a profile could read another profile's listening session on the same account by its ID. This affects Audiobookshelf apps on accounts with more than one profile, a beta surface.

Approach

  • resolveDefaultLibrary now requires the caller's access filter, so no caller can fall back to the server-wide first library.
  • Collection and playlist handlers resolve access once, before any read or write, and pass the filter to the render helpers. When resolution fails they log it at Warn and return 403, the status the rest of the package already uses for this. A request is refused whole: playlist creation no longer commits before the access check, and remove or rename requests are refused rather than half-done.
  • resolveLibrary returns the filter it authorized the library with. Library detail, items, authors, series, search and personalized shelves use that filter instead of resolving it a second time, so library filter data can't run with a different or empty scope.
  • GET /me/listening-sessions/{sid} requires the same account and profile (sameABSPrincipal), matching the session list and the sync routes.

Native API, web, Apple, Android and Jellyfin surfaces are unaffected. login.go is left to #2793, which fixes its own discarded access error.

Validation

  • New focused tests fail on main and pass here: collection libraryId follows a profile restricted to the second library; collection, library collection list, playlist and playlist creation return 403 with no catalog data and no write when the access resolver errors; another profile on the same account gets 404 for a session.
  • go test ./internal/audiobooks/..., go build ./..., gofmt, go vet, make lint-changed, make lint-router-recovery, and the local-path, bidi, size-ratchet and route-inventory checks pass.
  • make test-go on a fresh database: the failures are in packages that don't import internal/audiobooks/abs (DB-backed suites run while other jobs shared the database) plus the known TestRecordOutcomeClearsTheParkedRetry.
  • Not reproduced live. The dev sandbox could not start (the host's shared database restarted, then Docker ran out of network address pools), and its template has no audiobook library. The defects are shown in source on main and by the tests above.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2795/

Risks

While access resolution fails, collection and playlist calls, including removals and renames, now return 403 instead of succeeding with unscoped data. Deleting a whole collection or playlist still works, since it reads no catalog data. ABS clients already get 403 from library and item routes in the same condition.

Follow-ups

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
  • Tool(s): Claude Code, Codex CLI
  • Model(s): claude-opus-5-5 (implementation and code review), gpt-6.1-sol (plan review and adversarial review)
  • Involvement: Fully AI-generated, not yet human verified
  • Adversarial review: Before implementation, gpt-6.1-sol reviewed the plan read-only. It found that returning empty member lists on an access failure would look like a real empty result, and that playlist creation committed before the access check. The plan changed to refuse the whole request before any write. Its other points (author lists from a materialized view, playlist entries without a libraryItem) are outside this issue. A multi-agent code review of the final diff found the second access lookup in library detail, now removed, and the rest was answered above. A background gpt-6.1-sol adversarial review of this PR at 616ccfd reported no findings. It reviewed the source only; it could not run the tests in its read-only sandbox.

🤖 Generated with Claude Code

…ion detail to the profile

Collection entries took their libraryId from the server's first audiobook
library, because collectionBooks resolved the default library without the
caller's access filter. resolveDefaultLibrary now requires the filter.

Collection, playlist and library filter responses discarded the error from
access resolution, and an unresolved filter means no restriction. Handlers
now resolve access once, before any read or write, and refuse the request
with 403 (logged at Warn) when it fails; the filter is passed to the render
helpers. resolveLibrary returns the filter it authorized the library with,
so library handlers no longer resolve it twice. Playlist creation no longer
commits before the access check.

Listening-session detail now requires the same account and profile, like
the session list and sync routes already do.

Closes #2795

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 20, 2026
@silo-kody

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

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: da24c554-cce4-45cc-bfd9-98581a5a3509
📥 Commits

Reviewing files that changed from the base of the PR and between 174fb9a and 6cda93f.

📒 Files selected for processing: 8
  • internal/audiobooks/abs/access_scope_test.go
  • internal/audiobooks/abs/collections_handler.go
  • internal/audiobooks/abs/handler.go
  • internal/audiobooks/abs/items_handler.go
  • internal/audiobooks/abs/libraries_handler.go
  • internal/audiobooks/abs/listening_stats_handler.go
  • internal/audiobooks/abs/listening_stats_handler_test.go
  • internal/audiobooks/abs/playlists_handler.go
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Most software today is very much like an Egyptian pyramid with millions of bricks piled on top of each other, with no structural integrity, but just done by brute force and thousands of slaves. - Alan Kay |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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

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-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 20, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 20, 2026

Copy link
Copy Markdown

#1247 C2 is Not run, not failed or blocked, so this PR does not unblock a recorded result. The changed ABS handlers alter the permissions and response data that C2 covers; the case should be validated after merge. Collection and playlist responses still include stubs for out-of-scope member IDs, so this change does not clear the whole profile-access criterion.

For this major change, the PR should explain why the permissions and returned data change; the Approach section already gives the intended rationale. C2 has no prior run, so plan its first validation after merge.

Suggested fix:

-Validation tasks: unblocks #1247 C2
+Validation tasks: changes #1247 C2

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

…-gaps

# Conflicts:
#	internal/audiobooks/abs/listening_stats_handler_test.go
@Quick104

Copy link
Copy Markdown
Contributor Author

Review summary (reviewed head 6cda93f27)

No defects found. I merged main into the branch to clear a conflict with #2817 (6cda93f27). That PR deleted most of listening_stats_handler_test.go, so the resolution keeps main's trimmed file and this PR's two-case TestStats_Session_Detail_NonOwner_404. The merge changes no production code.

What I checked

  • Every handler that gained requireAccess resolves access before decoding the body or touching a store, so a resolver error can't leave a write half-applied. Batch add used to skip items on a per-item access error. It now refuses the whole request with 403, which matches the other write routes.
  • resolveLibrary now builds the filter from absAuthFrom instead of accessFilterFromRequest. All six library routes that call it sit behind bearerAuth, so the "no auth, unrestricted filter" branch it dropped was unreachable in production.
  • Session detail's sameABSPrincipal check uses the same user-and-profile filter as the session list and the sync routes (abs_playback_session_store.go filters on user_id and profile_id). A session with an empty profile still matches an owner whose profile is empty.
  • Every resolveDefaultLibrary caller already passed a filter, so making it required breaks nothing.
  • login.go:322 still discards the access error. That code predates this PR and fix(audiobooks): scope login envelope libraries to the authenticated profile #2793 covers it, as the body says.

Tests. All three changed tests fail on the base for the reasons the PR gives:

  • TestCollectionBooks_CarryTheProfileLibrary gets libraryId 1 instead of 2.
  • In TestScopeResolutionFailure_FailsClosed, all four cases return 200 with catalog data, and the create case commits a playlist.
  • In TestStats_Session_Detail_NonOwner_404, the other-profile case gets 200.

go test ./internal/audiobooks/... and make lint-changed pass on the merged head. I didn't reproduce the leaks live.

Cross-provider review. One read-only gpt-6.1-sol round on 616ccfdd0 found nothing. It also confirmed the tests fail on base production code.

Validated features. No passed case on the v1.0 board is reachable from this diff. #1247 C2 (Audiobookshelf restrictions match native enforcement) hasn't been run, so Validation tasks: unblocks #1247 C2 is right.

User manual. Unaffected. The Audiobookshelf beta page covers sign-in and choosing a profile. It says nothing about which collections, playlists, or sessions a profile sees.

Apple/Android. Not applicable. These routes serve third-party Audiobookshelf apps.

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: the PR fixes profile-scope leaks on a beta surface without reworking it, which is the kind of change the beta label allows (v1 scope).
  • Readiness: the approach fails closed and changes no write ordering, and each regression test fails on the base. It stays below 10 because no Audiobookshelf client was run against it.

@Quick104
Quick104 merged commit 64e7fec into main Oct 21, 2026
13 of 15 checks passed
@Quick104
Quick104 deleted the fix/abs-profile-scope-gaps branch October 21, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] Audiobookshelf collections, playlists and session detail ignore the profile's library scope

1 participant