Repository navigation
fix(http): validate Host and Origin to block DNS rebinding - #14
Merged
Merged
Conversation
createMcpHandler is deliberately validation-free, and the template put nothing in front of it. A page on any website could rebind its domain to 127.0.0.1 and drive the local MCP endpoint from the user's browser, calling every registered tool. The MCP transport specification requires servers to validate Origin for this reason. Check the Host header and any browser Origin against allowlists before the MCP handler runs and answer 403 otherwise. Both lists default to the localhost names and are configurable through MCP_ALLOWED_HOSTS and MCP_ALLOWED_ORIGINS for deployments reached under a public name.
autoantohaki
force-pushed
the
fix/http-dns-rebinding
branch
from
October 22, 2026 00:08
58bac75 to
d292432
Compare
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.
Requested by mau
Summary
Before:
/mcpaccepted anyHostand any browserOrigin.createMcpHandleris deliberately validation-free and the template put nothing in front of it. A web page could DNS-rebind its own domain to127.0.0.1and call every tool on a developer's local server from the browser. The MCP Streamable HTTP spec requires servers to validateOriginfor exactly this reason.After: the MCP endpoint answers
403with a JSON-RPC error whenHostor a presentOriginnames a hostname outside the allowlist. The default allowlist islocalhost,127.0.0.1and[::1], so local development and the Compose setup (reached atlocalhost:3333) keep working. Deployments behind a public name add it withMCP_ALLOWED_HOSTS/MCP_ALLOWED_ORIGINS. Non-browser clients send noOriginand are unaffected./healthzand/readyzare not restricted, so probes keep working.How: the change uses the SDK's own
validateHostHeader/validateOriginHeader, two comma-separated config values, and docs inconfiguration.md,deployment.md,.env.exampleand the CHANGELOG. Tests cover a rebound host, a foreign origin, an allowed localhost origin, and a custom allowlist.Verification
npm run verify