Skip to content

fix(jellycompat): enforce account-level library restrictions - #72

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
d3v1l1989:fix/jellycompat-library-access
Jun 7, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
d3v1l1989:fix/jellycompat-library-access

Conversation

@d3v1l1989

@d3v1l1989 d3v1l1989 commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #71.

Problem

The Jellyfin-compat API ignores account-level library restrictions (users.library_ids).
The compat AccessFilterFn wired up in cmd/silo/main.go was a hand-rolled partial
re-implementation of the access policy that only considered:

  • profile-level restrictions (profile.library_restrictions_enabled + allowed ids), and
  • the viewer's own disabled_library_ids setting.

It never loaded the user row, so the admin-assigned per-account library allowlist —
the primary mechanism for restricting what a user can see — was silently dropped.
Every compat session (Infuse, Findroid, VidHub, jellyfin-web, …) could list, browse,
search, and play items from all enabled libraries, including libraries the admin
had explicitly not granted to that account. The native API applies these restrictions
correctly via access.Resolver, so the two APIs disagreed about the same viewer.

Additional smaller gaps in the same code path:

  • a profile restricted to zero libraries was treated as unrestricted
    (len > 0 check), both in the filter construction and in
    ListUserLibraries;
  • MaxPlaybackQuality ceilings (account and profile) were never propagated
    to the compat filter;
  • any error while resolving the policy (store unavailable, profile deleted
    mid-session) failed open, returning an unrestricted filter;
  • ListUserLibraries never applied DisabledLibraryIDs, so an unrestricted
    user's hidden libraries still appeared as compat views.

Fix

Replace the duplicated closure with the shared access.Resolver — the same
component the native API and the requests entitlement path already use — via a
new jellycompat.NewScopeAccessFilter(resolver) adapter:

  • account library_ids ∩ profile restrictions ∩ user-disabled libraries now
    apply to every compat surface that consumes the access filter (views,
    virtual folders, browse, search, item detail, images, recommendations,
    playback);
  • MaxContentRating and MaxPlaybackQuality ceilings propagate like on the
    native API;
  • PIN verification is skipped (SkipPINVerification: true) because compat
    login already verifies profile PINs via the password#pin convention;
  • resolution failures now fail closed (empty allowlist) instead of open;
  • ListUserLibraries distinguishes nil (unrestricted) from empty
    (restricted-to-nothing) allowlists and filters disabled libraries.

Anything to watch out for

  • Playback-quality ceilings now apply to the compat API. Previously
    users.max_playback_quality / profile quality caps were only enforced on
    the native API; compat clients (Infuse, Findroid, VidHub, …) saw and played
    every file version. After this change a capped viewer loses access to
    file versions above their ceiling on compat clients too — same behavior
    as the native API. Deployments that relied (accidentally) on the compat
    API ignoring quality caps will see capped users restricted there as well.
  • Access-policy resolution failures now deny instead of allow. If the
    user store is unavailable or a session references a deleted profile, the
    viewer gets an empty library allowlist for that request instead of an
    unrestricted catalog.
  • A profile restricted to zero libraries now sees zero libraries on the
    compat API (previously: all libraries).

How it was tested

  • new unit tests: scope→filter mapping, unrestricted pass-through,
    fail-closed on resolver error, empty-allowlist ListUserLibraries;
  • go build ./cmd/... ./internal/..., go vet, full
    go test ./internal/jellycompat/ pass;
  • verified live on a production deployment: a restricted user
    (library_ids excluding one library) no longer sees the withheld library
    via /Users/{id}/Views or search on the compat API; toggling the library
    in the account's allowlist removes/restores it on the compat layer
    immediately, and an unrestricted admin account still sees everything.

Implementation was AI-assisted (Claude); I've read the full diff, and the behavior was verified live before submitting.

Summary by CodeRabbit

  • Bug Fixes
    • Improved enforcement of content rating restrictions and library access controls for user profiles
    • Enhanced access filtering logic with more robust error handling to ensure consistent application of restrictions
    • Strengthened security posture by ensuring the system properly denies access when content restrictions cannot be verified

d3v1l1989 added 2 commits June 7, 2026 08:13
The compat AccessFilterFn re-implemented a subset of the access policy
and never loaded users.library_ids, so admin-assigned account library
restrictions did not apply to the Jellyfin-compat API: restricted users
could list, browse, search, and play items from every enabled library.

Replace the hand-rolled closure with the shared access.Resolver via a
new jellycompat.NewScopeAccessFilter adapter so account restrictions,
profile restrictions, user-disabled libraries, and rating/quality
ceilings apply exactly as on the native API. PIN verification is
skipped because compat login already verifies profile PINs.

Also: fail closed (empty allowlist) when scope resolution errors
instead of returning an unrestricted filter; treat an empty allowlist
as restricted-to-nothing in ListUserLibraries instead of unrestricted;
and hide user-disabled libraries from the compat views list.
Extract a folderListSource interface for the two FolderRepository
methods directContentService uses (matching the existing browseSource/
itemAccessSource pattern) so ListUserLibraries is unit-testable, and
add coverage for the restricted-allowlist path and the user-disabled
library filtering in the views list.
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cc291571-0b6a-4283-8c24-67c995bdb712

