Skip to content

fix(notifications): keep destination management on the acting account - #2601

Merged
Quick104 merged 2 commits into
mainfrom
fix/issue-2598-destination-account
Oct 16, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/issue-2598-destination-account

Conversation

@Quick104

@Quick104 Quick104 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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's default profile 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 matched profile_id alone. This change matches the account and the profile on every management read and write, in /api/v2/notifications and in the frozen /api/v1 routes. 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, and PushDeviceService.Unregister, and the repositories match (user_id, profile_id). The same applies to the per-profile webhook cap and to the cleanup PurgeProfile runs 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_key but changes its columns from (profile_id, name) to (user_id, profile_id, name). Without it, B's default profile couldn't use a webhook name A's default already 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

  • Reproduced on a Silo dev sandbox built from main: two accounts whose profiles both had the ID default. 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.
  • New DB tests cover webhooks, web push, legacy push registration, 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 test for internal/notifications, internal/apiv2, and internal/api/... against a sandbox database: pass. Five internal/api/handlers tests that also fail on main against 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 full make test-go and the web gate were not run; web/ is untouched.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-2601/

Risks

  • The migration rebuilds one unique index on notification_webhooks, a small per-profile table. Its Down fails without changing anything when two accounts' same-ID profiles already share a webhook name.
  • This doesn't change whether PurgeProfile removes 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.
  • The push device key (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

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: Claude Code, running in T3 Code
  • Tool(s): Claude Code; OpenAI Codex CLI for the plan review
  • Model(s): claude-opus-5-5 (implementation); gpt-6.1-sol (plan review)
  • Involvement: Fully AI-generated; human verification is pending maintainer review
  • Adversarial review: before implementing, gpt-6.1-sol (xhigh, read-only 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-only codex 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.

  • A Goose migration replaces the webhook name uniqueness constraint on (profile_id, name) with one on (user_id, profile_id, name) in 20261016163853_scope_webhook_names_to_account.sql
  • WebhookRepository.InsertWithLimit now applies maxPerProfile per account-profile pair, and push-device upserts purge the same device installation for other accounts/profiles in webhook_repo.go and push_devices.go
  • System.PurgeProfile passes the account ID to webhook, web-push, push-device, and email-preference cleanup so only the specified account's rows are deleted
  • Adds integration tests in destination_management_db_test.go covering cross-account isolation, endpoint reassignment, and purge behavior
  • Risk: rolling back the migration fails if duplicate webhook names exist across accounts; the advisory lock in InsertWithLimit is still keyed by profile ID, so same-ID profiles across accounts serialize on webhook creation

Macroscope summarized 9e271e4.

@silo-triage silo-triage Bot added the size/XL 500–999 added + deleted lines (all files); change volume, not priority. label Oct 16, 2026
@silo-kody

silo-kody Bot commented Oct 16, 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 16, 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: 27339834-af25-4927-9496-3e5ac01e208c
📥 Commits

Reviewing files that changed from the base of the PR and between 4471cde and 9e271e4.

📒 Files selected for processing: 1
  • internal/notifications/system.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.

📝 Walkthrough

Notification destination operations now pass account and profile identity through API handlers, services, and repositories. Webhook, web-push, push-device, and profile-cleanup queries scope records to both identifiers. Database and handler tests cover profiles with matching IDs across accounts.

Changes: Account-scoped notification destinations

Layer / File(s) Summary
Resolve and pass viewer identity
internal/api/handlers/*, internal/apiv2/notification_destination_tests.go, internal/apiv2/notification_destinations.go, internal/apiv2/notification_webhook_update.go, internal/apiv2/*_test.go
Handlers and service contracts pass the authenticated user ID with the profile ID to destination operations. API v2 handlers resolve viewer identity before listing or changing destinations. Tests check the dispatched user ID.
Scope webhook operations and names
internal/notifications/webhook_service.go, internal/notifications/webhook_repo.go, migrations/sql/20261016163853_scope_webhook_names_to_account.sql, internal/notifications/webhook_*_test.go, internal/notifications/destination_test_sends_test.go
Webhook reads, updates, deletes, secret rotation, guarded operations, pagination, and per-profile limits filter by account and profile. The migration changes webhook-name uniqueness to (user_id, profile_id, name). Tests cover cross-account access and name constraints.
Scope web-push and device ownership
internal/notifications/webpush_service.go, internal/notifications/webpush_repo.go, internal/notifications/push_devices.go, internal/notifications/*push*_test.go, internal/notifications/destination_pages_test.go
Web-push listing and deletion use account and profile identity. Endpoint reassignment removes pending or retrying attempts when either owner identifier changes. Push-device cleanup and unregister operations filter by account, profile, and device.
Scope profile cleanup by account
internal/notifications/system.go, internal/notifications/email_prefs_repo.go, internal/notifications/email_verification_dispatch_test.go
Profile cleanup passes the account ID to destination, push-device, and email-preference deletion operations. Email preferences are deleted only when both account and profile match.
Verify cross-account isolation
internal/notifications/destination_management_db_test.go
Database tests cover webhook and web-push isolation, webhook limits and name constraints, push-device registration and deletion, and profile purging when accounts share a profile ID.

Priority: ⬆️ High

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix · Severity of issue fixed: High

Merge Risk: ⚪ Minimal · up to 9e271

Profile cleanup now targets destinations using both the account and profile IDs, avoiding changes to another account’s matching profile. No merge-blocking risk is evident in the reviewed change.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Linked Issues check Warning Most coding requirements in [#2598] are implemented. Webhook and web-push operations, legacy push unregistering, quota checks, and PurgeProfile use (user_id, profile_id). The migration and databas… Update the affected delete paths and tests so a cross-account destination ID returns the required not-found result while leaving the foreign row unchanged. If 204 is required for compatibility, update [#2598] before treating this requirem…
Docstring Coverage Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 45 functions across 32 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: notification destination management is scoped to the acting account.
Description check Passed The description directly explains the cross-account authorization issue, the account-and-profile scoping changes, migration, tests, validation, risks, and follow-ups.
Out of Scope Changes check Passed The changes stay within [#2598]. V1 route coverage, legacy push registration handling, webhook quota handling, reassignment cleanup, account-scoped PurgeProfile cleanup, the migration, and supportin…
Full details: Out of Scope Changes check

Explanation

The changes stay within [#2598]. V1 route coverage, legacy push registration handling, webhook quota handling, reassignment cleanup, account-scoped PurgeProfile cleanup, the migration, and supporting tests implement the account-and-profile ownership requirement. The changes do not include the separately assigned interest-row cleanup or the follow-up inbox, preference, or clock work.

Full details: Linked Issues check

Explanation

Most coding requirements in [#2598] are implemented. Webhook and web-push operations, legacy push unregistering, quota checks, and PurgeProfile use (user_id, profile_id). The migration and database tests cover account-scoped names and cleanup. However, [#2598] expects deleting another account's destination to return not found. The PR explicitly retains 204 for idempotent deletes of IDs that the acting account does not own.

Resolution

Update the affected delete paths and tests so a cross-account destination ID returns the required not-found result while leaving the foreign row unchanged. If 204 is required for compatibility, update [#2598] before treating this requirement as satisfied.

  • 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 go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 16, 2026
@Quick104
Quick104 force-pushed the fix/issue-2598-destination-account branch from 0de8142 to 469778c Compare October 16, 2026 21:27
@silo-kody

silo-kody Bot commented Oct 16, 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 ❌

@silo-kody

silo-kody Bot commented Oct 16, 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 ❌
⚠️ 1 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

Quick104 and others added 2 commits October 16, 2026 17:49
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]>
@Quick104
Quick104 force-pushed the fix/issue-2598-destination-account branch from 4471cde to 9e271e4 Compare October 16, 2026 21:56
@silo-kody

silo-kody Bot commented Oct 16, 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 ❌

@Quick104
Quick104 merged commit df107b7 into main Oct 16, 2026
16 checks passed
@Quick104
Quick104 deleted the fix/issue-2598-destination-account branch October 16, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/XL 500–999 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] A profile can list and change another account's webhooks and web push subscriptions when profile IDs match

1 participant