Skip to content

fix(networking): never carry a webui request's custom headers to another origin - #1787

Merged
uzairansaruzi merged 2 commits into
masterfrom
issue/1781-strip-sent-redirect-headers
Nov 20, 2026
Merged

uzairansaruzi merged 2 commits into
masterfrom
issue/1781-strip-sent-redirect-headers

Conversation

@uzairansaruzi

@uzairansaruzi uzairansaruzi commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Linked issue

Fixes #1781

What changed

A webui request in flight when the user signed out, switched server, or edited a header could carry its custom headers (often a proxy secret) to another origin. The redirect guard looked up the header names to strip when the redirect arrived, and by then the store held another server's headers or none.

Each request now snapshots its headers once, applies them, and gets a redirect guard built from exactly those headers (CrossOriginHeaderStripper(baseURL:sentHeaders:)). Same-origin redirects keep their headers, and a cross-origin redirect of anything but GET or HEAD is still refused. HermesConnection already built its guard from the headers it admitted, and it now uses the same initializer. ADR 0095 now records the rule.

How it was tested

  • testStripsSentHeaderOnRedirectAfterTheStoreIsReplaced replaces the header store before the mock redirects to another host. It failed on the base (X-Api-Key: k1 reached the new origin) and passes with the fix.
  • scripts/test-sim <udid> --only on CrossOriginRedirectHeaderTests, CustomHeaderAPIClientInjectionTests, CustomHeaderModelTests, CustomHeaderSSEInjectionTests, CustomHeaderAuthManagerTests, HermesConnectionTests: all pass.
  • python3 ci/check_comments.py, python3 ci/check_test_waits.py, python3 -m unittest discover -s ci -p 'test_*.py': pass.

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

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

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

No actionable comments were generated in the recent review.

Walkthrough

APIClient now creates a redirect guard for each request from the headers applied to that request. Cross-origin redirect filtering uses those captured header names. The tests cover replacement of custom-header configuration before a redirect.

Changes: Request-scoped redirect header filtering

Layer / File(s) Summary
Capture admitted header names
HermesMobile/Networking/APIClient.swift, HermesMobile/Networking/Hermes/HermesConnection.swift
CrossOriginHeaderStripper stores sanitized names from supplied headers. HermesConnection passes its admitted headers directly to the stripper.
Wire request-scoped guards and validate redirects
HermesMobile/Networking/APIClient.swift, HermesMobileTests/CustomHeaderInjectionTests.swift, docs/adr/0095-api-client-custom-headers.md
APIClient creates guards from headers applied to each request. Cross-origin downloads use no custom headers and an empty-header guard. The redirect test replaces the custom-header store before redirection, and the ADR describes the request-scoped rule.

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

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: audichuang

Merge Risk: Minimal · previous review 0e004

This change makes webui requests strip the custom headers they were actually sent with when redirected to another origin, even if the header configuration changed in between. A regression test covers the scenario, and no merge-blocking risk was identified.

Security architecture risk: Minimal · up to 0e004

The change closes a window in which an in-flight request could forward custom credentials after the user changed servers, signed out, or edited headers. The inspected request paths consistently attach their captured redirect guard, and existing origin and method restrictions remain intact. No introduced or worsened architecture risk was established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The protected assets are custom credentials attached to individual in-flight requests, including reverse-proxy secrets. Consequences of disclosure would depend on those credentials’ downstream authority; the inspected evidence does not establish a tenant-wide or service-wide privilege scope.

Security Findings and Attack Paths

  • inferred — The addressed pre-existing attack path requires a header-bearing request, configuration replacement before its redirect is processed, and a redirect to another origin. Reading the replacement configuration could miss the original secret’s name. Capturing names before sending removes that dependency in the inspected APIClient paths; no introduced or worsened attack path was established.

Trust Boundaries and Controls

  • observed — Hermes preserves its existing admitted-header boundary: configured headers are validated, application is restricted to the connection origin, and redirect stripping includes the Hermes session-token name. The bot-status probe applies headers and constructs its guard from the same HermesHeaders value.

Resilience and Maintainability Implications

  • observed — The default header store snapshots and replaces values under a lock, while each request’s redirect policy remains immutable after capture. The regression test replaces the store immediately before a mocked cross-origin redirect and asserts that the second hop lacks the original API key; its execution was not independently verified.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: webui requests' custom headers are no longer carried to another origin on redirect. The raw summary shows the stripper now uses the headers sent with each request, whi…
Linked Issues check Passed Issue #1781 requires that a webui request strip the header names it was sent with when redirected cross-origin, even after the store is replaced or a header is removed. At the reviewed head, `APIClien…
Out of Scope Changes check Passed All reported changes map to #1781. The APIClient.swift change moves the guard from a stored redirectHeaderStripper to a per-request guard built from the applied headers. This also applies to the b…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: webui requests' custom headers are no longer carried to another origin on redirect. The raw summary shows the stripper now uses the headers sent with each request, which matches the title's intent. The title is specific and accurate, so it passes.

Full details: Linked Issues check

Explanation

Issue #1781 requires that a webui request strip the header names it was sent with when redirected cross-origin, even after the store is replaced or a header is removed. At the reviewed head, APIClient.applyCustomHeaders(to:) reads customHeaderProvider() once, applies those headers, and returns CrossOriginHeaderStripper(baseURL:sentHeaders:). The stripper stores sentHeaderNames at construction, so later store changes do not affect it. Its willPerformHTTPRedirection logic keeps headers on same-origin redirects, refuses cross-origin redirects for methods other than GET or HEAD (completionHandler(nil)), and removes the sent header names from cross-origin GET/HEAD redirects. This covers the 307/308-with-body refusal in the acceptance criteria. HermesConnection (HermesHeaders.redirectGuard(for:)) now uses the same initializer with its admitted headers. The test testStripsSentHeaderOnRedirectAfterTheStoreIsReplaced and the RedirectingMockURLProtocol.beforeRedirect hook cover the store-replacement case. ADR 0095 is updated per the summary. Limit: the whole-PR diff could not be read (changed blobs unavailable), so the base failure of the new test rests on the author's report. The head code does establish the required behavior.

Full details: Out of Scope Changes check

Explanation

All reported changes map to #1781. The APIClient.swift change moves the guard from a stored redirectHeaderStripper to a per-request guard built from the applied headers. This also applies to the bounded-download, multipart, and download paths, which all build their guard the same way. The HermesConnection.swift change is a one-line switch to the same initializer, which the issue names as the reference behavior. The CustomHeaderInjectionTests.swift changes add a redirect hook and update the redirect test to the new initializer, which supports the fix. The ADR change is required by the issue's acceptance criteria. No unrelated behavior change was identified in the reviewed sources. Limit: the full PR diff was unavailable, so this relies on the summary and the head file.

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b1f53de and 0e00419.

Files selected for processing: 4

  • HermesMobile/Networking/APIClient.swift
  • HermesMobile/Networking/Hermes/HermesConnection.swift
  • HermesMobileTests/CustomHeaderInjectionTests.swift
  • docs/adr/0095-api-client-custom-headers.md

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

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no actionable new defects were found.

Summary

Each request now captures its custom headers once and uses that snapshot when following redirects.

  • Each request strips the custom headers it sent when it redirects off-origin.
  • CI checks that Swift files do not gain comments, while architecture records hold durable decisions.

The six comment-checker tests, comment baseline check, and test-wait check passed. iOS tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Build request] --> B[Capture custom headers]
  B --> C[Apply headers and build guard]
  C --> D[Send request]
  D --> E{Redirect destination}
  E -->|Same origin| F[Keep headers]
  E -->|Another origin| G{GET or HEAD?}
  G -->|Yes| H[Remove captured header names]
  G -->|No| I[Refuse redirect]
Loading

Reviews (2) · Last reviewed commit: "fix(networking): strip the headers a web..." · Reviewed by Greptile

uzairansaruzi and others added 2 commits November 20, 2026 13:37
…1789)

## Linked issue

No issue: a maintainer-requested chore.

## What changed

About 10% of our Swift was comments (28,500 of them, 29,000 lines). Most
restated the code, a few gave cover to shortcuts, and the ones that
recorded a real decision were scattered where nobody looks for
decisions. This PR deletes them and bans new ones.

- **Every comment was classified** as a tautology, stale, an excuse, or
a decision record. The decision records are now 180 ADRs holding 979
decisions under `docs/adr/` (format in `docs/adr/README.md`). The
excuses became #1781, #1782, #1783, #1784 and #1785.
- **The comments are gone**: 29,032 lines across 665 Swift files. Two
third-party licence notices stay (`ReviewDiffCanvasView.swift`,
`BotProfileAppearance.swift`) because no file in `ThirdPartyNotices/`
covers them yet, and so do the `// test-wait:` annotations
`ci/check_test_waits.py` reads.
- **`ci/check_comments.py` fails a Swift file that gains a comment.** It
runs in Tooling Tests. `ci/comment_baseline.txt` lists the two files
that still hold comments; a count there only goes down, and a pull
request cannot raise it past the target branch's.
- **The `delete-comment` skill** (`.agents/skills/delete-comment`,
linked from `.claude/skills`) repeats the sweep for whatever is left.
`.gitignore` now tracks repo skills.
- **`AGENTS.md`** states the rule in Taste and points decisions at
`docs/adr/`.

Nothing but comments and the blank lines around them changes in Swift.

## How it was tested

- **Only comments changed.** An oracle built on the toolchain's
SwiftParser compared the token stream of all 701 Swift files with
`master`'s: none differ. The only comment trivia it finds at this head
are the 26 licence lines and 15 `// test-wait:` lines.
- **The checker finds what Swift finds.** Its scanner and SwiftParser
agree on every one of the 28,507 comments in the 701 files at the base.
- `python3 -m unittest discover -s ci -p 'test_*.py'`: 21 passed.
`python3 ci/check_comments.py` and `python3 ci/check_test_waits.py`
pass.
- `scripts/test-sim` on iPhone 17e, after the rebase onto current
`master`: 246 passed, 0 failed. The selection is the classes that read
source-relative fixtures or had a `test-wait` annotation rewritten, plus
the files `master` changed under the rebase: `HermesSlashCommandTests`,
`HermesInsightsClientTests`, `HermesChatSettingsTests`,
`LocalizationCatalogTests`, `HermesAgentFixtureTests`, `SSEClientTests`,
`KanbanLiveUpdateTests`, `CronManagementModelTests`,
`CronManagementViewModelTests`, `HermesCronClientTests`,
`HermesConversationTests`, `HermesBranchDuplicateTests`,
`ToolCallSummaryFormatterTests`. The full suite is left to this PR's CI.

## Checklist

- [x] 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
- [x] New/changed `Codable` models decode tolerantly (none changed)
- [x] No new third-party dependencies (the list in `AGENTS.md` is
locked)
- [x] No invented API endpoints or JSON shapes (none touched)

Reviewed with sol-loop: 3 rounds with gpt-6.2-sol on high. Sol verdict:
changes requested in round 3 (a regex literal after a comment, stray
`test-wait` annotations, paths outside the checkout); all fixed in the
last commit, which Sol has not re-reviewed.

Created with Claude Fable 5.2 in Claude Code (T3 Code). Classification
and ADR drafting by Claude Opus 5.5 subagents.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
…ross-origin redirects

Fixes #1781

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uzairansaruzi
uzairansaruzi changed the base branch from chore/ban-comments to master November 20, 2026 18:38
@uzairansaruzi
uzairansaruzi force-pushed the issue/1781-strip-sent-redirect-headers branch from 0e00419 to a5a813a Compare November 20, 2026 18:38
@uzairansaruzi
uzairansaruzi merged commit 5667e37 into master Nov 20, 2026
6 of 10 checks passed
@uzairansaruzi
uzairansaruzi deleted the issue/1781-strip-sent-redirect-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(networking): strip the headers a webui request was sent with on cross-origin redirects

1 participant