fix(mcp): prove same-machine callers by peer address, not Origin - #390
Merged
Merged
Conversation
The route-based MCP endpoint trusted a caller-supplied loopback Origin as proof of a same-machine caller. A non-browser client forges the header, so a network-reachable dev server (vite --host and friends) exposed the whole agent tool surface, including the terminal spawn action, to unauthenticated remote callers. On the zero-config default (no widened allowedOrigins, no identity check), require the connected peer address to be loopback. The address comes from the socket via getRequestIP (never X-Forwarded-For), so a client cannot forge it. Configuring authorization or allowedOrigins: false opts out; a host that can't resolve a peer keeps the prior origin-only behavior.
◈ PR Lens
Architecture 1 component touched across 2 lanes. Data flow
View
Tip Add 🪧 More tips
Thanks for using PR Lens! It's built by Coldtea, free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The route-based MCP endpoint treated a caller-supplied loopback
Originheader as proof of a same-machine caller.Originis browser hardening (DNS-rebinding), not a network-locality check: a non-browser client sends any value it likes. So a dev server reachable beyond loopback (vite --host, a framework's equivalent, or the aggregate hub route) exposed the entire agent tool surface, with no authentication, to remote callers. Where the terminals plugin is mounted (e.g. Vite/Nuxt DevTools' built-in terminal) that surface includes a shell-spawn action, so this was an unauthenticated remote code execution path.Why this fix
On the zero-config default (no widened
allowedOrigins, no identity check) the endpoint's stated contract is "trust same-machine callers." That can only be enforced from the connected peer address, which a client cannot forge, not from a request header, which it can. This change makes the default contract actually hold, while keeping the local dev experience zero-config.Origin.getRequestIP, neverX-Forwarded-For), so it can't be spoofed by a header.mcp: { authorization }to prove who is calling (which also lifts the loopback-peer restriction, so authenticated callers may be remote), orallowedOrigins: falsewhen the host owns the boundary.authorizationas the docs now state.The existing origin and identity gates are untouched; this adds a locality gate between them, scoped strictly to the vulnerable default so no explicit configuration changes behaviour.
Verification
Originfrom a non-loopback peer is403; a loopback peer (incl. IPv4-mapped::ffff:127.0.0.1) is200; an identity check lifts the restriction;allowedOrigins: falseopts out; an unknown peer stays origin-only.pnpm lint && pnpm knip && pnpm typecheck && pnpm buildand the affected test suites pass; API snapshots updated for the newMcpConnectionInfoexport andisLoopbackAddresshelper.Scope / follow-up
This closes the reachable RCE at the transport boundary for every framework that mounts the route over the node/h3 path. A separate hardening worth considering: auto-mounted MCP currently sets
authorization: falseeven when the hub's ownauthis enabled, an inconsistent silent downgrade for the destructive tool surface. Left for a follow-up since it touches the shared auth handler.Given the downstream reach (Vite DevTools, Nuxt DevTools v4), this is worth coordinating disclosure and a release with those maintainers.
This PR was created with the help of an agent.