feat: automatic debrid cleanup driven by ARR webhooks - #391
Closed
buzzromain wants to merge 9 commits into
Closed
buzzromain wants to merge 9 commits into
buzzromain wants to merge 9 commits into
Conversation
allow_delete: false does not mean "nothing happens" when media is deleted in Sonarr/Radarr: HandleArrDelete calls DeleteArrFile unconditionally, only the automatic debrid removal is gated on the flag.
/webhooks/arr sits outside authMiddleware (Sonarr/Radarr can't do session/basic auth on webhook connections), so arrName was resolved straight from attacker-controlled input (query param, payload instanceName, or header) with nothing tying a request to the ARR it claimed to be from. Combined with HandleArrDelete's DownloadId fallback, an unauthenticated request naming any configured ARR with allow_delete on could delete any known infohash's debrid torrent. RegisterArrWebhooks now embeds the ARR's own API token in the registered URL, and handleArrWebhook rejects any request whose token doesn't match that ARR's configured one.
FindArrFilesByFolder matched any tracked file under the given folder regardless of which ARR it belonged to. With overlapping library roots across two configured ARRs (shared parent folder, symlinked structure), a legitimate SeriesDelete/MovieDelete from one ARR could sweep up and delete the other ARR's tracked files when allow_delete is on — media it has no knowledge of or authority over.
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds automatic debrid cleanup driven by Sonarr/Radarr webhooks: Decypharr tracks which files it manages for each configured Arr and, optionally, removes the underlying debrid torrent when that media is deleted upstream.
arr_refstracking: managed file paths are indexed by infohash per Arr, updated on Download/Rename/FileDelete/SeriesDelete/MovieDelete events.allow_deleteoption per Arr (defaultfalse, opt-in): when a tracked file is deleted in Sonarr/Radarr, the tracked-file reference is always dropped; the underlying debrid torrent is only removed ifallow_deleteis enabled for that Arr, and only once no other tracked file still references it.Changes
pkg/storage/arr_files.go—arr_refsstore: managed-path index, per-Arr scopingpkg/server/webhook_arr.go— webhook handler, token-based auth (arrWebhookAuthorized)pkg/manager/arr_cleanup.go— webhook registration, import-history bootstrap, delete/rename handlingpkg/arr/notification.go,history.go— webhook registration API, incremental history syncinternal/config—allow_deletefield;pkg/server/templates/config.html— UI checkboxdocs/src/content/docs/guides/arrs.mdxpkg/server/webhook_arr_test.go,pkg/storage/arr_files_test.goConfiguration example
{ "arrs": [ { "name": "Sonarr", "host": "http://sonarr:8989", "token": "API_TOKEN", "allow_delete": true } ] }Decypharr registers its webhook in Sonarr/Radarr automatically at startup — no manual webhook configuration needed.