Skip to content

fix(notifications): keep admin test pushes on the caller's account - #3604

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/push-test-send-account-scope
Nov 9, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/push-test-send-account-scope

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

An admin testing push on the profile default could send a real notification to someone else's phone and be told it was delivered. This change keeps admin test pushes on the caller's own account, on both the v2 routes and the v1 bridge routes (/admin/notifications/push/apple/test and /admin/notifications/push/fcm/test).

These routes take a profile_id from the request body and never check it against an account. Profile IDs are only unique per account, and older accounts all share default, so the query picked whichever account's device was seen last. Naming the other account's server_device_id reached the same phone. The response also returned that account's attempt and device IDs and the relay outcome, plus delivery_id on v2.

Kody flagged the query as critical while reviewing #3592. It is not a privilege escalation: only an acting admin can call these routes, and the push carried the owner's own notification to the owner's own device, so no notification text reached the admin. The harm is the misdirected push and the false "delivered" report.

Approach

EnqueueTestAttempt now also matches user_id, and both API versions pass the account from the caller's token. Any profile on the caller's account can still be tested. Another account's profile or device gets the same 404 as a device that does not exist, and no attempt is recorded. On v1, only this authorization behaviour changes; the change is recorded in docs/architecture/v1-scope.md.

Deliberate behaviour change: a server admin can no longer test another account's device, even through a unique profile ID, where that used to work. The request has no account field, and frozen v1 cannot gain one. I found no web, Apple or Android caller of these routes, and the user manual does not mention them. If admins turn out to need this for support, v2 could add an explicit account field later.

This query also changes in #3592, so whichever PR merges second needs a small rebase.

Validation

  • New database test (added to db-contracts.txt): fails on both platforms without the fix, passes with it. It covers the caller's own and sibling profiles, the other account's device with and without a selector, and matching errors.
  • v1 and v2 handler tests: pass, and fail if the handler does not pass the caller's account.
  • Real server with a throwaway database, all four routes: results under Evidence. A successful send to the caller's own device used a fake relay in the database test, not a physical device.
  • make lint-changed, build, vet, OpenAPI and web type generation, contract, route inventory and v1 route freeze checks: pass.
  • make test-go: fails only on TestPersonalListPageFollowsAccessDB and TestRatingsPageIndexDB, query-plan tests in internal/catalog, which depends on no package changed here. The first also fails on clean main; the second passed when run alone on clean main, so I have not reproduced it there.
  • make test-db-contracts: no test failed, but it exits non-zero because backup tests skip on a machine without pg_dump/pg_restore. That run predates a final test-only cleanup; the new test passed again afterwards, directly and in make test-go.
  • Merged main for fix(notifications): stop web push when the registering login session ends #3603, which changed the same query. The merged query keeps both the account filter and fix(notifications): stop web push when the registering login session ends #3603's live-login check, and fix(notifications): stop web push when the registering login session ends #3603's TestPushStopsWhenTheRegisteringLoginEndsDB passes the account it registers under. A copy of the new database test that calls main's signature fails on main and passes here.
  • Not run: web lint, build and tests (the only web change is a generated doc comment), verify-actionlint, verify-shellcheck, verify-prometheus-rules.

Evidence

No screen changes; this is API behaviour. Tokens below are test fixtures.

Before, with an admin and another account both on default, the push for the admin's own profile went to the other account's device (b…) instead of the admin's (a…):

--- FAIL: TestSendPushTestStaysOnTheCallersAccount/apple
    relayed tokens = ["bbbbbbbb…" "cccccccc…"]; want the admin's own phone, then the sibling profile's
--- FAIL: TestSendPushTestStaysOnTheCallersAccount/android
    relayed tokens = ["bbbbbbbb…" "cccccccc…"]; want the admin's own phone, then the sibling profile's

After, on a real server, where the admin has no device and the other account has one on default. Each request returned the same 404 as a profile that does not exist, and no attempt rows were written:

POST /api/v1/admin/notifications/push/apple/test {"profile_id":"default"}
POST /api/v1/admin/notifications/push/apple/test {"profile_id":"default","server_device_id":"<other account's device>"}
POST /api/v1/admin/notifications/push/apple/test {"profile_id":"no-such-profile"}
  404 {"error":"not_found","message":"Apple push device not found"}

POST /api/v2/admin/notifications/push/apple/test (same three bodies)
  404 {"title":"Not found","status":404,"detail":"Push device not found.", ...}

The FCM routes returned the same responses with Android push device not found on v1. A regular user got 403 and an anonymous caller 401.

Risks

