Path-replacement UPDATE SQL is not source-scoped — a PUT to source A can overwrite source B's replacement #255

Closed
opened 2026-07-11 15:06:20 +02:00 by timothy · 1 comment
Owner

Severity: High (correctness/security — cross-source data mutation). Pre-existing latent bug, surfaced during the #202 media-source write-API pre-review (independent Codex pass, verified against source).

What's wrong

The path-replacement update path merges by row Id and the repository UPDATE keys on Id with no media-source predicate:

  • ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs:26 classifies every positive Id as an update.
  • ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs:397 (Plex) UPDATEs PlexPathReplacement by Id only — no AND PlexMediaSourceId = @id.
  • MediaSourceRepository.cs:690 — same unscoped UPDATE for Jellyfin (JellyfinPathReplacement). Emby structurally identical.

So a request addressed to source A carrying a positive Id that actually belongs to source B silently overwrites B's replacement row. Today this is only reachable via Blazor (which always sends a single source's own rows), so it's latent — but the #202 REST write API exposes it to arbitrary programmatic/MCP clients, making it a real cross-tenant mutation vector.

Fix (being done within #202, per scope decision on the tracker)

Defense-in-depth: (1) handler rejects any incoming positive Id not owned by the route source → 422, no partial mutation; (2) add AND {Family}MediaSourceId = @id to the Plex/Jellyfin/Emby path-replacement UPDATE SQL (query-string change, no schema/migration). Cross-source attack test (PUT to A with B's id → 422, B unchanged).

Filed for record — the fix ships as part of #202 (design doc §C4b). Cross-refs: #202, adversarial-reviewer#19 (slice 2 pre-review).

**Severity: High (correctness/security — cross-source data mutation).** Pre-existing latent bug, surfaced during the #202 media-source write-API pre-review (independent Codex pass, verified against source). ## What's wrong The path-replacement update path merges by row `Id` and the repository UPDATE keys on `Id` **with no media-source predicate**: - `ErsatzTV.Application/Plex/Commands/UpdatePlexPathReplacementsHandler.cs:26` classifies every positive `Id` as an update. - `ErsatzTV.Infrastructure/Data/Repositories/MediaSourceRepository.cs:397` (Plex) UPDATEs `PlexPathReplacement` by `Id` only — no `AND PlexMediaSourceId = @id`. - `MediaSourceRepository.cs:690` — same unscoped UPDATE for Jellyfin (`JellyfinPathReplacement`). Emby structurally identical. So a request addressed to source A carrying a positive `Id` that actually belongs to source B silently overwrites B's replacement row. Today this is only reachable via Blazor (which always sends a single source's own rows), so it's latent — but the #202 REST write API exposes it to arbitrary programmatic/MCP clients, making it a real cross-tenant mutation vector. ## Fix (being done within #202, per scope decision on the tracker) Defense-in-depth: (1) handler rejects any incoming positive `Id` not owned by the route source → 422, no partial mutation; (2) add `AND {Family}MediaSourceId = @id` to the Plex/Jellyfin/Emby path-replacement UPDATE SQL (query-string change, no schema/migration). Cross-source attack test (PUT to A with B's id → 422, B unchanged). Filed **for record** — the fix ships as part of #202 (design doc §C4b). Cross-refs: #202, adversarial-reviewer#19 (slice 2 pre-review).
timothy added the bugapireview labels 2026-07-11 15:06:20 +02:00
Author
Owner

Fixed in PR #262 (merged to main 8e2f9954, #202). Update{Plex,Jellyfin,Emby}PathReplacementsHandler now rejects any incoming positive Id not owned by the route source (422, no partial mutation), and the repo UPDATE SQL gained the AND {Family}MediaSourceId = @id predicate (defense-in-depth). Covered by cross-source attack tests (MediaSourceRepositoryPathReplacementScopeTests + per-family handler tests).

Fixed in PR #262 (merged to main `8e2f9954`, #202). `Update{Plex,Jellyfin,Emby}PathReplacementsHandler` now rejects any incoming positive `Id` not owned by the route source (422, no partial mutation), and the repo UPDATE SQL gained the `AND {Family}MediaSourceId = @id` predicate (defense-in-depth). Covered by cross-source attack tests (`MediaSourceRepositoryPathReplacementScopeTests` + per-family handler tests).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: timothy/ersatztv#255