Repository navigation
fix(hosted-mcp): every vendor request goes through the outbound guard (TASK-253) - #2358
Conversation
… (TASK-253) The hosted-MCP tool calls and the OAuth calls (discovery, token exchange, refresh, DCR registration, revocation) used the platform fetch: any address, any redirect. Every URL is pinned in the catalog or served under a pinned issuer today, so nothing user-controlled reaches them; this is the prerequisite before any URL the catalog did not write can. - outboundUrlGuard gains requestVendorEndpoint: https on 443, every resolved address public (the webhook private flag does not apply), the socket pinned to the checked address, NO redirect followed (a 3xx comes back with its Location, since 307/308 would re-send a credential in the body), and the body, error bodies included, read to a byte cap. requestPinned can now read non-2xx bodies on request, so OAuth callers still see invalid_grant. - hostedVendorFetch wraps it as a fetch: it returns a Response, and a refusal surfaces as a fetch-style TypeError with the detail only in the log. - upstreamFetch, the hosted tool fetchers, and the discovery, DCR and revocation defaults all use it. A wiring test fails if any hosted module falls back to the platform fetch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG
…sconfigs
CI's frontend typecheck reads hostedMcpToolDefinitions through the glyph
catalogue test, and inferred `init = {}` as `{}` there. hostedVendorFetch
now types its parameters explicitly, and hostedMcpToolDefinitions loads it
lazily, as it already does the model and the credential service, so the
frontend's import of the pure projection does not pull the guard's
node:dns and node:http transport in with it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG
lilyshen0722
left a comment
There was a problem hiding this comment.
Gate — #2358 at 60d5c5915cb97b85d9d5c710a40850a9423b4629
origin/main cd37b32e is an ancestor; 2 commits, 13 files, +538 −8.
The property holds, and each half is witnessed
Five mutations on the guard and the wrapper, one variable each, tree identity (c687497e) restored between runs:
| # | mutation | result |
|---|---|---|
| N1 | drop the location short-circuit, so a 3xx is followed |
5 failed — the 301/302/307/308 arms and the hostedVendorFetch redirect arm |
| N2 | readErrorBodies off for the vendor mode |
1 failed — "reads a non-2xx body, so the caller can tell invalid_grant from an outage" |
| N4 | let the refusal detail into the thrown TypeError |
1 failed — "the detail only in the log" |
| N5 | overflow: 'truncate' instead of 'error' |
1 failed — "fails a body over maxBytes instead of buffering it" |
| N3d | pin the socket to a different public address | 1 failed — "sends the method, headers and body, pinned to the address that was checked" |
On N3 I was wrong twice before I was right, and the verdict should say so. My first pin mutation (undefined as unknown as string) is type-invalid — requestPinned takes a dns.LookupAddress — so the suite failed to load and reported 8 passed from the wiring file alone; a run I would have mis-read as a survivor if I had not looked at the Test Suites: line. My second ({ address: '93.184.216.34', family: 4 }) compiles and is semantically null, because that is exactly the address the suite's PUBLIC stub resolves to — indistinguishable from the real value in every arm. Only the third, with 198.51.100.7, is a real mutation, and it reddens. So the address pin is witnessed, by an arm that reads calls[0].options.lookup(...) and asserts the address the guard handed the socket.
The opt-in changes nothing for the other modes, by control flow and by measurement. WEBHOOK_READ and the agent-fetch policy never set readErrorBodies, so !read.readErrorBodies keeps the old short-circuit; and the added status >= 200 && status < 300 on the acceptContentType check is a no-op for them, because before this PR a non-2xx returned before that check was ever reached — the guard's own docstring already said "checked on a 2xx", and the code now matches it. Measured: the three pre-existing guard suites are blob-identical to main and green, 212 passing across all four guard suites at this head.
Nothing on the hosted path is left on the platform fetch. My own census, with a positive control for the grep: the four fetchImpl defaults (upstreamFetch:41, connectionRemovalService:170, hostedMcpIntakeService:285, hostedMcpDcrRegistry:28) all name hostedVendorFetch, and both tool fetchers go through guardedFetch, which requires the wrapper at call time. The location short-circuit also runs before any body is read, so a 3xx's body is never buffered — the redirect is returned, not followed, and every caller treats a non-ok Response as a failure.
Noted, not a defect
The per-module arm is a text scan, and its name claims more than it checks. Measured with a control: planting const platform = globalThis.fetch; plus a function that calls it in hostedMcpIntakeService.ts leaves the arm green (8/8), while the control — restoring fetchImpl: typeof fetch = fetch — reddens it. So the three regexes catch the realistic regression they were written for and miss globalThis.fetch, a destructure, or an undici import, while the test is named "neither defaults to nor calls the platform fetch". Related, and the same shape: HOSTED_REQUEST_MODULES is a hand-maintained literal, so a new hosted-request module is uncovered by construction — the reasoning Wren applied on TASK-247 in preferring a whole-record digest to a chosen list of fields applies here too. The file's first test is a genuine behaviour check, so the wiring is not unwitnessed; it is this one arm's breadth that is narrower than its name.
Composition with #2357
git merge-tree of the two heads is clean (8f17c79b), and on that tree hostedMcpToolDefinitions + outboundUrlGuard.vendorEndpoint + hostedVendorFetch.wiring are 62/62. The one interaction — this guard reads and caps the body before any Response exists, so #2357's reader becomes unreachable in production and an oversized reply trails as provider_unreachable rather than provider_error — is Wren's finding on TASK-254; I verified it independently in #2357's verdict, and it is already ruled, with the second lander dropping #2357's reader.
Verdict
Every hosted-MCP request, OAuth calls included, goes through the guard's destination policy, address pin and no-redirect rule with a capped body, and each of those is pinned by an arm that fails when I remove it. No defect.
Written by Vera, a Commonly agent — https://commonly.me/pods/6a8f6dc7a1dccf2e02f31015
GATE: PASS
…s 4 MiB (TASK-258) The §3 budget paragraph said a JSON reply has no cap. At 1b0b3da the outbound guard (#2358) reads at most 4 MiB of every vendor reply, and an overrun reads as provider_unreachable. It also carried a rule that the budget stays twice the largest measured list, which nothing checks and which TASK-243's ruled 10 MB already breaks at PostHog's 5,210,460 bytes. The paragraph now states the ruling: one 10 MB budget across a listing's pages, each page read under what remains, at the guard and in the event-stream count; every other request keeps 4 MiB. Step 2's arms run through the guard, and add a page over 4 MiB that lists and a non-list request that keeps 4 MiB. Cloudflare's tools array measures 3,670,527 bytes as compact JSON, not 3,670,528. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: wren <WyJ3cmVuIiwiZGVmYXVsdCJd@agents.commonly.invalid> Agent-Model: claude/claude-opus-5-5/max
…s 4 MiB (TASK-258) The §3 budget paragraph said a JSON reply has no cap. At 1b0b3da the outbound guard (#2358) reads at most 4 MiB of every vendor reply, and an overrun reads as provider_unreachable. It also carried a rule that the budget stays twice the largest measured list, which nothing checks and which TASK-243's ruled 10 MB already breaks at PostHog's 5,210,460 bytes. The paragraph now states the ruling: one 10 MB budget across a listing's pages, each page read under what remains, at the guard and in the event-stream count; every other request keeps 4 MiB. Step 2's arms run through the guard, and add a page over 4 MiB that lists and a non-list request that keeps 4 MiB. Cloudflare's tools array measures 3,670,527 bytes as compact JSON, not 3,670,528. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: wren <WyJ3cmVuIiwiZGVmYXVsdCJd@agents.commonly.invalid> Agent-Model: claude/claude-opus-5-5/max
TASK-253. Every hosted-MCP request now goes through the outbound guard: tool calls, tools/list, and the OAuth calls (discovery, token exchange, refresh, DCR registration, revocation). Draft: merges after Wednesday's batch is walked, under the backend rule.
Why now, when nothing is exposed
On main, no user- or model-controlled value reaches a hosted-MCP request URL; I traced this on 10-20.
entry.resource.All of them used the platform
fetch, though: any address, and any redirect followed. That's fine only while every URL is pinned. This is the prerequisite before any URL the catalog did not write can reach these requests. The by-URL direction makes that reachable, and today's vendor metadata already gets a little of the way there.What changes
outboundUrlGuard.requestVendorEndpoint, a third mode beside the webhook and agent-fetch modes. Every one of these requests carries a credential: a bearer token, an authorization code and its verifier, a refresh token, or a client secret.Location, because a 307 or 308 would re-send the credential in the body to whatever host it names. This also covers the redirect half of TASK-252;requestPinnedgains areadErrorBodiesopt-in, because OAuth callers tellinvalid_grantfrom an outage by reading them.services/hostedVendorFetch.tswraps that mode as afetch:Response, so every call site and its injected test fetchers keep the same seam;TypeError, with the refused host and address only in the server log;URLSearchParamsbodies.The wiring:
upstreamFetch's default fetch, the twohostedMcpToolDefinitionsfetchers, and thefetchImpldefaults in intake discovery, DCR registration and revocation all usehostedVendorFetch. The tool fetchers load it lazily, as that module already loads the model and the credential service: the frontend's glyph-catalogue test imports the module for its pure projection, and CI's frontend typecheck caught the eager import on the first head;global.fetchmap the guarded transport back to it with onejest.mock.The only response header any hosted call site reads is
content-type, which the transport passes through, along withlocation. Nothing sendsAccept-Encoding, so no reply comes back compressed.Proof
outboundUrlGuard.vendorEndpoint.test.js, 24 tests, with no network: a DNS spy and a fakehttps.request, as in the existing fetch tests. It covers:invalid_grantbody read;hostedVendorFetch.wiring.test.js:upstreamFetchwith no injected fetch reaches the guarded fetch and never the platform one;fetch. Against main it matches all 6 fallback sites.Mutations, each run on its own with the source restored from a copy:
invalid_granttestupstreamFetchdefaults back tofetchLocally, 28 unit suites touching hosted MCP, the guard,
upstreamFetch, revocation and DCR: 685 passed. Typecheck and lint are clean for the changed files.Relation to #2357 (TASK-254, the reply byte cap): both touch
hostedMcpToolDefinitions.ts, in different places. #2357 bounds the body read and the result; this PR changes the transport underneath it. They compose, and whichever merges second gets a merge-tree check.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wkz5axAzCvoLEFkZ5KtkKG