Repository navigation
fix(notifications): keep destination management on the acting account - #2601
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
0de8142 to
469778c
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Profile IDs are unique only within an account, and every account from before profiles has a profile "default". The webhook, web push, and legacy push device management queries filtered on profile_id alone, so one account's "default" profile could list, edit, test, rotate the secret of, and delete another account's "default" webhooks, and list or delete its browser subscriptions. Carry the acting user through the v1 and v2 destination routes, services, and repositories and match (user_id, profile_id). The per-profile webhook cap counts per account profile. Web push and legacy push re-registration treat a same-ID profile on another account as a new owner, so its pending attempts are dropped. PurgeProfile deletes deliveries, destinations, and email prefs for the profile on the given account only. The webhook name constraint keeps its name and moves from (profile_id, name) to (user_id, profile_id, name), so two accounts' same-ID profiles can use the same name and older nodes still map the violation. Closes #2598 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…chema Co-Authored-By: Claude Opus 5.5 <[email protected]>
4471cde to
9e271e4
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Problem
Closes #2598
Related issue: #2596
Validation tasks: none
A profile could see and change notification webhooks and browser push subscriptions that belong to another account, as long as the two profiles had the same ID. Every account created before profiles has a profile with the ID
default, so on a server with two such accounts, account A'sdefaultprofile listed account B's webhooks with their names and destination hosts. It could also edit them, send test messages through them, rotate and read their signing secrets, and delete them. It could list and delete B's browser subscriptions and unregister B's legacy push device registrations.Profile IDs are unique only within an account. The destination tables store
user_id, but the management queries matchedprofile_idalone. This change matches the account and the profile on every management read and write, in/api/v2/notificationsand in the frozen/api/v1routes. The v1 change is a cross-account authorization fix, which the bridge allows.Approach
The routes already know the acting user. They now pass it with the profile ID to
WebhookService,WebPushService, andPushDeviceService.Unregister, and the repositories match(user_id, profile_id). The same applies to the per-profile webhook cap and to the cleanupPurgeProfileruns when a profile is deleted: deliveries, webhooks, web push subscriptions, push devices, and email preferences are removed for that profile on that account only.When a browser endpoint or legacy device install moves to a same-ID profile on another account, it now counts as a new owner, as a profile switch already did. Pending web push attempts are canceled, and the legacy push row is replaced. This covers attempts that exist at the moment of reassignment. A fanout enqueue that races the reassignment is handled by the sender's recipient check from the #2596 fix.
A migration keeps
notification_webhooks_profile_name_keybut changes its columns from(profile_id, name)to(user_id, profile_id, name). Without it, B'sdefaultprofile couldn't use a webhook name A'sdefaultalready had, and the error revealed that the name existed. The constraint keeps its name so older nodes in a rolling upgrade still turn a duplicate name into a validation error instead of a 500.Request and response shapes, operation IDs, and status codes don't change. Deletes that were idempotent still return 204 for an ID the account doesn't own and leave the row alone. Guarded v2 webhook update, delete, rotate-secret, and test return 404, as they do for a missing ID. No Apple, Android, or web change is needed. jellycompat has no notification destinations.
Validation
main: two accounts whose profiles both had the IDdefault. A listed B's webhook on v2 and v1, rotated its secret (200), and deleted it (204). On the fix branch, A sees only its own webhooks, rotate and delete on B's ID return 404, B's webhook stays, and A can reuse B's webhook name.PurgeProfile, and the migration's Down, which fails and changes nothing when two accounts share a name. Existing destination DB tests gained cross-account cases. All of them fail on a copy of the tree that matches profile ID alone.go testforinternal/notifications,internal/apiv2, andinternal/api/...against a sandbox database: pass. Fiveinternal/api/handlerstests that also fail onmainagainst a populated database were skipped.go build,gofmt,go vet,make lint-changed,make lint-router-recovery,make migrate-validate, and the apiv2 OpenAPI, contract, and fixture checks, the route inventory, the v1 route freeze, the migration ledger, and the local-path check: pass. The fullmake test-goand the web gate were not run;web/is untouched.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2601/
Risks
notification_webhooks, a small per-profile table. Its Down fails without changing anything when two accounts' same-ID profiles already share a webhook name.PurgeProfileremoves interest rows and notification preferences, which are still keyed by profile ID alone. [bug] Same-ID profiles on two accounts share one series-interest row, so one stops getting episode notifications #2597 owns those.(profile_id, device_id, platform)stays. After the reassignment change, one install holds registrations for only one account profile, so the key can't collide across accounts.Follow-ups
notification_deliveriesreads),notification_preferences, andnotification_inbox_clocksare also keyed by profile ID alone. That is a separate concern, tracked in [bug] A profile sees another account's notification inbox when profile IDs match #2603 and fixed in fix(notifications): key episode notification state by account and profile #2602, and is not changed here.Checklist
AI Disclosure
codex exec) reviewed the plan. It changed two things: the webhook name constraint keeps its name for rolling upgrades, and idempotent deletes keep returning 204. It also noted the reassignment race the [bug] Episode notifications can reach another account's devices and webhooks when profile IDs match #2596 sender check covers. A background adversarial review by gpt-6.1-sol (xhigh, read-onlycodex exec) of 0de8142 found nothing, so it posted no review.🤖 Generated with Claude Code
Note
Scope all notification destination operations to the acting account
Webhook, web-push, push-device, and email-preference operations previously matched rows by profile ID alone, so another account using the same profile ID could list, update, delete, or test-send another account's destinations. This PR threads the acting user ID through the API handlers, services, and repositories so every destination query, update, and delete is scoped to the (user_id, profile_id) pair.
WebhookRepository.InsertWithLimitnow appliesmaxPerProfileper account-profile pair, and push-device upserts purge the same device installation for other accounts/profiles in webhook_repo.go and push_devices.goSystem.PurgeProfilepasses the account ID to webhook, web-push, push-device, and email-preference cleanup so only the specified account's rows are deletedInsertWithLimitis still keyed by profile ID, so same-ID profiles across accounts serialize on webhook creationMacroscope summarized 9e271e4.