Repository navigation
fix(notifications): let an iPhone recover push after a reinstall - #3352
Conversation
A reinstalled iOS app keeps its device ID but sends a new installation key, and every Apple push registration was refused with a generic 403 that nothing on the server could clear. A registration whose key does not match now gets 403 push_installation_key_mismatch when the caller's account owns the installation; another account still gets permission_denied. The owning account can call POST /api/v2/devices/push/apple/reset (resetApplePushInstallation) with its login session and current key. Under the installation lock the reset deletes the device's Apple push rows and clears the stored key, owner and generation, so the next registration binds the new key from any generation. A reset is refused for another account's installation and is a no-op when the installation is already bound to the sent key, so a retried reset cannot undo the registration after it. The Apple capability reports installation_reset_available.
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:
|
|
The API excerpts cover the owner mismatch and reset flow, but do not show the changed capability response. Please add before-and-after excerpts for the same capabilities request, and identify the exact build or commit for each API excerpt.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Warning Review limit reachedThis review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Next included review available in 34 minutes. View limit details
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Reset API contract and recovery guidance contracts/api/v2/openapi.json, contracts/api/v2/fixtures/*, web/src/api/v2/*, docs/notifications-push-api.md, internal/contractledger/ledger_test.go |
The API contracts add reset request and receipt schemas, the reset route, and a capability field. Client API schemas map the route. The guide describes reset outcomes and re-registration behavior. The contract ledger records retry behavior. |
Installation ownership and reset state internal/notifications/apple_push_ordering.go, internal/notifications/push_devices.go, internal/notifications/push_devices_test.go, internal/notifications/push_legacy_ownership_test.go, scripts/ci/db-contracts.txt |
Registration reports a distinct mismatch for the owning account. Reset checks ownership and the submitted key, then clears the binding and Apple push rows when the key differs. The installation remains reserved to its owner. Database tests cover ownership, retries, and ordering. |
Authenticated reset endpoint and wiring internal/apiv2/notification_apple_push.go, internal/apiv2/notification_apple_push_test.go, internal/apiv2/problem.go, internal/apiv2/router.go, internal/api/router.go, internal/api/testdata/media_routes.txt |
The endpoint requires a current login session and an available reset service. It passes the session user, device ID, and installation key to the service. The API maps mismatch errors and reports reset availability. |
Diagnostic-report approval entries contracts/api/v2/breaking-approvals.json |
The approvals for listAdminDiagnosticReports and getAdminDiagnosticReport were removed. The approvals list is now empty. |
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Feature · Severity of issue fixed: Medium
Sequence Diagram(s)
sequenceDiagram
participant iOSClient
participant ApplePushResetEndpoint
participant PushDeviceService
participant PushDeviceRepository
participant Database
iOSClient->>ApplePushResetEndpoint: POST reset with device ID and installation key
ApplePushResetEndpoint->>ApplePushResetEndpoint: Validate current login session
ApplePushResetEndpoint->>PushDeviceService: Reset installation for session user
PushDeviceService->>PushDeviceRepository: ResetApplePushInstallation
PushDeviceRepository->>Database: Lock installation and check owner and key
PushDeviceRepository->>Database: Clear binding and Apple registrations
ApplePushResetEndpoint-->>iOSClient: Return reset result or mapped error
Possibly related issues
- Silo-Server/silo-server#3348 — The change adds an owner-authorized reset and a distinct mismatch response for the reported reinstall registration failure.
Suggested reviewers: quick104
Merge Risk: 
Low · previous review d7712
-
A reset can report success to another account even though subsequent registration is refused. The impact is bounded, but the response should be corrected.
Security architecture risk: 
Moderate · up to d7712
-
Updated servers preserve installation ownership during recovery. However, older server versions do not recognize the new cleared-but-reserved state. During a mixed-version upgrade or rollback, another signed-in account could claim a resetting device and block its owner's recovery. Deployment safeguards preventing that sequence were not established.
Retained concerns
- Medium · security · inferred: The new cleared-but-owned installation state is not protected by base-version writers. If an older API writer remains active after reset, or a cleared reservation survives a downgrade, another authenticated account knowing the device ID can submit an ordered registration with its own key. The older writer sees generation zero and no foreign destination rows, then overwrites the retained owner. Updated writers prevent this, but reset availability is determined locally and the supplied evidence does not establish a deployment barrier preventing the incompatible sequence.
Security review details
-
Security Blast Radius
- inferred — The version-skew attack is scoped to known device IDs left in the reset state and reachable through an older writer sharing their database. It requires another authenticated account but not the victim's installation key. The established outcome is installation-ownership replacement and blocked recovery; victim-notification disclosure was not established.
Security Findings and Attack Paths
- inferred — A successful owner reset removes the destination rows that base writers use to recognize foreign ownership. An attacker registration through an older ordered writer can then pass the generation-zero check and persist the attacker's account and key. Fully upgraded writers reject that same sequence using the retained user_id.
Trust Boundaries and Controls
- observed — The new route derives account identity from authenticated claims, applies profile-scoped gates, and requires a bounded access-token session. Production authentication checks session activity on each request, while reset persistence checks ownership before changing an active binding. Display credentials and session-less API keys cannot authorize reset.
Resilience and Maintainability Implications
- observed — Transactional deletion removes queued attempts, but a worker that already loaded a destination can continue to provider dispatch. This delivery limitation predates reset in the registration replacement path, and the guide explicitly disclaims immediate remote-delivery revocation; it is not retained as a new security concern.
Hardening Proposals
- proposed — Gate reset activation until every writer sharing installation state enforces retained-owner reservations, and define a downgrade barrier while cleared reservations remain. A database-enforced reservation could alternatively make that guarantee independent of application-version agreement.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the change: an iPhone can recover Apple push after a reinstall. The changeset adds a distinct key-mismatch error, an owner-scoped reset operation (POST /api/v2/devices/push/apple/reset), a capability flag, and the supporting storage logic, so the title matches the main change. The title is 64 characters and follows the conventional type(scope) form, which is concise and specific enough for a teammate scanning history.
Full details: Linked Issues check
-
Explanation
Issue
#3348requires recovery for the owning account or an actionable server error. The PR implements both.ApplyApplePushAndFinalizereturnspush_installation_key_mismatchto the owning account when the key differs. Other accounts still receivepermission_denied.POST /api/v2/devices/push/apple/resetrequires a current session, the device ID, and the installation key. The reset clears Apple registration state under the installation lock and retains the owner reservation. The owner can register again. Same-key retries are no-ops. Database tests cover reset, ownership, replay, unknown devices, legacy and ordered registration, and lock ordering. Transport tests cover the problem type, session checks, reset responses, and the capability field. Android changes are not required by#3348.
Full details: Out of Scope Changes check
-
Explanation
The changed API schemas, generated web API definitions, router wiring, route fixtures, capability field, problem type, documentation, service and repository code, and tests support the Apple recovery behavior in
#3348. The removal of two stale API contract approvals is outside the Apple code area, but the PR ties it to the additive OpenAPI contract check triggered by this API change. The repository summary provides no demonstrated unrelated behavior change. Android and Jellyfin-compatible client behavior remains unchanged.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 83.33% which is sufficient. 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 6 functions across 11 files. (1 skipped: 1 unsupported.)
Full details: Description check
-
Explanation
The pull request description directly describes the Apple push installation reset API, ownership behavior, capability changes, documentation updates, tests, and validation results covered by the changeset.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
There was a problem hiding this comment.
Actionable comments posted: 1

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:
84534e2e-9f80-4820-ad7f-4c14a2ddadf2
Files selected for processing: 16-
contracts/api/v2/fixtures/apple_push_registration_capability.jsoncontracts/api/v2/openapi.jsondocs/notifications-push-api.mdinternal/api/router.gointernal/api/testdata/media_routes.txtinternal/apiv2/notification_apple_push.gointernal/apiv2/notification_apple_push_test.gointernal/apiv2/problem.gointernal/apiv2/router.gointernal/contractledger/ledger_test.gointernal/notifications/apple_push_ordering.gointernal/notifications/push_devices_test.gointernal/notifications/push_legacy_ownership_test.goscripts/ci/db-contracts.txtweb/src/api/v2/operations.tsweb/src/api/v2/schema.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.
-
The two approvals added for the roku diagnostics platform (Silo-Server#3298) match no change against main any more, and the v2 contract check refuses stale approvals whenever openapi.json changes.
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:
|
|
The Suggested fix: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…account A reset cleared the installation's owner along with its key and generation, and deleted the device's Apple push rows. Until the owner registered again, any account that knew the device_id could bind the installation through ordered bootstrap or the legacy writer, and the owner could then neither register nor reset. The reset now keeps the installation's account. Ordered bootstrap and the legacy Apple writer refuse another account while that reservation holds. The owner still registers with any key at any positive generation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Quick104
left a comment
There was a problem hiding this comment.
Review of 31e1688: one verified defect and one docs gap. I'm fixing both in a commit on this branch, so there's no need to change them yourself. A summary with scores follows as a separate comment.
🤖 Claude Code (claude-opus-5-5)
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:
|
Review summaryReviewed head: 31e1688, base 63ef34b. The fix is d7712a7, pushed as an ordinary commit on this branch. Main has moved to 81ae2ce, and the branch still merges cleanly. Fit: 8/10 · Readiness: 8/10 — conditional (assuming CI is green)
Fixed on this branch
Left for the maintainers
Checks
🤖 Claude Code (claude-opus-5-5) |
| if _, err = tx.Exec(ctx, `DELETE FROM push_devices WHERE device_id=$1 AND platform=$2`, cmd.DeviceID, PushPlatformApple); err != nil { | ||
| return false, err | ||
| } | ||
| if _, err = tx.Exec(ctx, `UPDATE apple_push_installations SET installation_key_hash='',generation=0,profile_id='',intent_hash='',registration_id='',server_device_id='',push_mode='' WHERE device_id=$1`, cmd.DeviceID); err != nil { |
There was a problem hiding this comment.
Ownership-check bypass in internal/notifications/apple_push_ordering.go occurs because retaining user_id on reset creates a foreign-owned generation-zero state, and ResetApplePushInstallation returns a successful no-op for generation == 0 before checking ownership, giving a different account 200 {"reset":false} instead of the documented 403. Check a nonzero stored owner before returning for generation zero, while preserving the no-op for unowned installations.
Prompt for LLM
File internal/notifications/apple_push_ordering.go:
Line 362:
Ownership-check bypass in internal/notifications/apple_push_ordering.go occurs because retaining user_id on reset creates a foreign-owned generation-zero state, and ResetApplePushInstallation returns a successful no-op for generation == 0 before checking ownership, giving a different account 200 {"reset":false} instead of the documented 403. Check a nonzero stored owner before returning for generation zero, while preserving the no-op for unowned installations.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
Confirmed on d7712a7: the reset returned before the ownership check for a reserved generation-zero installation. I added assertions to the existing database test for a foreign-account reset and the owner's idempotent retry. The foreign-account assertion fails on that head. I am moving the ownership check ahead of the generation-zero return; an unowned placeholder still returns a no-op. — Codex in T3 Code, gpt-6-astra
There was a problem hiding this comment.
That addresses the reported bypass. The ordering should be:
- Acquire the installation lock and handle any error.
- Read the stored owner and reject a nonzero owner different from the caller, even when generation is zero.
- Return a no-op for generation zero, preserving the behavior for an unowned placeholder and the owner’s retry.
- Continue with the existing same-key check and reset logic.
The added assertions target the regression: a foreign-account reset must remain 403 permission_denied after the owner resets, while the owner’s repeated reset returns {"reset":false}. The failing assertion on d7712a7 confirms the original finding; passing it after the change would verify this case.
There was a problem hiding this comment.
Fixed in 494100c. Reset now checks the stored owner before returning for a reserved generation-zero installation; an unowned generation-zero placeholder remains a no-op. The added foreign-account assertion fails on d7712a7 and passes with this fix. Owner retry, unknown-installation reset, Apple upsert, and Apple retirement checks pass against disposable Postgres, and make lint-changed reports 0 issues. — Codex in T3 Code, gpt-6-astra
There was a problem hiding this comment.
Based on the reported change and test results, 494100c addresses this finding: ownership is checked before the generation-zero no-op, so a foreign account is still rejected after the owner resets, while owner retries and unowned placeholders remain no-ops.
The regression assertion failing on d7712a7 and passing with the fix directly covers the reported bypass. No further change is needed for this finding based on that evidence.
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:
|
|
CodeRabbit follow-up on the summary covering d7712a7: The foreign-account reset response is fixed in 494100c. Kody confirmed that fix, and the regression assertion fails before it and passes afterwards. The older-writer concern is valid by source inspection: the earlier generation-zero path checks destination rows and can overwrite a retained owner after reset deletes those rows. The current writers reject this. I have not run a mixed-version deployment test. 774ea3b documents the compatibility requirement in This follow-up changes documentation only. — Codex in T3 Code, gpt-6-astra |
|
The Go test failure on 774ea3b is the existing playback cleanup race tracked in #3361: The same failure was reproduced on the unmodified CI base during this review batch. The single retry also failed only on that same test: https://github.com/Silo-Server/silo-server/actions/runs/41359012025/job/125007720831. The aggregate CI result only propagated the Go failure. Required CI remains red; no further retry was requested. — Codex in T3 Code, gpt-6-astra |
Problem
Closes #3348
Related issue: N/A
Validation tasks: unblocks #1234 C2; unblocks Silo-Server/silo-apple#336 C1 and C2 (not run yet)
In the reported case, the reinstalled iOS app kept its device ID but sent a new push installation key. The server binds each Apple installation to the key from its first registration, so every later registration fails with
403 permission_denied. Nothing on the server cleared that binding, and the contract said there was no recovery, so push stayed broken until someone deleted the rows by hand.This change tells the owning account why it was refused and gives it a way to clear its own installation. Another account is still refused, and its refusal does not change.
Approach
403with the problem typepush_installation_key_mismatch, but only when the caller's account owns the installation. Another account still getspermission_denied, so the new code says nothing about who owns a device ID. The status and the refusal are the same as before, so current apps behave as they do today.POST /api/v2/devices/push/apple/reset(resetApplePushInstallation). It needs a current login session of the owning account and the app's current installation key. Under the existing installation lock, it deletes the device's Apple push rows (their queued attempts cascade) and clears the stored key and generation. The installation keeps its account, so until the owner registers again, another account's ordered or legacy registration for that device ID is still refused. The owner's next registration then binds the new key at any generation. It answers{"reset": true}when it cleared something,{"reset": false}when there was nothing to clear or the installation is already bound to the sent key, and403 permission_deniedfor another account's installation. Because of the same-key no-op, a retried reset cannot undo the registration that followed it.getApplePushRegistrationCapabilitiesgainsinstallation_reset_available. All changes are additive to/api/v2, and no migration is needed: ownership comes from theuser_idthe installation row already stores.docs/notifications-push-api.mddocuments the recovery flow and replaces the "no recovery" sentence for Apple. Android installations are unchanged and still have no recovery path.push_installation_key_mismatchand the capability reportsinstallation_reset_available. It also confirms how the reported case happens: the app keys its installation record by server address but shares the device ID across servers, so re-adding a server under another address creates a new key for the same device ID. jellycompat has no Apple push registration, so it needs no change.Validation
Follow-up 494100c: repeated resets check ownership while the installation is at generation zero. The existing database test now covers a foreign account and an owner retry; the foreign-account assertion fails on d7712a7 and passes with the fix. Focused reset, upsert, and retirement database tests pass; changed-line lint reports 0 issues.
Reproduced on
origin/mainagainst a local build with a real login: samedevice_id, new key, generation 1 and then 2, both refused withpermission_denied.On the fix build, the same steps on the same kind of data: the owner gets
push_installation_key_mismatch; reset, then registration with the new key at generation 1, returns 200; a retried reset returns{"reset": false}and leaves the new registration in place; a second account is refused for registration and reset (403permission_denied); the original key still works before the reset.New database tests cover owner reset and re-registration, refusal for another account (also between the reset and the owner's next registration, through the ordered and legacy writers), the replayed reset, an unknown device, and a registration queued behind a reset. A transport test covers the new problem code, the reset route's session requirement and the capability field. Both database tests are listed in
scripts/ci/db-contracts.txtand pass through the dbpins runner.Go gate: build, gofmt, vet,
make lint-changed, router-recovery lint, route inventory, migration ledger, scenario catalogs, offline routes, OpenAPI, web types, fixtures, local paths, case collisions, size ratchet, bidi, migrations and v1 route freeze all pass.make test-gopasses except two jellycompat Dolby Vision tests (TestPlaybackInfoWithoutStripOrToneMapStillHasNoRoute,TestPlaybackInfoSkipsStripWhenRPUCannotBeStripped), which fail the same way on the base commit.make verify-apiv2-contractreports both changes as additive. It also refused two stale approvals from feat(diagnostics): accept the roku platform #3298 that match no change againstmain(the check runs only whenopenapi.jsonchanges), so this pull request removes them.Web: the regenerated API types pass typecheck, ESLint and Prettier. No web code changed.
Evidence
Evidence: none, no user-visible change
API before and after, same steps (registration with a new key from the owning account, then a second account):
Before:
mainat 63ef34b. After: this branch at 04c5169 (later commits only change the contract approvals file and docs).Risks
Checklist
AI Disclosure
Note
Add owner-only Apple push installation reset endpoint
...
Macroscope summarized 774ea3b.