Skip to content

fix(http): validate Host and Origin to block DNS rebinding - #14

Merged
autoantohaki merged 1 commit into
mainfrom
fix/http-dns-rebinding
Oct 22, 2026
Merged

autoantohaki merged 1 commit into
mainfrom
fix/http-dns-rebinding

Conversation

@autoantohaki

Copy link
Copy Markdown
Member

Requested by mau

Summary

Before: /mcp accepted any Host and any browser Origin. createMcpHandler is deliberately validation-free and the template put nothing in front of it. A web page could DNS-rebind its own domain to 127.0.0.1 and call every tool on a developer's local server from the browser. The MCP Streamable HTTP spec requires servers to validate Origin for exactly this reason.

After: the MCP endpoint answers 403 with a JSON-RPC error when Host or a present Origin names a hostname outside the allowlist. The default allowlist is localhost, 127.0.0.1 and [::1], so local development and the Compose setup (reached at localhost:3333) keep working. Deployments behind a public name add it with MCP_ALLOWED_HOSTS / MCP_ALLOWED_ORIGINS. Non-browser clients send no Origin and are unaffected. /healthz and /readyz are not restricted, so probes keep working.

How: the change uses the SDK's own validateHostHeader / validateOriginHeader, two comma-separated config values, and docs in configuration.md, deployment.md, .env.example and the CHANGELOG. Tests cover a rebound host, a foreign origin, an allowed localhost origin, and a custom allowlist.

Verification

  • npm run verify
  • Documentation updated
  • No credentials or machine-specific paths added

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
autoantohaki force-pushed the fix/http-dns-rebinding branch from 58bac75 to d292432 Compare October 22, 2026 00:08
@autoantohaki
autoantohaki merged commit 44e1f43 into main Oct 22, 2026
4 of 5 checks passed
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