📥 Commits

Reviewing files that changed from the base of the PR and between e9cf274 and ccaf8d1.

📒 Files selected for processing (4)
  • cmd/silo/main.go
  • internal/jellycompat/access_filter.go
  • internal/jellycompat/access_filter_test.go
  • internal/jellycompat/content_direct.go

📝 Walkthrough

Walkthrough

This PR delegates Jellyfin compat library access filtering to the shared access.Resolver to enforce account-level restrictions. A new scope-based filter maps account and profile restrictions into allowlist/disabled-ID fields. The content service abstracts folder listing for testability and filters denied libraries from results. Main wiring is updated to use the shared resolver instead of profile-scoped logic.

Changes

Account-level library restrictions for Jellyfin compat layer

Layer / File(s) Summary
Scope-based access filter implementation
internal/jellycompat/access_filter.go, internal/jellycompat/access_filter_test.go
ScopeResolver interface abstracts scope computation. NewScopeAccessFilter maps scope fields into AccessFilter (allowed/disabled library IDs, content ratings, playback quality), skips PIN verification, and fails closed with empty allowlist on resolution errors. Unit tests validate scope field mapping, unrestricted scope behavior, and fail-closed semantics.
Content service library restriction and filtering
internal/jellycompat/content_direct.go, internal/jellycompat/access_filter_test.go
folderListSource interface replaces concrete folder repository dependency. ListUserLibraries reworks allowlist handling: non-nil empty allowlist returns empty list immediately; non-nil non-empty allowlist fetches by IDs. Client-side filtering excludes disabled library IDs from results. Integration tests validate restricted allowlist calls ListByIDs with correct IDs, disabled IDs are excluded, and empty allowlist returns zero libraries.
Compat server integration
cmd/silo/main.go
compatDeps.AccessFilterFn replaces inline profile-scoped filter with jellycompat.NewScopeAccessFilter backed by shared access.NewResolver for viewer/account scope handling. Removes encoding/json import used by old profile-scoped unmarshalling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing account-level library restriction enforcement in the Jellyfin-compat layer.
Linked Issues check ✅ Passed All coding objectives from issue #71 are met: account-level library allowlists enforced via access.Resolver, profile zero-library handling fixed, MaxPlaybackQuality/MaxContentRating propagated, fail-closed on errors, nil vs empty allowlist distinction, and DisabledLibraryIDs filtering in ListUserLibraries.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #71: access resolver integration for compat filtering, interface extraction for testability, and comprehensive unit test coverage of the fix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@Quick104
Quick104 merged commit 366bf79 into Silo-Server:main Jun 7, 2026
1 check passed
Quick104 pushed a commit that referenced this pull request Jun 7, 2026
* fix(jellycompat): enforce account-level library restrictions

The compat AccessFilterFn re-implemented a subset of the access policy
and never loaded users.library_ids, so admin-assigned account library
restrictions did not apply to the Jellyfin-compat API: restricted users
could list, browse, search, and play items from every enabled library.

Replace the hand-rolled closure with the shared access.Resolver via a
new jellycompat.NewScopeAccessFilter adapter so account restrictions,
profile restrictions, user-disabled libraries, and rating/quality
ceilings apply exactly as on the native API. PIN verification is
skipped because compat login already verifies profile PINs.

Also: fail closed (empty allowlist) when scope resolution errors
instead of returning an unrestricted filter; treat an empty allowlist
as restricted-to-nothing in ListUserLibraries instead of unrestricted;
and hide user-disabled libraries from the compat views list.

* test(jellycompat): cover library list filtering via folder source stub

Extract a folderListSource interface for the two FolderRepository
methods directContentService uses (matching the existing browseSource/
itemAccessSource pattern) so ListUserLibraries is unit-testable, and
add coverage for the restricted-allowlist path and the user-disabled
library filtering in the views list.
Quick104 pushed a commit that referenced this pull request Jun 17, 2026
* fix(jellycompat): enforce account-level library restrictions

The compat AccessFilterFn re-implemented a subset of the access policy
and never loaded users.library_ids, so admin-assigned account library
restrictions did not apply to the Jellyfin-compat API: restricted users
could list, browse, search, and play items from every enabled library.

Replace the hand-rolled closure with the shared access.Resolver via a
new jellycompat.NewScopeAccessFilter adapter so account restrictions,
profile restrictions, user-disabled libraries, and rating/quality
ceilings apply exactly as on the native API. PIN verification is
skipped because compat login already verifies profile PINs.

Also: fail closed (empty allowlist) when scope resolution errors
instead of returning an unrestricted filter; treat an empty allowlist
as restricted-to-nothing in ListUserLibraries instead of unrestricted;
and hide user-disabled libraries from the compat views list.

* test(jellycompat): cover library list filtering via folder source stub

Extract a folderListSource interface for the two FolderRepository
methods directContentService uses (matching the existing browseSource/
itemAccessSource pattern) so ListUserLibraries is unit-testable, and
add coverage for the restricted-allowlist path and the user-disabled
library filtering in the views list.
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.

Jellyfin compat layer ignores account-level library restrictions (users.library_ids)

2 participants