Skip to content

fix(access): preserve empty v1 group library policies - #2702

Merged
Quick104 merged 5 commits into
mainfrom
fix/issue-2700-v1-empty-library-policy
Oct 20, 2026
Merged

Quick104 merged 5 commits into
mainfrom
fix/issue-2700-v1-empty-library-policy

Conversation

@Quick104

@Quick104 Quick104 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A v1 access-group update with library_ids: [] grants members unrestricted library access. Reading an existing empty policy through v1 also returns null, for both library_ids and allowed_permissions, which widens the group when the response is saved back. Preserve empty lists so both paths deny every library, or every extra permission, as documented.

Closes #2700
Related issue: N/A
Validation tasks: changes #1196 C1

Approach

Preserve the distinction between omitted, null, empty and populated library policies when copying v1 request and response values, and between null and empty permission policies in v1 responses. v1 responses now return [] instead of null for groups that allow no libraries or no extra permissions. Cover persistence, inherited scope, catalog filtering and GET/save behavior, with v2 controls. This is a critical fix to the frozen v1 bridge contract; no schema or capability changes are needed.

Apple and Android need no companion change: neither current client manages access groups. Web admin uses v2, and Jellyfin already enforces empty policies through the shared resolver. The API documentation and user manual already describe the intended behavior.

Validation

  • Live HTTP checks on an isolated deployment with synthetic accounts, libraries and catalog titles: v1 empty policy changes from access to both libraries to access to neither. Omitted/null/populated and all v2 controls stay unchanged.
  • Before-failing and after-passing handler and real-database regressions cover storage, inherited scope and catalog results. All 274 database contracts pass; final changed-line lint is clean.
  • Build, formatting, vet, router lint, web lint/build/budget and all 8,367 web tests pass. Contract, fixture, migration, route and hygiene gates pass. Prometheus rules pass on Linux after local Docker DNS prevented the image pull.
  • The full Go suite fails in six unchanged tests: resource-capability support on macOS, two Jellyfin Dolby Vision route expectations, and three NFO spelling/permission expectations. Each failure also reproduces on exact base 365e3d436fc2fac8e8b3f4f6d42111ff1baeb48b.
  • Review fix at 8b000c5e5: on a sandbox, v1 create, get and a read-then-save keep [] for both lists; null, populated and omitted controls are unchanged. TestAccessGroupPermissionPolicyRoundTrip fails on the old permissions copy and passes now. Changed-line lint is clean; the focused handler and v2 tests pass.
  • Human re-validation of User management / access groups / invites — Server #1196 C1 is required after merge, including inherited libraries and account override precedence. Public recorded cases were reviewed; board-wide coverage and status remain unverified because the GitHub token lacks read:project.

Evidence

Before build: 365e3d436fc2fac8e8b3f4f6d42111ff1baeb48b. After build: 8b000c5e5. The evidence page contains the API and storage comparisons for both lists, negative controls, correlated request rows and test results.

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

Risks

Roll out to every API replica; old replicas can still widen an empty policy. Existing NULL policies may be intentional or may have been widened by this bug, so the fix cannot safely repair them automatically. Administrators must review and re-save suspected affected policies.

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: T3 Code through the Codex harness; Claude Code for cross-provider review.
  • Tool(s): Codex, Claude Code via T3 delegation, shell, GitHub CLI.
  • Model(s): gpt-6.1-sol (xhigh); claude-opus-5-5 (high).
  • Involvement: AI-assisted. No human acceptance testing is claimed.
  • Adversarial review: Claude reviewed the plan and identified the response-copy path; this fix covers it. Three independent Sol reviewers, a validation reviewer and a final xhigh sweep examined the request/response semantics, persistence, callers and compatibility with no unresolved findings. The post-PR adversarial review by claude-opus-5-5 (high) reviewed exact head 3274e8b5e7f09bc21e879f95c67ed9a9c92ccd03, traced policy/storage/filtering and cleanup paths, and ran focused handler/v2 tests. It found no issues and posted nothing.
  • Follow-up review: Claude Code /silo review (claude-opus-5-5, xhigh) with a read-only Codex round (gpt-6.1-sol, xhigh) found that the response still turned an empty allowed_permissions into null; fixed in 8b000c5e5.

