inspector icon indicating copy to clipboard operation
inspector copied to clipboard

Stored credential headers are sent to metadata hosts the target chooses

Open olartgabo opened this issue 2 months ago • 1 comments

Found during the review of #4884 (MJ-001 redaction). Out of scope for that PR, deliberately left for its own ticket. Not covered by anything merged.

What happens

sdk/src/server-probe.ts:563 strips exactly one header before dialling an authorization-server metadata host:

const metadataHeaders = removeAuthorizationHeader(normalizeHeaders(config.headers));

removeAuthorizationHeader (:139-147) filters the single name Authorization. Every other stored header on the server config is sent as-is — X-Api-Key, X-Auth-Token, a vendor session header, anything a user saved against that server.

The hosts it sends them to are named by the target in its own WWW-Authenticate challenge (resource_metadata, and the authorization-server metadata URL), not by the user. The egress guard permits them because they are publicly routable.

Why it matters

A user saves an MCP server with X-Api-Key: <their vendor key>. The target answers 401 with resource_metadata="https://collect.attacker.test/prm". The probe dials that host and sends the vendor key.

Cross-origin redirects already strip credentials (hosted-egress-guard.ts:435-448). The initial cross-origin dial to the challenge-named host does not.

Suggested direction

Strip all stored credential headers — not a denylist of one name — before any request to a host the user did not configure. The existing redirect-stripping logic is the right precedent to reuse.

Notes

Separate from #5001 (bearer token echoed back in the response), though both live on the same probe path.

Not a pentest finding. Reported here so it is tracked rather than sitting only in the review write-up.

olartgabo avatar Sep 13 '26 03:09 olartgabo

Opened #5060 for this. @chelojimenez — tagging per CONTRIBUTING since I can't self-assign; happy to step aside if someone is already on it.

One deliberate departure from the suggested direction, worth your call: instead of stripping a list of credential-shaped names, stored headers now travel only to the configured server's own origin, and a target-chosen host gets none of them. X-Session-Id is what decided it — plainly a credential, and matched by no token|secret|apikey pattern I would have written. The metadata endpoints are unauthenticated by spec (RFC 9728 / RFC 8414), so nothing legitimate needs the headers there.

The gate is per destination rather than per discovery, because discoverOAuthProtectedResourceMetadata follows the documents it reads and one call can dial several hosts.

Every strip in the tests is paired with the same-origin carry it must not break, so "sends nothing anywhere" cannot pass. The one mutation that survives (unparseable URL failing open) is unreachable through the public entry point because assertMetadataDestinationAllowed rejects the pointer first — written out in the PR rather than papered over.

Cut from main, independent of #5058 for #5001; they touch the same file but not the same lines.

L4XB avatar Sep 14 '26 07:09 L4XB