Repository navigation
fix(bots): stop the tool relay forwarding Sec-Fetch-* headers upstream - #51894
Conversation
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
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
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 ownfetchrefuses to send one of them (Sec-Fetch-Mode: cors) without anOrigin, so the request failed before it left Orca and Pi ended up with no tools. The relay now drops those headers.What Changed
Sec-Fetch-Mode,Sec-Fetch-SiteandSec-Fetch-Destfrom the agent's request onto its upstream request. When Pi (Node/undicifetch) called a relayed MCP server, Electron's net-backedfetchthrewnet::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.sendUpstream(src/main/bots/tool-relay/bot-tool-relay-upstream.ts) skips anysec-fetch-*header name when it builds the upstream headers. It already skipsproxy-*, hop-by-hop headers and the relay credentials the same way. All other agent headers are still forwarded, includinguser-agent,accept-language,mcp-*andReferer.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 wholesec-fetch-prefix is simpler than keeping a list of single headers, and it follows the existingproxy-prefix rule. AnOriginfilter is not needed because the relay already refuses any request that carriesOrigin(its browser-page check inbot-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.fetchto a loopback server:main(sec-fetch-mode: cors, no origin)THREW Error: net::ERR_INVALID_ARGUMENTsec-fetch-*)200sec-fetch-mode: cors+originTHREW Error: net::ERR_FAILEDsec-fetch-dest: emptyonly200sec-fetch-mode: no-cors200Testing
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 exceptsec-fetch-*and the relay token, plus the saved credential header.The new test fails on
main'sbot-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
startsWithcheck 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
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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)