Anyone relying on these routes to test another account's device will now get a 404, as described under Approach. There is no migration, and the v1 and v2 response shapes do not change.

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: T3 Code running Claude Code
  • Tool(s): Claude Code, Codex CLI (review only)
  • Model(s): claude-opus-5-5, gpt-6.1-sol (review only)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: claude-opus-5-5 and gpt-6.1-sol independently reviewed the final diff for correctness, repository standards and the request. Neither found a correctness or spec problem. Three low-severity style notes from claude-opus-5-5 (the v1 test seam, single-use test helpers, running the database test on both platforms) were left as they are, since this is an authorization check reachable through two platform paths.

Note

Scope admin push-test device selection to the caller's account

Admin push-test routes previously dispatched using only the profile and device selectors, so a shared profile ID could resolve to another account's device. The v1 and v2 handlers now pass the authenticated account ID from request claims into the push-test service, and PushDeviceRepository.EnqueueTestAttempt matches account, profile, platform, provider, and push mode when selecting a device.

  • Requests without claims return 401 without a service call
  • Cross-account or missing targets return the existing not-found response without sending a push or creating an attempt
  • Updates OpenAPI docs, v1 scope ledger, notifications API docs, and the generated v2 schema; adds database coverage in TestSendPushTestStaysOnTheCallersAccount plus handler tests
  • Risk: PushDeviceRepository.EnqueueTestAttempt in push_delivery.go now requires an account ID; callers in push_devices_test.go and push_test_send_db_test.go are updated, and the new cross-account contract test is listed in db-contracts.txt

Macroscope summarized 85832db.

The admin test push routes take a profile ID but no account, and profile
IDs such as the legacy `default` repeat across accounts. Testing `default`
could send another person's phone a real notification and report it as
delivered, and naming their server device ID did the same.

Select only among the calling account's devices, on any of its profiles,
on both the v2 and v1 routes. Another account's profile or device now gets
the same 404 as a device that does not exist.
@Rhainland
Rhainland requested a review from Quick104 as a code owner November 6, 2026 12:49
@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 6, 2026
@silo-kody

silo-kody Bot commented Nov 6, 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 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Apple and Android test-push requests now require authenticated claims and use the caller’s account ID when selecting a device. Cross-account devices are not found. API schemas and documentation describe the account-scoped lookup and its 404 responses.

Changes: Account-scoped test-push requests

Layer / File(s) Summary
Authenticated test-push dispatch
internal/api/handlers/admin_apple_push.go, internal/apiv2/admin_notification_push.go, internal/api/handlers/admin_apple_push_test.go, internal/apiv2/admin_notification_push_test.go
Handlers require claims and pass the authenticated user ID to the selected platform sender. Tests check that requests without claims return 401 and that dispatch uses the claimed ID.
Account-scoped device selection
internal/notifications/push_sender.go, internal/notifications/push_delivery.go, internal/notifications/push_test_send_db_test.go, scripts/ci/db-contracts.txt, contracts/api/v2/openapi.json, web/src/api/v2/schema.ts, docs/architecture/v1-scope.md, docs/notifications-api.md
Push delivery passes the account ID to device lookup, which filters by user ID. Database tests cover account matching and cross-account not-found responses. API schemas and documentation describe the behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested labels: bug, go, api-v2, documentation, impact: security, impact: compat, size/L

Merge Risk: Minimal · up to c7bc8

Test-push requests select devices on the caller's account, and no actionable merge-blocking issue remains after normal checks.

Security architecture risk: Minimal · up to c7bc8

The change narrows test pushes to the caller’s account while preserving existing administrator checks. The reviewed paths reject cross-account selectors before creating an attempt or contacting the push relay. No material security risk introduced or worsened by this change was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The affected privileged operation covers Apple and Android test pushes through both API versions. The narrowed selection permits any profile on the caller’s account but excludes another account’s device even when its server_device_id is supplied.

Security Findings and Attack Paths

  • observed — The pre-existing cross-account selection path is narrowed at the database lookup rather than filtered after sending. The regression test checks that shared profile IDs select the caller’s token and that foreign profile or device selectors produce neither foreign attempts nor relay submissions.

Trust Boundaries and Controls

  • observed — Caller-controlled profile and device selectors remain subordinate to claims-derived account identity. The account ID is supplied by the API boundary, not accepted as another request-body selector, and is combined with platform, provider, mode and enabled-state predicates before selecting a device.

Resilience and Maintainability Implications

  • observed — Recovery uses persisted attempt references rather than rerunning the request’s profile-only selection. Processing rejects missing or disabled devices, missing attached notifications, attached-notification ownership mismatches and token decryption failures. These failure-containment controls predate this PR and are preserved.
Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed

Check name Status Explanation
Title check Passed The title clearly describes the change to restrict admin test pushes to the caller's account.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description states that admin test pushes on the v1 and v2 Apple and FCM routes are restricted to the caller's own account, which matches the changeset: handlers pass the account ID from claims, E…
Full details: Description check

Explanation

The description states that admin test pushes on the v1 and v2 Apple and FCM routes are restricted to the caller's own account, which matches the changeset: handlers pass the account ID from claims, EnqueueTestAttempt matches user_id, docs and OpenAPI are updated, and tests are added. It is detailed and directly on-topic, so it passes the lenient relevance check.

Full details: Docstring Coverage

Explanation

Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 7 files. (5 skipped: 4 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent 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: 7bc26bf5-71b6-42ae-aba7-682488f014e9
Commits

Reviewing files that changed from the base of the PR and between 6791aac and c7bc8bb.

Files selected for processing: 12

  • contracts/api/v2/openapi.json
  • docs/architecture/v1-scope.md
  • docs/notifications-api.md
  • internal/api/handlers/admin_apple_push.go
  • internal/api/handlers/admin_apple_push_test.go
  • internal/apiv2/admin_notification_push.go
  • internal/apiv2/admin_notification_push_test.go
  • internal/notifications/push_delivery.go
  • internal/notifications/push_sender.go
  • internal/notifications/push_test_send_db_test.go
  • scripts/ci/db-contracts.txt
  • web/src/api/v2/schema.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@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 Nov 6, 2026
@coderabbitai coderabbitai Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase documentation Improvements or additions to documentation impact: compat Breaks a supported client or server path labels Nov 6, 2026
# Conflicts:
#	internal/notifications/push_delivery.go

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 T3 Code running Claude Code (claude-opus-5-5)

One small cleanup, below. I merged main into the branch first (85832db): #3603 added the login-liveness filter to the same EnqueueTestAttempt query, so the resolved query keeps both filters, and the merge passes account 7 in #3603's TestPushStopsWhenTheRegisteringLoginEndsDB. I found no correctness problem.

@Quick104

Quick104 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🤖 T3 Code running Claude Code (claude-opus-5-5)

Review summary

Reviewed head: 85832db128 (the contributor's c7bc8bb with main merged in).

No defects found. The change scopes the test-push device lookup to the caller's account in the shared repository query, so both API versions get it from one place.

Branch update. I merged main because #3603 changed the same EnqueueTestAttempt query. The merged query filters on the caller's account and on #3603's live-login check. #3603's TestPushStopsWhenTheRegisteringLoginEndsDB now passes the account it registers its devices under.

Verification.

  • The new TestSendPushTestStaysOnTheCallersAccount doesn't compile on main, because the signature changed. I ran a copy that calls main's signature against a scratch Postgres. On main it fails for both platforms: the admin's default test push goes to the other account's phone. On the head it passes, along with TestSendPushTestCarriesTheProfilesNewestNotification and TestPushStopsWhenTheRegisteringLoginEndsDB.
  • The v1 and v2 handler tests pass.
  • A multi-angle code review and an independent gpt-6.1-sol review of this head found nothing that held up. I posted and then withdrew one cleanup note: the system field is still read elsewhere.

Remaining. One deliberate behaviour change is for the maintainers to settle: an admin can no longer send a test push to another account's device. Nothing calls these routes from the web app, silo-apple, or silo-android, and the request has no account field, so scoping to the caller is the change that fits the current contract. If support needs cross-account tests later, an explicit v2 field could add them.

Validated features. None affected. The passed Notifications cases (#1234 C1/C3/C4, #1235 C1/C2, Silo-Server/silo-apple#336 C1, Silo-Server/silo-android#346 C1) cover event fan-out, payload privacy, and opening content. None of them uses an admin test push to another account's device. Validation tasks: none stands.

User manual. Unaffected. The manual doesn't describe these routes.

Apple/Android. No client change is needed. Neither app calls these routes.

Overlap. #3592 still edits this query, so whichever PR merges second needs a small rebase.

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

  • Fit: it fixes a misdirected push and a false "delivered" report. The fix sits in the shared query, adds no new surface, and records the v1 change in the bridge ledger.
  • Readiness: the behaviour was shown failing on main through main's own API and fixed on the head. CI is running on the merge commit.

@Quick104
Quick104 merged commit 220ac9e into Silo-Server:main Nov 9, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase bug Something isn't working documentation Improvements or additions to documentation go Pull requests that update go code impact: compat Breaks a supported client or server path impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants