Skip to content

fix(bots): stop the tool relay forwarding Sec-Fetch-* headers upstream - #51894

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51748
Nov 28, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51748

Conversation

@nwparker

@nwparker nwparker commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca's bots reach their MCP tools (like Notion) through a small local relay inside Orca. Pi talks to that relay with Node's fetch, which adds a few browser-style "where is this request coming from" headers. The relay was passing those headers on to the real tool server. Electron's own fetch refuses to send one of them (Sec-Fetch-Mode: cors) without an Origin, so the request failed before it left Orca and Pi ended up with no tools. The relay now drops those headers.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

What Changed

  • Before: the relay copied Sec-Fetch-Mode, Sec-Fetch-Site and Sec-Fetch-Dest from the agent's request onto its upstream request. When Pi (Node/undici fetch) called a relayed MCP server, Electron's net-backed fetch threw net::ERR_INVALID_ARGUMENT, the MCP handshake never reached the server, and Pi registered 0 tools. Codex and Antigravity don't send these headers, so they kept working.
  • After: sendUpstream (src/main/bots/tool-relay/bot-tool-relay-upstream.ts) skips any sec-fetch-* header name when it builds the upstream headers. It already skips proxy-*, hop-by-hop headers and the relay credentials the same way. All other agent headers are still forwarded, including user-agent, accept-language, mcp-* and Referer.

Why

Sec-Fetch-* is browser fetch metadata describing the agent-to-relay hop. It means nothing for the relay-to-server hop, and Electron's network stack sets its own values anyway. Dropping the whole sec-fetch- prefix is simpler than keeping a list of single headers, and it follows the existing proxy- prefix rule. An Origin filter is not needed because the relay already refuses any request that carries Origin (its browser-page check in bot-tool-relay.ts).

This is a partial fix for the issue: it removes the transport failure we reproduced. Surfacing Pi's startup MCP warning in chat (#45081) and any Pi-side behavior are out of scope.

Linked Issue

Refs #51748

Visual Proof

N/A. This is a main-process header change with no UI. Evidence comes from an Electron 45.4.1 main-process probe run in the background on a remote Mac (no window). It sends the same request through session.defaultSession.fetch to a loopback server:

Headers sent Result
Pi's headers as forwarded on main (sec-fetch-mode: cors, no origin) THREW Error: net::ERR_INVALID_ARGUMENT
Pi's headers as forwarded on this branch (no sec-fetch-*) 200
sec-fetch-mode: cors + origin THREW Error: net::ERR_FAILED
sec-fetch-dest: empty only 200
sec-fetch-mode: no-cors 200

Testing

  • Added a relay test in src/main/bots/tool-relay/bot-tool-relay.test.ts. It sends Pi-style headers (user-agent: node, accept-language: *, sec-fetch-mode/site/dest) and checks that the upstream request has everything except sec-fetch-* and the relay token, plus the saved credential header.

  • The new test fails on main's bot-tool-relay-upstream.ts (1 failed / 12 passed) and passes with this change (13/13): pnpm exec vitest run src/main/bots/tool-relay/.

  • Ran the Electron probe above (macOS, Electron 45.4.1). Windows uses the same Chromium net stack.

  • Static gates on the touched files are clean: oxlint anti-slop and code-quality configs, ast-grep, the changed-code quality gate, and oxfmt.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Every added test fails without this change and avoids the test anti-patterns

Performance

None, because the change adds one startsWith check per request header, and only for relayed MCP requests, which are bound by network round trips. Microbenchmark of the header loop: about 70 to 145 ns per request with typical headers (14) and about 1.5 to 1.8 µs with 214 headers, old vs new. That is far below a millisecond, with no new I/O, polling, subprocesses or renderer work.

Risk

Level: Low

A tool server that needed the agent's Sec-Fetch-* values would stop getting them. That is unlikely: these headers describe browser context, and Electron sends its own. To back out, revert this commit.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

The relay runs in the desktop main process on every platform, so the change is the same everywhere. There is no protocol or saved-data change, so mixed versions and remote hosts are unaffected.

Reported by ayisuplus in #51748.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Agents that call the relay with Node's fetch (Pi via undici) send
Sec-Fetch-Mode: cors, Sec-Fetch-Site and Sec-Fetch-Dest. The relay copied
them onto its own upstream request, and Electron's net-backed fetch fails a
request that carries Sec-Fetch-Mode: cors without an Origin, so the MCP
handshake never reached the tool's server and the agent registered no tools.

Skip sec-fetch-* names when building the upstream headers. Origin is already
refused by the relay's browser-page check, and Referer is kept.

Refs #51748
@coderabbitai

coderabbitai Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The upstream relay no longer forwards request headers whose names start with sec-fetch-. A new test checks that these headers are omitted, selected other headers are forwarded, and the response status is 200.

Merge Risk: Minimal · up to 956de

The relay stops forwarding browser fetch-metadata headers, so tool-server connections no longer fail in Electron. Other headers are forwarded as before. The change is small and easy to revert, and no merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the tool relay no longer forwards Sec-Fetch-* headers upstream. It matches the raw summary, which says sendUpstream skips sec-fetch-* headers, and the description, whi…
Description check Passed The description follows the template closely. It covers ELI5, What Changed (before and after with the mechanism), Why (including alternatives such as the Origin filter), Linked Issue (Refs #51748), Vi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the tool relay no longer forwards Sec-Fetch-* headers upstream. It matches the raw summary, which says sendUpstream skips sec-fetch-* headers, and the description, which covers the same fix. The title uses the conventional fix(scope) form and is specific enough for a reviewer scanning history.

Full details: Description check

Explanation

The description follows the template closely. It covers ELI5, What Changed (before and after with the mechanism), Why (including alternatives such as the Origin filter), Linked Issue (Refs #51748), Visual Proof (N/A with a reason and probe evidence), Testing with the checkboxes, Performance (None, with a reason and measurements), Risk (Level: Low with a rollback plan), the Agent skill boundary, Notes, and the Checklist. The Linked Issue section uses 'Refs' rather than 'Fixes', and the template says Refs is not sufficient for outside contributors. The author is not identified as an outside contributor, so this is a minor concern. The AI Disclosure section is empty, and the final checklist item is unchecked. Neither is critical for this check.

  • 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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 202a1188-744d-4d12-b68c-fac445890af8
Commits

Reviewing files that changed from the base of the PR and between b9bd7bc and 956de89.

Files selected for processing: 2

  • src/main/bots/tool-relay/bot-tool-relay-upstream.ts
  • src/main/bots/tool-relay/bot-tool-relay.test.ts

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

@nwparker
nwparker merged commit b3b282a into main Nov 28, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/issue-51748 branch November 28, 2026 17:28
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.

1 participant