Skip to content

fix(auth): keep legacy custom headers when their Keychain migration fails - #1791

Merged
uzairansaruzi merged 2 commits into
masterfrom
issue/1785-keep-legacy-headers
Nov 20, 2026
Merged

uzairansaruzi merged 2 commits into
masterfrom
issue/1785-keep-legacy-headers

Conversation

@uzairansaruzi

@uzairansaruzi uzairansaruzi commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

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

  • 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.
  • 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.
  • 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).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration

Commits

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: audichuang

Merge Risk: Moderate · previous review e03e1

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[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.

Reviews (4) · Last reviewed commit: "fix(auth): drop the legacy header entry ..." · Reviewed by Greptile

Comment thread HermesMobile/Auth/AuthManager.swift Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 93fd25d and d7858d1.

Files selected for processing: 4

  • HermesMobile/Auth/AuthManager.swift
  • HermesMobileTests/CustomHeaderInjectionTests.swift
  • docs/adr/0148-server-custom-headers.md
  • docs/agents/multi-server-state-isolation.md

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

Comment thread HermesMobile/Auth/AuthManager.swift Resolved
Comment thread HermesMobile/Auth/AuthManager.swift Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d7858d1 and e03e147.

Files selected for processing: 3

  • HermesMobile/Auth/AuthManager.swift
  • HermesMobileTests/CustomHeaderInjectionTests.swift
  • docs/adr/0148-server-custom-headers.md
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.

Comment thread HermesMobile/Auth/AuthManager.swift Resolved
@uzairansaruzi
uzairansaruzi changed the base branch from chore/ban-comments to master November 20, 2026 18:38
@uzairansaruzi
uzairansaruzi force-pushed the issue/1785-keep-legacy-headers branch from e03e147 to c68d54b Compare November 20, 2026 18:38
uzairansaruzi and others added 2 commits November 20, 2026 14:04
…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>
@uzairansaruzi
uzairansaruzi force-pushed the issue/1785-keep-legacy-headers branch from c68d54b to 497cc1a Compare November 20, 2026 19:05
@uzairansaruzi
uzairansaruzi merged commit d35a0fc into master Nov 20, 2026
6 checks passed
@uzairansaruzi
uzairansaruzi deleted the issue/1785-keep-legacy-headers branch November 20, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(auth): keep legacy custom headers when their Keychain migration fails

1 participant