You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(catalog): hold curator-chosen provider IDs to the curator's libraries - #3932
Closes#2801
Related issue: N/A
Validation tasks: none (#1210 C1 and C2 are run as an administrator, and administrator edits, identifies and refreshes behave as before)
A metadata curator limited to some libraries could still merge an item onto a title in a library they can't curate. #2777 checks the destination when a curator runs match, split or merge, but that check only lives on the request. A curator could write another library's TMDB, IMDb or TVDB ID onto an in-scope item with PATCH /admin/items/{id}/metadata, and work that runs later without the check would act on it:
the item refresh job the curator queues (POST /admin/items/{id}/refresh-metadata) runs on the job runner's context, so its re-anchor merges the item onto whichever item sits at the anchor the new ID derives;
a refresh refused for curation scope (for example the source or merge-target refresh after a split or merge) was recorded as refresh debt, and the debt retry runs as automatic work with no curator scope;
a plain scheduled refresh of a local- item, or of an item with no durable provider IDs, merges it onto the item holding the stored ID without any refresh request.
The merge moves the item's files, library memberships and user state onto the other library's title. This change holds all of these to the curator's libraries. Administrator and automatic work are unchanged, and so is curation inside the curator's scope.
Approach
The check moves to where the curator makes the choice, because the stored IDs outlive the request:
When a curator's metadata edit changes tmdb_id, imdb_id or tvdb_id, the same transaction locks and authorises every other item that sits at the anchor the resulting IDs derive or already holds a newly chosen ID (in the item columns or media_item_provider_ids), using the request's curation authoriser. An out-of-scope item refuses the edit with the existing 403 ("Item is outside your assigned libraries" on v1, permission_denied on v2). IDs an edit form resends unchanged aren't re-checked. A split that creates a new target from chosen provider IDs gets the same check.
Both curation gates (the legacy one and the policy one) now also record the curator's assigned libraries on the request as a plain value. CreateItemMetadataRefresh, shared by v1 and v2, copies it into the item refresh job's payload as curation_scope, and the executor runs the job's metadata refresh under an authoriser built from it. That survives the job being claimed on another node. Acting administrators record no scope, so their jobs run as before.
A refresh that fails with the curation-scope refusal records no refresh failure and no refresh debt, the same as a cancelled refresh.
The queued job checks a snapshot of the curator's libraries taken when the job was queued, not a fresh policy decision: the job can't rebuild the request's device, client IP and time inputs. I didn't add a column or migration, since the job payload is already JSON and refresh debt now never carries curator work.
jellycompat has no item metadata write or refresh route, and library refresh is acting-admin only, so neither needs a matching change. No client change is needed: the 403 already exists for match and split.
Validation
New Postgres tests (added to scripts/ci/db-contracts.txt): curator provider-ID edits are refused when they name a title in another library (by anchor and by a durable IMDb row) and allowed inside the curator's libraries, from an acting administrator and from automatic writes; a curator-scoped re-anchor is refused onto another library's title without moving anything, and still merges or renames inside the curator's libraries. Both pass locally against a migrated database. The edit test fails with the check removed.
New unit tests: a curator refresh job's scope survives the JSON payload and refuses an out-of-scope merge (admin and unrestricted jobs don't); a curation-scope refusal records no refresh failure.
Focused runs of the touched packages' existing tests (internal/api/middleware, internal/api/handlers curation, split, merge and metadata tests, internal/adminjob item refresh, internal/metadata identify tests) pass. make lint-changed, the full Go suite and the db-contracts job were not run locally; they run in CI on this PR. These ran on 39711821a; the head commit only renames constants and was built and vetted.
Maintainer review (399fd8131, 2ff2684f2, 0fa214e52): main merged in, with the curator's scope also covering Reset to Provider (a reset-mode row in the job test). The check now derives the anchor from the IDs a refresh keeps, and it locks the edited item before comparing its IDs. The new TestCuratedProviderIDEditsStayInCurationScopeDB row (TMDB set to "0" over a library B IMDb anchor) fails on 399fd8131 and passes on 2ff2684f2. Kept IDs are trimmed before the anchor is derived, and a row with a padded kept TMDB ID fails on 2ff2684f2 and passes on 0fa214e52. With a plain authorizer in place of the new scope type, the edit test's out-of-scope rows and TestCurationScopeRefusalLeavesNoRefreshDebt fail on main.
Surface: v1 admin catalog API, a curator limited to "Movies A", with test titles Alpha (Movies A) and Beta (Movies B, TMDB 900000101). Base build 30a6abd19, fix build 39711821a (b5850341f for the NFO run), each against its own freshly migrated database with the same data.
Request (curator)
Before (30a6abd19)
After (39711821a)
PATCH Alpha {"tmdb_id": "900000101"} (Beta's ID)
200, Alpha stores 900000101
403 "Item is outside your assigned libraries", nothing stored
PATCH Gamma (Movies A) to an unused TMDB ID
200, stored
200, stored
POST Alpha refresh-metadata, then the job as admin
202, request_payload has no curation_scope
202, request_payload has "curation_scope": {"library_ids": [1]}
No network metadata provider was enabled for these runs, so on the base build the refresh job failed with "no metadata found from any provider" and the merge onto Beta didn't happen. The merge itself is covered by the re-anchor database test above rather than a live capture. The evidence page also has a separate run with only the built-in NFO provider, showing the rescan behaviour described under Risks, the same on both builds.
Risks
Security fix to a permission boundary. A curator whose edit names a title in a library they can't curate now gets 403 where it used to succeed.
Where this draws the line, for a maintainer to confirm: IDs a provider adds during a later automatic refresh (TMDB X returns an IMDb ID a library B title holds) still converge as automatic work, the same as after match/apply. Identity overrides a split persists for later scans are a separate path and not covered here.
The split check locks the items holding the chosen IDs after the source and target, not in one content-id-ordered pass. A deadlock between two concurrent curations of the same titles would roll one back.
A curator refresh job whose metadata refresh would merge out of scope now fails with the scope error instead of merging.
The scope covers the job's metadata refresh, not the folder rescan the job runs first. That rescan is the same automatic scan a library scan runs, and it acts on file identity a curator can't write: an NFO <uniqueid> naming a title in another library still merges the two during the rescan, on this branch as on main (step 5 of the evidence).
Checklist
I read and can explain the complete diff.
This pull request addresses one concern.
Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
The Evidence section shows every change a user can see, or says there is none.
AI Disclosure
Harness: Claude Code (desktop app)
Tool(s): Claude Code, GitHub CLI
Model(s): claude-opus-5-5
Involvement: AI-assisted with Claude Opus. I directed the task and designed the work.
Adversarial review: a second-model review of the design and diff during the work, which raised the refresh-debt guard and the scheduled-refresh path; both are handled above. No independent human review yet.
Note
Hold curator-chosen provider IDs to the curator's library scope
Adds MetadataCurationScope in metadata_curation.go, carrying the delegated curator's effective library IDs on the request context, installed by both permission middlewares
Curated provider-ID edits and split targets now check chosen IDs and the resulting identity against existing same-type items via catalog.LockMetadataCurationIdentity and lockCuratedProviderIDs in metadata_curation.go; unchanged (case-insensitive) IDs and automatic writes are excluded
Item refresh jobs serialize the curator's scope as curation_scope in the payload (item_refresh.go), and the refresh executor applies it as an authorizer so queued refresh work stays in scope
Curation-scope refusals no longer create refresh debt: refreshFailureLeavesNoDebt in service.go treats them like cancellation errors, and AdminHandler.UpdateItemMetadata maps them to a forbidden response
Behavioral Change: requests without a curation authorizer skip the new identity checks; scoped jobs that target out-of-scope or unlibraryed destinations are now refused
…ries
A delegated metadata curator could still merge an item onto a title in a
library outside their scope. They edit the item's tmdb_id, imdb_id or
tvdb_id, then work that runs later without the curation check acts on
the stored IDs: the item refresh job, a refresh-debt retry, or a
scheduled refresh of a local item. Each merges the item onto the item
already at the anchor the IDs derive or holding one of them.
- A curator's provider-ID edit, and a split target's chosen IDs, now
lock and authorise every other item at the derived anchor or holding
a newly chosen ID, as match/apply does for its destination. A refusal
returns 403.
- The curator gates record the curator's library scope on the request.
An item refresh job copies it into its payload and runs the metadata
refresh under it, so the job's merges are held to the same libraries
on whichever node runs it.
- A refresh refused for curation scope records no refresh failure or
debt, since the debt retry runs as automatic work with no scope.
Admin and automatic work are unchanged.
ClosesSilo-Server#2801
This organization requires a seat for paid usage-based reviews, including automatic and on-demand reviews. Ask an admin to assign a seat or enable paid usage-based reviews for users without a seat in Billing.
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: cf8ec0c1-e827-43bc-9c2e-584bb0f4531e
Commits
Reviewing files that changed from the base of the PR and between 2ff2684 and 0fa214e.
Files selected for processing: 2
internal/catalog/metadata_curation.go
internal/catalog/metadata_curation_db_test.go
Walkthrough
The change carries delegated curator library scope through metadata updates and queued refresh jobs. It checks provider-identity changes and refresh re-anchoring against that scope. Scope refusals do not create refresh failure debt.
Changes: Delegated metadata curation
Layer / File(s)
Summary
Define and attach curator scope internal/access/metadata_curation.go, internal/api/middleware/permissions.go, internal/api/middleware/policy_gates.go
A MetadataCurationScope stores curator library IDs in request context and provides an authorizer for requested library sets. Middleware attaches a clone of the curator’s effective library IDs.
Metadata updates and newly created split targets lock matching identity owners and authorize their libraries. The metadata handler maps scope refusals to a forbidden response. Database tests cover provider-ID edits by curators, admins, and automatic writes.
Carry scope into queued refreshes internal/adminjob/item_refresh.go, internal/adminjob/item_refresh_test.go, internal/api/handlers/admin_item_metadata_service.go
Refresh requests store an available scope, and the executor applies its authorizer when running the job. Tests cover request serialization and scoped merge authorization.
Refresh re-anchoring tests check destination scope. Cancellation, deadline, and curation-scope errors do not create refresh failure debt. Documentation and database-contract entries describe the restrictions.
Delegated curators are now blocked from choosing provider IDs that belong to items outside their libraries. Two curators who claim the same unused ID at the same moment can still both succeed, which could later lead to a cross-library merge. Closing this needs a per-identity lock before the owner lookup. The window is narrow, so it is a merge consideration rather than a blocker.
Security architecture risk: Moderate · up to 2ff26
The change strengthens library isolation for deferred metadata work. Residual identity-ownership gaps can still affect catalog associations and user state across libraries, but the inspected gaps predate this change; no newly reachable or broader attack path was established.
Retained concerns
No architecture-level concerns identified.
Security review details
Security Blast Radius
inferred — The relevant exposure is the shared catalog within the affected deployment: provider identities can cause consolidation across library boundaries, affecting catalog file associations, memberships, and associated user state rather than only the initiating curator's records. Exploitation requires curation authority over a source item; the inspected public split route additionally requires acting-administrator authority.
Security Findings and Attack Paths
inferred — The two retained concurrency findings describe a residual ownership race. Separate transactions choosing the same previously unowned provider ID can both pass the empty-owner branch and commit their item-column edits; later automatic identity convergence can cross their library scopes. Existing-owner locks and the late-owner recheck narrow exposure but do not reserve an absent identity. The unique provider-table constraint is not exercised by the inspected metadata-column write. This path predates the PR, whose base performed no identity-owner check, so it is not an introduced or worsened architecture concern.
observed — The retained split condition remains at the service boundary: caller-supplied provider IDs survive selection of an existing target and can be persisted as scan overrides, while the added identity guard runs only for a newly created target. The same existing-target persistence behavior is present at the merge base. The inspected public route requires acting-administrator access, so this inspection does not establish a newly exposed delegated-curator attack through that route.
Trust Boundaries and Controls
observed — Queued authority is server-derived rather than supplied as refresh-request scope. Job creation copies the authorized request's library snapshot into its payload, and execution reconstructs the authorizer for both refresh and reset. Earlier complete-refresh preparation and subtree ingestion still use the original context, so the new authorization boundary covers the metadata-refresh stage, not the entire job.
Hardening Proposals
proposed — For stronger identity isolation, serialize claims on a normalized provider-identity key shared by all relevant writers, or reserve ownership transactionally before committing curator-selected IDs. Preserve refusal semantics when concurrent claims belong to disjoint library scopes.
proposed — Before relying on queued-refresh scope enforcement operationally, account for legacy payloads without scope and ensure every worker eligible to claim new scoped jobs understands the field. Draining or revalidating legacy work would make the protection's activation explicit.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: curator-chosen provider IDs are now checked against the curator's libraries. It matches the changeset, which adds curator scope checks for provider-ID edits, splits, a…
Linked Issues check
Issue #2801 has one direct linked target. Its requirement is that curator-chosen provider IDs must not reach cross-library merges through later refresh jobs or refresh-debt retries. The change covers …
Out of Scope Changes check
The changes map to issue #2801 or its supporting work. Scope plumbing: access.MetadataCurationScope, its context helpers and authorizer, and the middleware that records the curator's libraries (`per…
Description check
The description is detailed and directly describes the changeset: curator library scope checks on provider-ID edits, splits, and refresh jobs (curation_scope payload), refresh-debt handling for scope …
Full details: Title check
Explanation
The title names the main change: curator-chosen provider IDs are now checked against the curator's libraries. It matches the changeset, which adds curator scope checks for provider-ID edits, splits, and refresh jobs. The title uses the conventional fix(catalog) prefix and stays under one line.
Full details: Linked Issues check
Explanation
Issue #2801 has one direct linked target. Its requirement is that curator-chosen provider IDs must not reach cross-library merges through later refresh jobs or refresh-debt retries. The change covers the three paths the issue names. (1) Provider-ID edits: lockCuratedProviderIDs and LockMetadataCurationIdentity in internal/catalog/metadata_curation.go check changed IDs and their derived anchor against existing owners, including durable provider-ID rows, under the request's curation authorizer. Out-of-scope owners return ErrMetadataCurationScope, which maps to 403. Split targets built from chosen IDs get the same check. (2) Refresh jobs: CreateItemMetadataRefresh stores curation_scope in the job payload, and ItemRefreshRequest.CurationScope applies it during Execute, so the job checks the curator's libraries when it runs. (3) Refresh debt: refreshFailureLeavesNoDebt excludes curation-scope refusals from failure counters and debt. The issue lists three possible directions and asks for a maintainer decision. The PR combines the first two and documents the boundary for automatic convergence. The PR description and the reported maintainer acceptance support that choice. Two items are excluded by design and disclosed: IDs added by later automatic provider refreshes, and NFO identity during the folder rescan. The issue does not require either one. Test coverage is reported as DB tests for edits, re-anchor and job scope, plus unit tests for refresh debt and payload round trip. I did not re-run these tests or re-read the full diff, so this verdict relies on the supplied summary and the author's reported results.
Full details: Out of Scope Changes check
Explanation
The changes map to issue #2801 or its supporting work. Scope plumbing: access.MetadataCurationScope, its context helpers and authorizer, and the middleware that records the curator's libraries (permissions.go, policy_gates.go). Enforcement: the metadata update and split paths, the 403 mapping in UpdateCatalogItemMetadata, and the UpdateMetadata transaction lock. Refresh path: the curation_scope payload and ItemRefreshRequest.CurationScope. Debt handling: refreshFailureLeavesNoDebt in service.go. Tests and supporting files: the DB and unit tests, the db-contracts.txt entries, and the API documentation about the boundary. No unrelated behavior change appears in the supplied summary. The documentation records the intended boundary and does not add unrelated behavior.
Full details: Description check
Explanation
The description is detailed and directly describes the changeset: curator library scope checks on provider-ID edits, splits, and refresh jobs (curation_scope payload), refresh-debt handling for scope refusals, plus tests, evidence, and risks. It is clearly related to the changes in the summary.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
coderabbitaiBot
added
bug
Something isn't working
go
Pull requests that update go code
impact: security
Auth, privacy, or permission boundary
needs-review
Needs maintainer review to resolve uncertain classification, scope, or changed evidence.
labels
Nov 10, 2026
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.
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 settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
The reason will be displayed to describe this comment to others. Learn more.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Compare stored IMDb IDs case-insensitively · metadata_curation.go:153-188
internal/catalog/metadata_curation.go:153-188 Major · Security & Privacy · Quick win
Compare stored IMDb IDs case-insensitively
If an out-of-scope movie stores TT123 and the edited movie has a different TMDB anchor, the owner query misses that movie when a curator selects tt123. The edit can then persist without the required owner authorization.
The allowed cases check only that UpdateMetadata returns nil. A no-op could pass. Assert the stored TMDB ID or title for each allowed case; the query must also read the title.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 237dcf9b-7d68-4b69-b017-89cb0ecfc8ff
Commits
Reviewing files that changed from the base of the PR and between 08be5e1 and 2fe0aa4.
Files selected for processing: 3
internal/catalog/metadata_curation.go
internal/catalog/metadata_curation_db_test.go
internal/metadata/service.go
Files skipped from review as they are similar to previous changes: 2
internal/metadata/service.go
internal/catalog/metadata_curation.go
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
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 settingsReview Options
The following review options are enabled or disabled:
Options
Enabled
Bug
✅
Performance
✅
Security
✅
Business Logic
❌
⚠️ 4 Kody Rule(s) were not evaluated
These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:
Preserve optional store capabilities through production wrappers
Detach mandatory cleanup from request cancellation and bound its lifetime
Preserve durable media identity and share identity-evidence precedence
Bound decoder throughput trades and share direct-play eligibility
…ile comparing
A refresh drops provider IDs it can't use before deriving the anchor, so derive the curation check's anchor the same way, and lock the edited item before comparing its stored IDs so a concurrent edit can't make a resent ID look unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
Two findings in the provider-ID check, both found by a cross-provider review round (Codex gpt-6.1-sol) and verified against the source. Both need the edited item to already keep an IMDb ID anchored in another library. I'm fixing both on this branch; the summary comment follows once the fix is pushed.
Fit: this closes a gap in an existing permission. A curator limited to some libraries could reach another library's title through stored provider IDs and the work that acts on them later. The change puts the check where the curator makes the choice, carries the scope on the job they queue, and leaves administrators and automatic work alone. Readiness: the edit-time check and the refresh-debt guard each fail on main and pass here, and the two holes the review found are fixed and covered.
Fixed both review findings in 2ff2684f2. The check derives the anchor from the IDs a refresh keeps, so a TMDB ID of "0" no longer hides a kept IMDb anchor in another library. It also locks the item before comparing its stored IDs.
Fixed Kody's follow-up in 0fa214e52. Kept IDs are trimmed before validation, as refresh does, so a stored TMDB ID with stray whitespace still anchors the check. A new test row fails on 2ff2684f2 and passes here.
Verification
TestCuratedProviderIDEditsStayInCurationScopeDB doesn't build on main because it uses the new MetadataCurationScope. With a plain authorizer in its place, its two out-of-scope rows fail on main (UpdateMetadata() error = <nil>, want refused=true) and pass here. The new "0" row fails on 399fd8131 and passes on 2ff2684f2. All runs used a freshly migrated Postgres.
TestCurationScopeRefusalLeavesNoRefreshDebt fails on main (refresh failures = 1, want 0).
TestCuratorRefreshReanchorStaysInScopePostgres also passes on main, because fix(catalog): authorize curation destinations before mutation #2777 already refuses a re-anchor under a request authorizer. It guards that behavior but doesn't show this change. The job payload carrying curation_scope is shown by the live capture on the evidence page, which still matches this head.
The concurrent-edit fix is checked by reading the source; the interleaving wasn't reproduced.
Review method: a multi-angle code review, a validation-impact check, and one cross-provider round (Codex gpt-6.1-sol), which raised the two findings above. The other candidates were declared in Risks, settled in the Kody threads, or not caused by this PR.
Maintainer decisions
The boundary in Risks is accepted as documented. IDs a provider adds during a later automatic refresh converge as automatic work, and a curator's choice is checked when it is written.
Remaining
Nothing blocking. The split's out-of-order locking (Risks), and the edited item's lock taken before the sorted set, can roll back one of two concurrent curations that pick each other's titles. No data is lost.
Validated features
Validation tasks: none stands. #1210 C1/C2 and #1211 C1/C2 passed as an administrator. Administrator and automatic work carry no curation scope and take the same code paths: MetadataCurationTxOptions returns the default options without an authorizer, and the executor uses the job's context unless curation_scope is set.
User manual and clients
Manual unaffected. The access page already says Metadata Curation lets a user correct media in the libraries they can access, and this makes the server enforce that.
Other clients: N/A. Only the server changes, and the 403 already exists for match and split. jellycompat has no item metadata write or refresh route.
Concurrent cross-item edits can block each other and cause PostgreSQL to abort a transaction. Acquire all affected item locks in a consistent order, or retry transactions aborted by the deadlock detector.
Prompt for LLM
File internal/catalog/metadata_curation.go, lines 219-220:
Source-first locking deadlocks concurrent cross-item edits
Concurrent edits that select each other's provider identities can deadlock because each transaction locks its own item before requesting both items in sorted order. Acquire all affected item locks in a consistent order, or retry transactions aborted by PostgreSQL's deadlock detector.
The reason will be displayed to describe this comment to others. Learn more.
Not changed. The lock on the edited item is what makes the comparison safe: it stops a concurrent edit from changing the stored IDs between the read and the write. The deadlock needs two curator edits running at once where each picks an ID the other item holds or anchors. Postgres detects that, rolls one transaction back, and that edit returns an error and can be retried. Nothing is written partially and nothing merges. It is the same failure the PR already accepts for concurrent splits under Risks. Locking the edited item together with the sorted set would mean finding the owners before locking the item, which reopens the race the lock closes.
The reason will be displayed to describe this comment to others. Learn more.
That’s a reasonable tradeoff. The source lock protects the ID comparison, and PostgreSQL will roll back a transaction chosen as the deadlock victim, preserving atomicity. The remaining impact is a failed request that must be retried; it is not necessarily retried automatically.
I’d treat the suggestion as an availability concern rather than a correctness or security blocker, given that this concurrency risk is accepted. The PR’s Risks section currently calls out concurrent splits specifically, so it would be helpful to mention cross-item provider-ID edits there too.
Consistent ordering is still possible in principle by reading optimistically, locking the discovered set in order, then re-reading and restarting the transaction if the identity or owner set changed—but that adds complexity and isn’t necessary if the retry tradeoff is acceptable.
Stored IDs aren't trimmed, and refresh trims them before deriving the anchor, so a kept TMDB ID with stray whitespace still anchors the refresh. Trim before validating so the check derives that same anchor.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bugSomething isn't workinggoPull requests that update go codeimpact: securityAuth, privacy, or permission boundaryneeds-reviewNeeds maintainer review to resolve uncertain classification, scope, or changed evidence.priority: P0Fix/merge first: data-loss, security, or widespread breakagesize/XL500–999 added + deleted lines (all files); change volume, not priority.
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #2801
Related issue: N/A
Validation tasks: none (#1210 C1 and C2 are run as an administrator, and administrator edits, identifies and refreshes behave as before)
A metadata curator limited to some libraries could still merge an item onto a title in a library they can't curate. #2777 checks the destination when a curator runs match, split or merge, but that check only lives on the request. A curator could write another library's TMDB, IMDb or TVDB ID onto an in-scope item with
PATCH /admin/items/{id}/metadata, and work that runs later without the check would act on it:POST /admin/items/{id}/refresh-metadata) runs on the job runner's context, so its re-anchor merges the item onto whichever item sits at the anchor the new ID derives;local-item, or of an item with no durable provider IDs, merges it onto the item holding the stored ID without any refresh request.The merge moves the item's files, library memberships and user state onto the other library's title. This change holds all of these to the curator's libraries. Administrator and automatic work are unchanged, and so is curation inside the curator's scope.
Approach
The check moves to where the curator makes the choice, because the stored IDs outlive the request:
tmdb_id,imdb_idortvdb_id, the same transaction locks and authorises every other item that sits at the anchor the resulting IDs derive or already holds a newly chosen ID (in the item columns ormedia_item_provider_ids), using the request's curation authoriser. An out-of-scope item refuses the edit with the existing 403 ("Item is outside your assigned libraries" on v1,permission_deniedon v2). IDs an edit form resends unchanged aren't re-checked. A split that creates a new target from chosen provider IDs gets the same check.CreateItemMetadataRefresh, shared by v1 and v2, copies it into the item refresh job's payload ascuration_scope, and the executor runs the job's metadata refresh under an authoriser built from it. That survives the job being claimed on another node. Acting administrators record no scope, so their jobs run as before.The queued job checks a snapshot of the curator's libraries taken when the job was queued, not a fresh policy decision: the job can't rebuild the request's device, client IP and time inputs. I didn't add a column or migration, since the job payload is already JSON and refresh debt now never carries curator work.
jellycompat has no item metadata write or refresh route, and library refresh is acting-admin only, so neither needs a matching change. No client change is needed: the 403 already exists for match and split.
Validation
scripts/ci/db-contracts.txt): curator provider-ID edits are refused when they name a title in another library (by anchor and by a durable IMDb row) and allowed inside the curator's libraries, from an acting administrator and from automatic writes; a curator-scoped re-anchor is refused onto another library's title without moving anything, and still merges or renames inside the curator's libraries. Both pass locally against a migrated database. The edit test fails with the check removed.internal/api/middleware,internal/api/handlerscuration, split, merge and metadata tests,internal/adminjobitem refresh,internal/metadataidentify tests) pass.make lint-changed, the full Go suite and the db-contracts job were not run locally; they run in CI on this PR. These ran on39711821a; the head commit only renames constants and was built and vetted.399fd8131,2ff2684f2,0fa214e52): main merged in, with the curator's scope also covering Reset to Provider (a reset-mode row in the job test). The check now derives the anchor from the IDs a refresh keeps, and it locks the edited item before comparing its IDs. The newTestCuratedProviderIDEditsStayInCurationScopeDBrow (TMDB set to"0"over a library B IMDb anchor) fails on399fd8131and passes on2ff2684f2. Kept IDs are trimmed before the anchor is derived, and a row with a padded kept TMDB ID fails on2ff2684f2and passes on0fa214e52. With a plain authorizer in place of the new scope type, the edit test's out-of-scope rows andTestCurationScopeRefusalLeavesNoRefreshDebtfail on main.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3932/
Surface: v1 admin catalog API, a curator limited to "Movies A", with test titles Alpha (Movies A) and Beta (Movies B, TMDB 900000101). Base build
30a6abd19, fix build39711821a(b5850341ffor the NFO run), each against its own freshly migrated database with the same data.30a6abd19)39711821a)PATCHAlpha{"tmdb_id": "900000101"}(Beta's ID)200, Alpha stores900000101403"Item is outside your assigned libraries", nothing storedPATCHGamma (Movies A) to an unused TMDB ID200, stored200, storedPOSTAlpharefresh-metadata, then the job as admin202,request_payloadhas nocuration_scope202,request_payloadhas"curation_scope": {"library_ids": [1]}No network metadata provider was enabled for these runs, so on the base build the refresh job failed with "no metadata found from any provider" and the merge onto Beta didn't happen. The merge itself is covered by the re-anchor database test above rather than a live capture. The evidence page also has a separate run with only the built-in NFO provider, showing the rescan behaviour described under Risks, the same on both builds.
Risks
<uniqueid>naming a title in another library still merges the two during the rescan, on this branch as on main (step 5 of the evidence).Checklist
AI Disclosure
claude-opus-5-5Note
Hold curator-chosen provider IDs to the curator's library scope
MetadataCurationScopein metadata_curation.go, carrying the delegated curator's effective library IDs on the request context, installed by both permission middlewarescatalog.LockMetadataCurationIdentityandlockCuratedProviderIDsin metadata_curation.go; unchanged (case-insensitive) IDs and automatic writes are excludedcuration_scopein the payload (item_refresh.go), and the refresh executor applies it as an authorizer so queued refresh work stays in scoperefreshFailureLeavesNoDebtin service.go treats them like cancellation errors, andAdminHandler.UpdateItemMetadatamaps them to a forbidden responseMacroscope summarized 0fa214e.