Skip to content

fix(hosted-mcp): every vendor request goes through the outbound guard (TASK-253) - #2358

Merged
lilyshen0722 merged 2 commits into
mainfrom
fix/hosted-mcp-outbound-guard
Oct 22, 2026
Merged

lilyshen0722 merged 2 commits into
mainfrom
fix/hosted-mcp-outbound-guard

Conversation

@lilyshen0722

@lilyshen0722 lilyshen0722 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Tool and list requests go to the catalog-pinned entry.resource.
  • OAuth requests go to the pinned issuer, or to the token and registration endpoints in that issuer's own metadata.

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.

  • https on the default port, with no credentials in the URL;
  • every address the host resolves to must be public. The webhook private-address flag does not apply;
  • the socket is pinned to the address that was checked;
  • no redirect is followed. A 3xx comes back as its status with its 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;
  • the body is read to a byte cap and then fails. Error bodies are included: requestPinned gains a readErrorBodies opt-in, because OAuth callers tell invalid_grant from an outage by reading them.

services/hostedVendorFetch.ts wraps that mode as a fetch:

  • it returns a Response, so every call site and its injected test fetchers keep the same seam;
  • a refusal surfaces as a fetch-style TypeError, with the refused host and address only in the server log;
  • it sends only string or URLSearchParams bodies.

The wiring:

  • upstreamFetch's default fetch, the two hostedMcpToolDefinitions fetchers, and the fetchImpl defaults in intake discovery, DCR registration and revocation all use hostedVendorFetch. 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;
  • the four suites that stub the vendor at global.fetch map the guarded transport back to it with one jest.mock.

The only response header any hosted call site reads is content-type, which the transport passes through, along with location. Nothing sends Accept-Encoding, so no reply comes back compressed.

Proof

  • outboundUrlGuard.vendorEndpoint.test.js, 24 tests, with no network: a DNS spy and a fake https.request, as in the existing fetch tests. It covers:
    • refusals of http, a non-default port, credentials in the URL and the metadata host, all without a lookup;
    • refusals of private, loopback, link-local, ULA and mixed answers, with the webhook flag set;
    • the address pin;
    • 301, 302, 307 and 308 returned and never followed;
    • a 400 invalid_grant body read;
    • an over-cap body failing;
    • the Response shape, form bodies, and a refusal that keeps the address out of the error.
  • hostedVendorFetch.wiring.test.js:
    • upstreamFetch with no injected fetch reaches the guarded fetch and never the platform one;
    • a source scan of the 7 hosted request modules finds no default to, or call of, the platform fetch. Against main it matches all 6 fallback sites.

Mutations, each run on its own with the source restored from a copy:

mutation fails
use the webhook policy instead of the agent-fetch one the http, port, credentials and private-address tests
follow one redirect the 4 never-followed tests and the hostedVendorFetch redirect test
don't read error bodies the invalid_grant test
upstreamFetch defaults back to fetch the behavioral wiring test and the source scan

Locally, 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

lilyshen0722 and others added 2 commits October 19, 2026 23:42
… (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 lilyshen0722 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

@lilyshen0722
lilyshen0722 marked this pull request as ready for review October 22, 2026 10:21
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Oct 22, 2026
Merged via the queue into main with commit 94f85f8 Oct 22, 2026
30 checks passed
samxu01 pushed a commit that referenced this pull request Oct 22, 2026
…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
samxu01 pushed a commit that referenced this pull request Oct 23, 2026
…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
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