Note

Preserve empty vs nil v1 access-group library policy slices

  • Fixes the v1 access-group handlers so an explicitly empty LibraryIDs or AllowedPermissions slice stays distinct from a nil slice when converted to a pointer. The Ptr helpers and toAccessGroupResponse now use slices.Clone, which copies the slice but keeps an empty slice non-nil.
  • Updates the in-memory test store's Create and Update methods to use slices.Clone so tests preserve the same nil/empty distinction.
  • Adds table-driven handler and v2 admin tests covering omitted, null, empty, and populated library_ids values, plus a permission-policy round-trip test.
  • Adds a PostgreSQL integration test, TestAccessGroupUpdateLibraryPolicyDB, and registers it in db-contracts.txt. It verifies that omitted library_ids keeps the existing restriction, null removes it, and an empty list denies all libraries.
  • Behavioral Change: an access group with an empty library_ids list now denies all libraries instead of being treated as unrestricted.

Macroscope summarized 8b000c5.

@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 19, 2026
@silo-kody

silo-kody Bot commented Oct 19, 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 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: cdb11d96-b5d5-4d99-bfe5-ccccd69e2748
📥 Commits

Reviewing files that changed from the base of the PR and between 365e3d4 and 3274e8b.

📒 Files selected for processing: 5
  • internal/api/handlers/access_groups.go
  • internal/api/handlers/access_groups_policy_db_test.go
  • internal/api/handlers/access_groups_test.go
  • internal/apiv2/admin_access_groups_test.go
  • scripts/ci/db-contracts.txt

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

📝 Walkthrough

The change uses slices.Clone for access-group library ID slices. New tests cover omitted, null, empty, and populated library_ids values across handler, admin API, and database update paths.

Changes: Library policy updates

Layer / File(s) Summary
Preserve library ID slice values
internal/api/handlers/access_groups.go
The handler uses slices.Clone when copying library ID slices in the policy field and response conversion.
Verify library policy update states
internal/api/handlers/access_groups_test.go, internal/api/handlers/access_groups_policy_db_test.go, internal/apiv2/admin_access_groups_test.go, scripts/ci/db-contracts.txt
Tests cover omitted, null, empty, and populated library_ids values. The database test checks stored IDs, resolved scope, restriction state, and visible-title count. The CI database-contract list includes that test.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: rhainland

Merge Risk: ⚪ Minimal · up to 3274e

No actionable issue is established for this change; it is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title concisely and accurately identifies the access-related fix: preserving empty v1 group library policies.
Linked Issues check Passed Issue #2700 requires v1 to preserve omitted, null, empty, and populated library_ids states. The handler now uses slices.Clone for request and response copies, which preserves nil versus empty slic…
Out of Scope Changes check Passed The changes stay within issue #2700. Production code changes preserve v1 policy state. Added tests validate the required v1 behavior and v2 controls. The database-contract list registers the new datab…
Description check Passed The pull request description directly explains the empty-versus-null v1 access-group policy bug and describes the corresponding handler, persistence, and test changes.
Full details: Linked Issues check

Explanation

Issue #2700 requires v1 to preserve omitted, null, empty, and populated library_ids states. The handler now uses slices.Clone for request and response copies, which preserves nil versus empty slices. Unit, API v2 control, and database tests cover update, GET/save round trips, storage, resolved scope, and catalog visibility. The changes satisfy the issue requirements.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2700. Production code changes preserve v1 policy state. Added tests validate the required v1 behavior and v2 controls. The database-contract list registers the new database test. No unrelated feature, schema, or API-surface change is present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • 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
  • 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 impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 19, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 19, 2026

Copy link
Copy Markdown

Major change: #1196 C1 (Server, build 7cc2c1f2). The v1 update/response path now preserves library_ids: [] as a deny-all group policy rather than an unrestricted one, changing the inherited-library permission outcome C1 covers. The PR must explain why this validated behavior changes; its description identifies the empty-list bug. C1 needs human re-validation after merge, including an empty allowlist and account-override precedence.

Suggested fix: Keep Validation tasks: changes #1196 C1 and record that post-merge C1 re-test.

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

Posted via Macroscope — v1 validation impact

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 3274e8b. The library_ids fix holds end to end: request copy, storage, resolver, catalog filter and response all keep null and [] apart, and jellycompat reads the same resolved scope. One finding, inline, on the sibling field in the same response function. I'm fixing it on this branch.

Comment thread internal/api/handlers/access_groups.go Resolved
The v1 access-group response copied allowed_permissions with
append([]string(nil), ...), so a group that allows no extra permissions
came back as null. Saving that response stored NULL, which allows every
assignable permission. Clone the slice so null and [] stay distinct, make
the test store copy the same way, and drop the unused string Ptr helper
that had the same collapse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added size/L 200–499 added + deleted lines (all files); change volume, not priority. and removed size/M 50–199 added + deleted lines (all files); change volume, not priority. labels 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 ❌

@macroscopeapp

macroscopeapp Bot commented Oct 20, 2026

Copy link
Copy Markdown

The Evidence section's stated after-build (3274e8b) predates the allowed_permissions response-copy change in 8b000c5, so the linked evidence does not establish that empty permission policies survive the v1 read/save path. Please update the evidence page with before-and-after v1 API excerpts for the same empty-policy round trip, showing allowed_permissions: [] remains empty and does not widen members' effective permissions.

Suggested fix: No diff; add this behavior to the linked evidence page.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@Quick104

Quick104 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed head: 8b000c5e5. The findings review was on 3274e8b5e.

The library_ids fix is correct end to end: the request copy, storage, resolver, catalog filter and response all keep null and [] apart, and jellycompat reads the same resolved scope. One gap remained in the same response function, and it is now fixed.

Addressed

  • Medium, security: v1 responses still returned an empty allowed_permissions as null, so reading a group and saving it back gave members every assignable permission. Reproduced on a sandbox. Fixed in 8b000c5e5: slices.Clone for that field, a test store that keeps [], a read-then-save regression test, and the unused accessGroupStringSliceField.Ptr() removed. The sandbox after-check and controls are in the thread and on the evidence page.

Remaining

Nothing blocking. The description already covers the two operational notes: groups that the old code saved as NULL stay unrestricted until an administrator re-saves them, and replicas still on an old build keep the old behavior until the rollout finishes.

Validated features

#1196 C1 was validated through the web admin and /api/v2, which this PR doesn't change. The shared resolver is also unchanged, so the recorded result doesn't regress. The v1 bridge now enforces the C1 criterion ("an empty list denies every library") as well, and Validation tasks: changes #1196 C1 is a reasonable conservative notice. When C1 is re-tested, a v1 read-then-save of a group with empty lists covers this change. #1196 C2 and the web admin task #1197 share no code with this diff. I read the validation issues directly because the board itself wasn't readable with the available token.

Checks

  • User manual: no change needed. The access page describes the web admin, which already behaves this way.
  • Apple and Android: neither app manages access groups, so neither needs a follow-up. Jellycompat uses the shared resolver and needs no change.
  • fix(access): move group members to the default before deletion #2705 edits the same handler file and scripts/ci/db-contracts.txt in other places. The two branches merge without conflicts.
  • Evidence: the page and the description now name 8b000c5e5 as the after build and include the allowed_permissions round trip, which answers the Macroscope evidence note posted a minute before they were updated. CI is green on 8b000c5e5.
  • Cross-provider round: a read-only Codex review (gpt-6.1-sol, xhigh) independently found the same allowed_permissions gap and nothing else.

Fit: 9/10 · Readiness: 9/10 — ready

  • Fit: this fixes an access-control widening on the /api/v1 bridge. Fixes like this are the one kind of change the frozen v1 contract still accepts. It needs no schema, setting or new API surface, and it matches the documented null/[] meaning that v2 already follows.
  • Readiness: both empty-list paths now hold on create, read, update and read-then-save. Focused unit and database tests and a live sandbox check cover them, with null, populated and omitted controls.

Review by Claude Code (claude-opus-5-5) with the /silo review workflow; cross-provider round by Codex (gpt-6.1-sol).

@Quick104
Quick104 merged commit dd3f7a6 into main Oct 20, 2026
18 checks passed
@Quick104
Quick104 deleted the fix/issue-2700-v1-empty-library-policy branch October 20, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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] Clearing a v1 access group library list removes its restriction

1 participant