Skip to content

fix(notifications): guard legacy mobile push account ownership - #2762

Merged
Quick104 merged 2 commits into
mainfrom
fix/push-registration-account-ownership
Oct 20, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/push-registration-account-ownership

Conversation

@Quick104

@Quick104 Quick104 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2760
Related issue: N/A
Validation tasks: none. The legacy registration behavior behind #1234 C2 changes, and that case is recorded as Not run; the Apple and Android tasks use ordered v2 registration, which this change leaves alone.

Legacy Apple and Android push registration can retire another account's destination and queued attempts when the caller supplies the same device identifier. This change refuses that collision with the existing v1 409 conflict response and preserves the foreign account's stored state. The confirmed impact is notification suppression.

Approach

Check account ownership at the repository boundary under the existing installation lock, before any destination cleanup or update. Same-account profile switches remain atomic. Ordered v2 installation proof and generation rules stay intact.

Current Apple and Android callers use ordered v2 and already handle registration refusal; neither needs a code change. Jellycompat has no mobile push-registration operation. The API reference documents the bridge rule. User manual: unaffected after checking notification guides, the release card and feature mappings. Browser push ownership is outside this change.

Validation

  • Offline before/after regression: actual repository code fails before the fix and passes after, using synthetic account/profile/token fixtures. No live deployment reproduction or provider delivery was attempted.
  • Push-focused repository and handler tests pass, including race detection, unchanged-row snapshots, rollback, repeated profile IDs, same-account switching and ordered proof/generation preservation. All five C36 database pins pass. All application migrations applied successfully to a separate disposable database; fixture tables and migrated-schema coverage are distinguished in the evidence.
  • Build, vet, changed-line lint, router recovery, formatting, generated contracts/fixtures and documentation hygiene pass. Web lint, formatting, build, bundle budget and 8,399 tests pass.
  • Full Go tests have the same seven failures on the untouched base. The broader database gates retain inbox-cutoff and collage assertions reproduced on the base. Earlier socket-bridge concurrency failures were assessed and retried serially. These gates are not green.
  • Actionlint and ShellCheck pass. The migration CLI validation target cannot run offline because of a Goose module metadata lookup, also reproduced on the base. The migration diff check passes. Prometheus checks were not run because the pinned image was unavailable locally; observability inputs are unchanged.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2760/

Risks

An older bridge client switching accounts can receive a conflict while the previous account's destination remains registered. Repeating registration does not resolve ownership. Ordered bootstrap must use the existing account before later transfers can use installation-key proof and a newer generation. Matching provider tokens and disabled rows do not grant reassignment authority. No automatic recovery policy is added.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section records the changed refusal behavior and offline verification limits.

AI Disclosure

  • Harness: Codex in T3 Code; independent review through Claude Code in T3 Code.
  • Tool(s): functions.exec, mcp__t3_code__delegate_task, gh, Go tools, isolated PostgreSQL, silo-evidence.
  • Model(s): gpt-6.1-sol (implementation, xhigh); claude-opus-5-5 (independent review, high).
  • Involvement: AI-assisted. AI wrote the implementation and tests; no human runtime verification is claimed.
  • Follow-up review: Claude Code (claude-opus-5-5) reviewed af2710cc0 with a read-only Codex (gpt-6.1-sol) cross-check and committed bbb28bb4d, which moves the ordered v2 bootstrap ownership checks onto the same helper and documents what clears a legacy ownership conflict. The account-switch trade-off for older builds is open for a maintainer decision in the review.
  • Adversarial review: The approach round checked ownership, locking, rollback, clients and bridge compatibility. It confirmed the repository boundary and raised an older-client limitation, now documented. Its proposed same-token exception was rejected because it would still allow a caller-supplied value to retire foreign rows. Background implementation review by claude-opus-5-5 completed against af2710cc05fa4d875a8cdc11386de1e7a095121a: it checked all seven files, surrounding transactions and pinned native callers, with zero verified findings; nothing was posted.

Note

Guard legacy mobile push registration against cross-account takeover

  • Adds a shared checkPushInstallationOwner helper in push_devices.go. It runs under the installation lock and returns ErrPushGenerationConflict when another account already owns a destination for the same device and platform.
  • Legacy UpsertApple and UpsertFCM writers now use this guard for generation-zero registration. Profile-switch cleanup is restricted to same-account destinations, so a legacy registration can no longer delete another account's push destination.
  • Registration handlers map ErrPushGenerationConflict to HTTP 409 with error code conflict on both the Apple and generic Android routes.
  • Adds database tests covering foreign-account rejection, rollback on failed profile switches, interaction with ordered registration, lock-waiting concurrency, and ownership retention. Updates the API doc and adds the five new tests to the CI contract list in db-contracts.txt.
  • Behavioral Change: unadopted installations may now register and switch profiles only within the current account; cross-account registration returns 409 instead of silently taking over the device. Same-account profile switching still retires the previous profile destination atomically.

Macroscope summarized bbb28bb.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 20, 2026
@silo-kody

silo-kody Bot commented Oct 20, 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 20, 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: aa2bb503-c508-4d00-844a-0eac8817da41
📥 Commits

Reviewing files that changed from the base of the PR and between ed40fa2 and af2710c.

📒 Files selected for processing: 7
  • docs/notifications-push-api.md
  • internal/api/handlers/notifications_push_devices.go
  • internal/api/handlers/notifications_push_devices_test.go
  • internal/notifications/destination_management_db_test.go
  • internal/notifications/push_devices.go
  • internal/notifications/push_legacy_ownership_test.go
  • scripts/ci/db-contracts.txt

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

Legacy Apple and Android push registration now rejects foreign-account ownership conflicts without changing destinations or queued attempts. Same-account profile switching remains supported. The API maps these conflicts to HTTP 409.

Changes: Legacy mobile push ownership

Layer / File(s) Summary
Ownership checks and database validation
docs/notifications-push-api.md, internal/notifications/push_devices.go, internal/notifications/*ownership*_test.go, internal/notifications/destination_management_db_test.go, scripts/ci/db-contracts.txt
Legacy Apple and FCM registration checks for destinations owned by another account before cleanup. Database tests cover foreign-account rejection, same-account profile changes, ordered ownership transfer, and lock outcomes. The API documentation describes the ownership and transfer rules.
HTTP conflict responses
internal/api/handlers/notifications_push_devices.go, internal/api/handlers/notifications_push_devices_test.go
Apple and Android registration handlers map push generation conflicts to HTTP 409 with the conflict error code. Tests verify the response and that each handler calls the store once.

Priority: ⬇️ Low

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

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to af271

Legacy Apple and Android push registration now rejects a device already owned by another account with a 409 conflict. It leaves that account's destination and queued notifications untouched. Profile switching within the same account still works, and concurrent registrations are serialized by the existing installation lock. Older bridge clients that previously took over a device automatically will now receive a conflict instead; this change is documented and intended. No merge-blocking risk remains.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 5 files. (2 skipped: … 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 and concisely describes the main change: protecting legacy mobile push account ownership.
Linked Issues check Passed Issue #2760 requires foreign-account rejection before destination or queued-attempt changes, same-account profile switching, ordered v2 protections, and locking at the repository transaction boundary.…
Out of Scope Changes check Passed The changes stay within issue #2760. Repository changes implement ownership checks and account-scoped cleanup. Handler changes expose the required existing 409 response. Tests verify the affected Appl…
Description check Passed The description directly explains the legacy Apple and Android push registration ownership fix, its conflict behavior, preserved state, validation, risks, and scope.
Full details: Linked Issues check

Explanation

Issue #2760 requires foreign-account rejection before destination or queued-attempt changes, same-account profile switching, ordered v2 protections, and locking at the repository transaction boundary. UpsertApple and UpsertFCM acquire the installation lock, reject generation-zero foreign ownership with ErrPushGenerationConflict, and restrict cleanup to the same account. The handlers map this error to HTTP 409 conflict. The added database tests cover Apple and Android ownership refusal, unchanged state, rollback, same-account switching, lock ordering, and ordered registration rules. The API documentation records the bridge behavior and web push remains unchanged.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #2760. Repository changes implement ownership checks and account-scoped cleanup. Handler changes expose the required existing 409 response. Tests verify the affected Apple and Android paths and transaction behavior. Documentation defines the changed bridge contract and explains the existing ordered-transfer requirements. No browser push, Jellycompat, or unrelated product behavior changes appear in the reviewed diff.

Full details: Docstring Coverage

Explanation

Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 5 files. (2 skipped: 2 unsupported.)

Resolution

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

  • 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 20, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 20, 2026

Copy link
Copy Markdown

The Notifications validation tasks listed by the parent currently record every case as Not run; there is no passed, failed, or blocked result for this PR to invalidate or unblock. The current reaches ... line therefore does not match the recorded validation impact. Suggested replacement:

Validation tasks: none

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review of af2710cc0. The guard is correct: both legacy writers check account ownership after taking the installation lock and before any delete, a refusal rolls back the installation row it inserted, and same-account profile switching still retires the previous profile's destination and its attempts in one transaction. The rule matches the one ordered v2 bootstrap already applies. I found one product trade-off that needs your call and two smaller items, which I'm fixing on this branch.

AI-generated review: Claude Code (claude-opus-5-5), cross-checked with Codex (gpt-6.1-sol).

Comment thread internal/notifications/push_devices.go Outdated
if generation > 0 {
return nil, ErrPushLegacyWriter
}
if err := checkLegacyPushOwner(ctx, tx, registration.DeviceID, PushPlatformApple, registration.UserID); err != nil {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Medium, needs your call (disclosed in Risks): account switching on older builds now leaves both accounts worse off.

Trigger: a shared phone runs an Apple build from before v2 push registration or an Android build from before ordered registration. Account A signs out and account B signs in on the same install. Neither of those builds unregisters on sign-out: the old Apple coordinator has no unregister call, and the old Android unregisterDevice() has no caller.

Impact: before this PR, B's registration replaced A's row. Now B gets 409 conflict on every launch and has no push destination. A's row stays enabled with its queued attempts, so A's notifications keep waking that phone; the client fetches their content with B's credentials and can only show generic text. No content leaks, but the phone shows the wrong account's alerts and none of B's. Signing out or revoking A's sessions doesn't clear it. Only A unregistering (which those builds can't do), deleting A's profile, or deleting A's account does. Upgrading the app while B is selected doesn't help either, because v2 bootstrap refuses the same retained row.

Options:

  1. Accept it for the bridge window. Current Apple and Android builds use ordered v2, the old builds handle the 409 quietly (they log it and try again on the next foreground or token callback, with no retry loop), and the original issue is low severity. The doc already states the limitation; I'm adding what clears it (separate comment).
  2. Let a legacy registration replace foreign rows only when every foreign row carries the same provider token hash as the request. The PR body rejects a same-token exception because the token is caller-supplied, but it differs from the device ID in the way that matters here: the server never returns it, so another account can present it only if it already holds that app install's APNs or FCM token. That keeps household account switching on old builds working and still refuses a caller who knows only the device ID. It would change the doc's statement that a matching token doesn't bypass ownership.

I haven't changed this; it's your decision.

Comment thread internal/notifications/push_devices.go Resolved
Comment thread docs/notifications-push-api.md Resolved
Ordered Apple and Android bootstrap now use the same account-ownership
check as the legacy writers, so the bridge and ordered paths cannot
drift on who owns an installation. The push API doc also names what
clears a legacy ownership conflict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

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

Copy link
Copy Markdown
Contributor Author

Review summary

Reviewed head: bbb28bb4d (my review covered af2710cc0; the only change since is my follow-up commit).

Fit: 8/10 · Readiness: 8/10 — conditional

Fit. This closes a real cross-account write. Before this PR, any signed-in account that sent another account's device ID to the legacy registration routes deleted that account's push destination and its queued attempts. The fix enforces ownership at the account level, matching the rule ordered v2 bootstrap already applies. It's a reasonable use of the critical-fix exception on the frozen /api/v1 bridge: these routes already answer 409 for another reason, and the response shape doesn't change. Fit isn't higher because the fix takes away a working flow on older app builds (below).

Readiness. The guard is correct on both platforms. It runs after the installation lock and before any delete, a refusal leaves destinations, attempts, and the installation row untouched, and same-account profile switching still retires the previous profile's destination in one transaction. What holds the score down is one open product decision.

Needs your call

  • Account switching on older builds. On a shared phone running an Apple or Android build from before ordered push registration, signing out of account A and into account B used to move the registration to B. Now B gets 409 conflict on every launch, and A's destination stays enabled, so the phone keeps getting A's notifications as generic alerts and none of B's. Those builds never unregister on sign-out, and signing out or revoking A's sessions doesn't release the device. Only deleting A's profile or account does. The old builds handle the 409 quietly, with no retry loop. The options are in the review thread: accept it for the bridge window (the doc states it), or let a legacy registration replace foreign rows only when they carry the same provider token as the request. The server never returns that token, so a caller who knows only the device ID would still be refused.

Addressed

  • Low, cleanup, fixed in bbb28bb4d: the foreign-owner query existed in three places. Ordered Apple and Android bootstrap now call the same helper (checkPushInstallationOwner), so the bridge and ordered paths can't drift apart on who owns an installation.
  • Low, docs, fixed in bbb28bb4d: the doc said repeated registration doesn't clear a conflict but not what does. It now names the owner's unregister and profile or account deletion, and says signing out doesn't release the device.

Verification

  • Live check on local builds of the base (ed40fa20f) and this head (bbb28bb4d), each against its own freshly migrated throwaway database, with two accounts and three profiles: one account's profile switch with the same token, a same-profile re-registration, then the second account registering the same device ID. On the base the second account's request returned 200 and replaced the first account's row. On this branch it returns 409 conflict and the first account's row is unchanged. The second account's unregister leaves that row in place. After the first account unregisters, the second account registers with 200.
  • go test -race ./internal/notifications/, the apiv2 and v1 handler push tests, all 23 notification DB pins, and make lint-changed pass on bbb28bb4d. CI is green on bbb28bb4d.
  • Not checked: provider delivery and the old app builds on real devices. Client behavior on a 409 comes from reading their source.

Validated features

No passed case is affected. #1234 C2 reaches the changed legacy routes but is recorded as Not run. The Apple and Android tasks (Silo-Server/silo-apple#336, Silo-Server/silo-android#346) cover current builds, which register through ordered v2 and see no change. I changed the body's line to Validation tasks: none, as the validation-impact check suggested.

Other checks

  • User manual: unaffected. It doesn't describe push registration or account switching.
  • Apple and Android: no change needed. Current builds use ordered v2. Jellyfin compatibility has no push registration.
  • Rolling deploys: a node still on the old binary keeps the old takeover behavior until every API node runs this change.
  • scripts/ci/db-contracts.txt: fix(access): move group members to the default before deletion #2705, fix(auth): store API keys as one-way verifiers #2715, and fix(auth): enforce signup policy before account commit #2716 edit other hunks. A trial merge of each with this branch is clean.
  • Evidence: the existing page still holds. My commit doesn't change behavior. I re-ran the tests the page cites on the new head, and the live check above adds the HTTP-level result.
  • Cross-provider round: Codex (gpt-6.1-sol) reviewed af2710cc0 read-only and found no implementation defect. It raised the same older-build account-switch trade-off, confirmed that neither old build retries in a loop, and listed which removal paths release ownership.

AI-generated review: Claude Code (claude-opus-5-5), cross-checked with Codex (gpt-6.1-sol).

@Quick104
Quick104 merged commit 9e81ab0 into main Oct 20, 2026
20 checks passed
@Quick104
Quick104 deleted the fix/push-registration-account-ownership branch October 20, 2026 14:53
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/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.

[bug] Legacy mobile push registration can retire another account’s destination

1 participant