You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(auth): keep legacy custom headers when their Keychain migration fails - #1791
Upgrading from a build that kept custom headers in one global Keychain entry could lose them: the migration to the per-server entry deleted the global copy even when the per-server save failed, so the next launch had no headers and a proxy that needs them refused the app.
AuthManager.hydrateCustomHeaders(for:) now deletes the legacy entry only after the scoped save succeeds. The headers are still applied for this launch either way, and a failed migration retries on the next one. ADR 0148 and the multi-server isolation doc's test list are updated to match.
How it was tested
New CustomHeaderAuthManagerTests.testLaunchKeepsLegacyGlobalHeadersWhenTheirMigrationFails uses the existing FailingKeychain double. It failed on the base (legacy entry was nil) and passes with the fix. The existing testLaunchMigratesLegacyGlobalHeadersToActiveServerScope still covers a successful migration removing the legacy entry.
Review follow-up: persistCustomHeaders(for:) drops the legacy entry on any header write, so a copy a failed migration left can't reach a server added later or bring back cleared headers. testAHeaderWriteRetiresLegacyHeadersAFailedMigrationLeft failed without it; CustomHeaderAuthManagerTests, CustomHeaderAPIClientInjectionTests and OnboardingViewModelIdentityTests then passed, 40 of 40.
Checklist
Local validation passes using scripts/test-sim <assigned-simulator-udid> with the tests required by AGENTS.md § Verifying; the selection and results are recorded above
New/changed Codable models decode tolerantly (optionals for fields the server might add or rename)
No new third-party dependencies (the list in AGENTS.md is locked)
No invented API endpoints or JSON shapes (verified against upstream source or a running server)
Reviewed with sol-loop: 1 round with gpt-6.2-sol on high. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code).
Reviewing files that changed from the base of the PR and between c68d54b and 497cc1a.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Walkthrough
Custom-header migration now retains the legacy Keychain value when saving the server-scoped value fails. The headers still apply for that launch. A later header update removes any remaining legacy value.
Changes: Custom-header migration
Layer / File(s)
Summary
Migration behavior and coverage HermesMobile/Auth/AuthManager.swift, HermesMobileTests/CustomHeaderInjectionTests.swift, docs/adr/0148-server-custom-headers.md, docs/agents/multi-server-state-isolation.md
AuthManager deletes the legacy key only after a successful server-scoped save. Header updates also remove the legacy key. Tests cover failed migration and removal after a later update. The ADR and test list document the failure case.
Custom headers can still be lost in a narrow failure case: a second failed Keychain write after a failed migration deletes the only saved copy. The retained legacy headers can also still be applied to another non-Hermes server that has no scoped entry. Both cases need a Keychain failure, so they are uncommon. They should be fixed or explicitly accepted before merging.
Security architecture risk: Moderate · up to e03e1
Preserving headers after a failed migration fixes data loss, but the retained copy is not bound to its original server. On devices with multiple saved servers, switching to another server without scoped headers can send it the original server’s credentials. Successful migration and cleanup during server addition limit this exposure but do not protect a plain switch between existing servers.
Retained concerns
Medium · security · inferred: Retained legacy credentials can cross server boundaries. If migration for server A fails and another saved webui server B has no scoped headers, switching to B loads A’s retained global headers into the active store. Initial API requests to B then carry those headers, including applicable Authorization values. If B’s migration save succeeds, A’s headers also become persistent under B’s scope. Unlike adding a new server, switching to an existing server performs no intervening persist-side cleanup.
Security review details
Security Blast Radius
inferred — The directly exposed material is one installation’s retained legacy header set, potentially including authentication credentials. Recipient scope is other selected webui destinations without usable scoped headers while the global copy remains. A successful migration into the wrong destination makes the misbinding persistent. Any resulting authority depends on the credentials in that blob; access to the whole Keychain or unrelated installations is not established.
Security Findings and Attack Paths
inferred — A party controlling an already saved webui endpoint B could receive server A’s legacy authentication headers after A’s migration save fails and the user switches to B before cleanup. B needs no authority over A’s credentials: hydration selects the unowned global fallback, and the initial request sends it. This is a source-derived path, not a reproduced exploit, and requires coexistence of legacy data and multiple saved servers.
Trust Boundaries and Controls
observed — Successful migration removes the legacy key, an existing scoped value takes precedence, and activating Hermes clears webui headers. Adding a webui server invokes persist-side global cleanup, limiting exposure to newly added destinations when deletion succeeds. A plain switch does not invoke that cleanup. Header syntax validation and cross-origin redirect stripping do not bind the initial request’s headers to their original server.
Resilience and Maintainability Implications
observed — The added regression tests cover immediate retention after a failed migration and retirement after clearing headers. Their fake fails saves but passes loads and deletions through. Those tests do not establish cross-server isolation during the retained state or recovery after deletion failure.
Hardening Proposals
proposed — Associate retained legacy headers with their original migration owner and enforce that association in both AuthManager and ProfileEntityProvider. Preserve explicit user-clearing semantics while preventing another server’s hydration from consuming or adopting the retained credentials.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: legacy custom headers are kept when their Keychain migration fails. The raw summary and PR objectives both describe this behavior, which is the core of the fix. The ti…
Linked Issues check
Stack objective [#1785]: Addressed by this PR alone. Coding requirements: (1) A failed scoped save must leave the legacy entry intact and still apply the headers for this launch. (2) A successful migr…
Out of Scope Changes check
The attested summaries list four changed paths. AuthManager.swift changes the legacy delete to run after the scoped save, and also makes persistCustomHeaders(for:) delete the unscoped key after a wr…
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check
Explanation
The title names the main change: legacy custom headers are kept when their Keychain migration fails. The raw summary and PR objectives both describe this behavior, which is the core of the fix. The title is 73 characters and uses a conventional fix(auth) prefix. The commit message adds a rule about dropping the legacy entry on any header write. The title does not cover that detail, which is acceptable because the title need not cover every detail.
Full details: Linked Issues check
Explanation
Stack objective [#1785]: Addressed by this PR alone. Coding requirements: (1) A failed scoped save must leave the legacy entry intact and still apply the headers for this launch. (2) A successful migration must remove the legacy entry. The attested summary of HermesMobile/Auth/AuthManager.swift says hydrateCustomHeaders(for:) deletes the legacy value only after the scoped save succeeds, and still uses the legacy value to populate the header store when the save fails. This matches the requirement. The attested summary of HermesMobileTests/CustomHeaderInjectionTests.swift describes a failed-migration test that checks the headers load and the legacy value remains. Criterion (2) is covered by the existing testLaunchMigratesLegacyGlobalHeadersToActiveServerScope, per the PR description. The author reports the new test failed on base and passes with the change. Limitations: the diff for AuthManager.swift could not be read (changed blobs missing from checkout), so this verdict relies on attested summaries, the PR description, and the author's test report. Stack review evidence was unavailable. No other stack member is needed for this objective, so the stack status does not change the result.
Full details: Out of Scope Changes check
Explanation
The attested summaries list four changed paths. AuthManager.swift changes the legacy delete to run after the scoped save, and also makes persistCustomHeaders(for:) delete the unscoped key after a write. CustomHeaderInjectionTests.swift generalizes the helper to KeychainStoring and adds failed-migration tests. ADR 0148 and docs/agents/multi-server-state-isolation.md are documentation updates for the same behavior. The persistCustomHeaders change is the only change not named in the PR description. It is connected to the fix: once a failed migration keeps the legacy entry, a later header write must remove it. Otherwise the legacy headers could return after the user changes or clears headers. The commit message and ADR describe this rule. No unrelated code change appears in the evidence. Limitations: the full diff could not be read, so this relies on attested summaries. The PR description should state the persistCustomHeaders rule explicitly, but this is a documentation gap, not a scope failure.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
[Medium impact] The PR appears safe to merge with no new actionable findings.
Summary
Keeps legacy custom headers when their per-server migration fails.
Legacy headers stay available when their server save fails.
Previous review follow-up:
The earlier cross-server finding is not reposted. Header writes now remove the leftover global copy.
uzairansaruzi explicitly accepted losing the legacy copy when a later user save also fails, to prevent another server from inheriting credentials. Greptile withdrew that finding.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Files skipped from review as they are similar to previous changes: 1
docs/adr/0148-server-custom-headers.md
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…ails
Delete the pre-#16 global custom-header entry only after the per-server
save succeeds, so a failed migration keeps the only copy and retries on
the next launch.
Fixes#1785
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A copy a failed migration left would otherwise be read for a server added
later, or bring back headers the user cleared.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Fixes #1785
What changed
Upgrading from a build that kept custom headers in one global Keychain entry could lose them: the migration to the per-server entry deleted the global copy even when the per-server save failed, so the next launch had no headers and a proxy that needs them refused the app.
AuthManager.hydrateCustomHeaders(for:)now deletes the legacy entry only after the scoped save succeeds. The headers are still applied for this launch either way, and a failed migration retries on the next one. ADR 0148 and the multi-server isolation doc's test list are updated to match.How it was tested
CustomHeaderAuthManagerTests.testLaunchKeepsLegacyGlobalHeadersWhenTheirMigrationFailsuses the existingFailingKeychaindouble. It failed on the base (legacy entry wasnil) and passes with the fix. The existingtestLaunchMigratesLegacyGlobalHeadersToActiveServerScopestill covers a successful migration removing the legacy entry.scripts/test-sim <udid> --only HermesMobileTests/CustomHeaderAuthManagerTests: 10 passed, 0 failed.python3 ci/check_comments.py,python3 ci/check_test_waits.py,python3 -m unittest discover -s ci -p 'test_*.py': pass.persistCustomHeaders(for:)drops the legacy entry on any header write, so a copy a failed migration left can't reach a server added later or bring back cleared headers.testAHeaderWriteRetiresLegacyHeadersAFailedMigrationLeftfailed without it;CustomHeaderAuthManagerTests,CustomHeaderAPIClientInjectionTestsandOnboardingViewModelIdentityTeststhen passed, 40 of 40.Checklist
scripts/test-sim <assigned-simulator-udid>with the tests required byAGENTS.md§ Verifying; the selection and results are recorded aboveCodablemodels decode tolerantly (optionals for fields the server might add or rename)AGENTS.mdis locked)Reviewed with sol-loop: 1 round with gpt-6.2-sol on high. Sol verdict: approved
Created with Claude Opus 5.5 in Claude Code (T3 Code).
🤖 Generated with Claude Code