Skip to content

fix(catalog): stop queries outside a viewer's libraries from matching every library - #1855

Closed
Quick104 wants to merge 2 commits into
mainfrom
fix/catalog-query-library-scope
Closed

Quick104 wants to merge 2 commits into
mainfrom
fix/catalog-query-library-scope

Conversation

@Quick104

@Quick104 Quick104 commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: changes #1137 AC5; reaches #194 A5 and #195 W3 (restricted profiles)

A restricted profile could see titles from libraries it isn't allowed to open. This happened whenever a query named only libraries outside the profile's allowed set: a Home or library rule row scoped to another library, the children of a Jellyfin BoxSet for a smart collection, or a collection's item page. Instead of returning nothing, the query ran over every library. Rating limits still applied. This change makes those queries return nothing.

A second path had the same effect for a profile allowed no library at all: a sorted collection row copied the viewer's library list in a way that turned an empty list (no library) into nil (every library), so the row showed every member. That is fixed too.

The query executor narrows a query's library_ids to the viewer's allowed libraries (internal/catalog/query_executor.go). When the two lists share no library, the narrowed list is empty, no library clause is added, and the query is unscoped. The executor also missed a viewer with no allowed libraries while some library was disabled: it got the disabled-library clause but not the "match nothing" guard.

Approach

  • When the viewer has an allowlist and the narrowed library list is empty, the executor adds 1 = 0, as it already did for an empty allowlist. The guard now runs whether or not a disabled-library clause was added.
  • collectionRailQueryAccess (internal/sections/fetcher.go) copies the library list with slices.Clone, which keeps an empty list non-nil, instead of append([]int(nil), ...).

Validation

  • Go unit tests: a new test checks that a collection row keeps an empty library scope empty (it fails without the fix). A new table test builds the preview SQL for libraries outside the allowlist, an empty allowlist next to a disabled library (both for regular and episode scopes), and overlapping libraries. The four leak cases fail without the fix and pass with it; the overlap cases are unchanged.
  • go test passes for internal/catalog, internal/sections, internal/jellycompat and internal/api/handlers. gofmt, go vet and make lint-changed are clean.
  • Not run locally: DB-backed tests (they run in CI), and a manual check in a running app.

Risks

None identified. A query whose libraries overlap the viewer's allowed set builds the same SQL as before. /api/v1 uses the same executor, so the fix applies there too.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code with subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: an independent reviewer agent found the leak while reviewing a related collections change, read every caller that passes a query's own libraries to the executor, and confirmed the guard; the new test was then run against the unfixed code to confirm it fails.

🤖 Generated with Claude Code

Note

Fix catalog queries outside viewer's libraries matching every library

  • Queries with a library scope that does not intersect the viewer's allowlist now get an always-false condition in the preview plan, instead of matching all libraries. See query_executor.go and the planner in query_executor.go.
  • collectionRailQueryAccess in fetcher.go now preserves the difference between nil and empty scopes when cloning effective library IDs, so an explicitly empty scope stays a denying scope rather than becoming unrestricted.
  • Adds table-driven tests in query_executor_access_test.go and a regression test in collection_rail_fetch_test.go.
  • Behavioral Change: episode-scoped and generic preview queries with empty or disjoint library scopes now return no rows; previously they could return results from all libraries.

Macroscope summarized 168c7ad.

…the viewer's

The query executor narrows a query's library_ids to the viewer's allowed
libraries. When the two shared none, the narrowed list was empty, no
library clause was emitted, and the query ran over every library. The
same happened for a viewer with no allowed libraries while a library was
disabled. jellycompat BoxSet children, collection items and custom
filter rows pass a query's own library_ids to the executor, so they
could list titles from libraries the viewer cannot open.

An allowlist that leaves no library now adds 1 = 0, as an empty
allowlist already did.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@silo-kody

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T05:18:55.271640Z 168c7ad New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 25968e2e-f004-43d9-a924-5e427c62b92c
📥 Commits

Reviewing files that changed from the base of the PR and between 747fccc and 168c7ad.

📒 Files selected for processing (4)
  • internal/catalog/query_executor.go
  • internal/catalog/query_executor_access_test.go
  • internal/sections/collection_rail_fetch_test.go
  • internal/sections/fetcher.go

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


📝 Walkthrough

Walkthrough

The change preserves empty library access scopes in collection rail queries and makes preview SQL exclude results when the effective library selection is empty.

Changes

Library access scope enforcement

Layer / File(s) Summary
Preserve empty collection rail scopes
internal/sections/fetcher.go, internal/sections/collection_rail_fetch_test.go
collectionRailQueryAccess clones library IDs and preserves a non-nil empty scope. A test checks this behavior.
Exclude previews with no matching libraries
internal/catalog/query_executor.go, internal/catalog/query_executor_access_test.go
Preview SQL adds 1 = 0 when the effective library selection is empty. Tests cover disjoint, empty, and overlapping scopes for regular and episode queries.

Priority: ⬆️ High

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: rhainland

Merge Risk: ⚪ Minimal · up to 168c7

This change makes restricted viewers get no results, instead of results from all libraries, when they query libraries outside their allowlist. No merge-blocking risk was found. DB-backed tests and a manual check in a running app were not run.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 168c7

The changes tighten existing library access checks and preserve denied scopes. No introduced security weakness was identified, but full request-path and database-backed verification remains incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The relevant exposure is catalog rows and totals from libraries outside a restricted viewer's allowed set, through callers of the affected query planner and collection adapter. This assessment does not establish coverage of every request surface or playback authorization path.

Security Findings and Attack Paths

  • observed — The reviewed path previously allowed an out-of-scope query selection to become an empty library list without an explicit deny-all condition. Head makes that condition false for restricted viewers, even when a disabled-library clause exists. The supported change closes this path rather than increasing its reachability.

Trust Boundaries and Controls

  • observed — The existing resolver derives library scope from account policy and the selected profile, performs profile verification, and applies disabled-library preferences. For requests carrying that resolved scope, the handler adapter transfers it into the catalog filter; query-selected library IDs narrow this authority rather than defining it.

Resilience and Maintainability Implications

  • observed — The changed collection adapter copies the filter and clones effective library IDs without mutating the input allowlist. The planner constructs local query conditions. These changed operations add no shared authorization-state mutation or multi-step policy transition requiring cleanup or recovery.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. 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 summarizes the main change: queries outside a viewer’s allowed libraries now stop matching every library.
Description check ✅ Passed The description explains the access-control issue, the fixes for catalog queries and collection rows, and the regression tests. It is directly related to the changeset.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • 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.

collectionRailQueryAccess copied the effective library list with
append([]int(nil), ids...), which turns an empty list into nil. An empty
allowlist means no library and nil means every library, so a sorted
collection row showed every member to a profile allowed no library.
slices.Clone keeps the empty list non-nil.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@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 ❌

Quick104 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

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: Before-and-after screenshots of an affected home or collection rail for a restricted viewer, or before-and-after section API excerpts for the same request.

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:20
@Quick104

Copy link
Copy Markdown
Contributor Author

This PR is superseded: #2013 brought both of its commits to main, and #1953 and #2006 later moved the preview-plan guard onto AccessFilter.LibraryScope. Main already covers everything this branch changes, including both regression tests, so I recommend closing it.

The PR has no Closes lines, so closing it leaves no linked issue behind.

@Quick104

Copy link
Copy Markdown
Contributor Author

Closing as superseded: #2013 brought both fixes and their tests to main.

@Quick104 Quick104 closed this Oct 14, 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.

1 participant