You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Static review of public source at commit 603217008710. No traffic was sent to any MCP environment.
createMcpExpressApp (and the matching Hono helper) auto-arm Host + Origin validation only for loopback hosts. Binding to 0.0.0.0 / :: logs a warning, but any other non-loopback host (LAN IP, container hostname, public DNS name) gets neither middleware nor that warning:
packages/middleware/express/src/express.ts (same ladder in packages/middleware/hono/src/hono.ts):
constlocalhostHosts=['127.0.0.1','localhost','::1'];if(localhostHosts.includes(host)){app.use(localhostHostValidation());}elseif(host==='0.0.0.0'||host==='::'){console.warn(`Warning: Server is binding to ${host} without DNS rebinding protection. `+'Consider using the allowedHosts option...');}// Origin: only armed for loopback or explicit allowedOrigins
So createMcpExpressApp({ host: '192.168.1.10' }) or { host: 'mcp.internal' } serves without Host/Origin checks and without the operator nudge that 0.0.0.0 already gets. DNS rebinding / browser-origin abuse is exactly what those middleware exist for on HTTP MCP endpoints.
Suggested change:
Treat every non-loopback host like 0.0.0.0: require allowedHosts (and ideally allowedOrigins), or at least emit the same warning.
Or fail closed: refuse to construct the app for non-loopback binds unless allowlists are provided.
Keep the explicit opt-out path for demos that truly need an open bind.
Severity: medium as insecure default / defense-in-depth for non-loopback HTTP mounts; not claiming a working exploit against a specific deployment. No proof-of-concept.
Happy to send a focused PR if this direction is useful.
Any host that is neither loopback nor 0.0.0.0/:: falls through both branches, so there's no Host check and no warning. Equivalent wildcard spellings like 0:0:0:0:0:0:0:0 or [::] also skip the warning.
A backwards-compatible fix I'd suggest: make the warning branch the else (any non-loopback bind without allowedHosts warns), and apply it the same way in all three factories, with one test per factory. Fail-closed would break existing LAN/container deployments that sit behind their own auth or proxy, so I think it belongs in a separate, explicitly breaking change if you want it at all.
This also overlaps with #2852, which proposes removing the default Origin arming from the same code. It's probably worth settling both in one place so the Host/Origin defaults don't get changed twice.
@tiagovilasboas, you offered a PR. If you're not planning to send one, I'm happy to put up the warning-only version for all three factories once a maintainer confirms that direction.
The same ladder is in the published v1.x line. createMcpExpressApp in @modelcontextprotocol/sdk 1.30.1, released the day after this was filed, installs no Host validation for a host outside the three loopback names when allowedHosts is unset, and only warns for 0.0.0.0 and ::. 1.30.1 also added a comment above the parser saying a disallowed Host is answered 403 unread, which on those binds has nothing to run after. A fix on main would need a v1.x backport, the way #2698 got #2717.
Great analysis by @tiagovilasboas and @mactsouk regarding the non-loopback bind ladder across Express, Hono, and Fastify adapters.
When running MCP servers over HTTP or SSE in Docker containers, Kubernetes pods, or LAN environments, binding to 0.0.0.0 or a service hostname without strict Host and Origin validation creates an acute vulnerability: a browser executing untrusted JavaScript can perform a DNS rebinding attack (resolving an external hostname to the local or container IP), sending requests with an external Host header directly to the unauthenticated or weakly authenticated MCP server.
In designing production guardrails for MCP servers, we found that addressing this requires three concrete architectural patterns:
1. Robust IPv6 Bracket-Aware Host Header Parsing
A naive host.split(':') fails on bracketed IPv6 literals (e.g. [::1]:3000 or [2001:db8::1]) and doesn't handle port normalization:
exportfunctionparseHostHeader(rawHost: string): {hostname: string;port: number|null}{consttrimmed=rawHost.trim().toLowerCase();if(trimmed.startsWith('[')){constclosingIdx=trimmed.indexOf(']');if(closingIdx===-1)thrownewError('Malformed IPv6 host header: missing closing bracket');consthostname=trimmed.substring(0,closingIdx+1);constremainder=trimmed.substring(closingIdx+1);if(remainder.startsWith(':')){constport=parseInt(remainder.substring(1),10);if(isNaN(port)||port<1||port>65535)thrownewError('Invalid port');return{ hostname, port };}return{ hostname,port: null};}constparts=trimmed.split(':');if(parts.length===1)return{hostname: parts[0],port: null};if(parts.length===2){constport=parseInt(parts[1],10);if(isNaN(port)||port<1||port>65535)thrownewError('Invalid port');return{hostname: parts[0], port };}thrownewError('Malformed host header: unbracketed IPv6 or excessive colons');}
2. Dual-Layer Origin & Wildcard Host Whitelisting
To allow legitimate developer workflows while stopping browser pivots:
Wildcard Rejection: Client requests presenting Host: 0.0.0.0 or :: must be rejected immediately (wildcard IPs are bind addresses, never valid client target hosts).
Native Desktop Permissiveness: Native MCP clients (Claude Desktop, Cursor, CLI stdio-to-HTTP bridges) do not send an Origin header. The middleware should allow missing Origin headers by default (allowNoOrigin: true), but strictly block untrusted browser origins and Origin: null (sandboxed iframe exploits).
Explicit Domain & Subdomain Allowlisting: Support exact hostnames (mcp.internal) and wildcard subdomains (*.corp.net).
3. Modern JSON-RPC Error Envelopes (Avoiding Legacy -32000)
As noted in recent spec discussions (e.g. #3185), transport-level Host/Origin rejections on modern MCP paths should avoid legacy -32000 and return standard JSON-RPC 2.0 -32600 (Invalid Request) accompanied by HTTP 400 (malformed header) or 403 (unauthorized host/origin):
// Standard JSON-RPC 2.0 response for rejected Host / Origin{"jsonrpc": "2.0","id": null,"error": {"code": -32600,"message": "Forbidden: Host header not permitted","data": {"reason": "DNS Rebinding protection: host not allowed","rejectedHeader": "Host","value": rawHost}}}
This prevents silent bypasses on containerized binds while ensuring clients receive actionable, spec-compliant diagnostic responses rather than opaque drops.
Disclosure: Maintainer of mcp-production-kit (open-source TypeScript kit for MCP servers with automated DNS rebinding protection, secret redaction, audit logging, and stdio stream isolation).
Activity
iamhuman-cheolheelee commentedon Sep 24, 2026
Confirmed on
main(7f7a94c). The same ladder exists in all three factories, not just Express/Hono:packages/middleware/express/src/express.ts(createMcpExpressApp)packages/middleware/hono/src/hono.ts:92-98packages/middleware/fastify/src/fastify.ts:81-86(usesapp.log.warn)Any
hostthat is neither loopback nor0.0.0.0/::falls through both branches, so there's no Host check and no warning. Equivalent wildcard spellings like0:0:0:0:0:0:0:0or[::]also skip the warning.A backwards-compatible fix I'd suggest: make the warning branch the
else(any non-loopback bind withoutallowedHostswarns), and apply it the same way in all three factories, with one test per factory. Fail-closed would break existing LAN/container deployments that sit behind their own auth or proxy, so I think it belongs in a separate, explicitly breaking change if you want it at all.This also overlaps with #2852, which proposes removing the default Origin arming from the same code. It's probably worth settling both in one place so the Host/Origin defaults don't get changed twice.
@tiagovilasboas, you offered a PR. If you're not planning to send one, I'm happy to put up the warning-only version for all three factories once a maintainer confirms that direction.
imran-siddique commentedon Sep 25, 2026
The same ladder is in the published v1.x line.
createMcpExpressAppin@modelcontextprotocol/sdk1.30.1, released the day after this was filed, installs no Host validation for a host outside the three loopback names whenallowedHostsis unset, and only warns for0.0.0.0and::. 1.30.1 also added a comment above the parser saying a disallowed Host is answered 403 unread, which on those binds has nothing to run after. A fix on main would need a v1.x backport, the way #2698 got #2717.A7mdMe commentedon Nov 14, 2026
Great analysis by @tiagovilasboas and @mactsouk regarding the non-loopback bind ladder across Express, Hono, and Fastify adapters.
When running MCP servers over HTTP or SSE in Docker containers, Kubernetes pods, or LAN environments, binding to
0.0.0.0or a service hostname without strict Host and Origin validation creates an acute vulnerability: a browser executing untrusted JavaScript can perform a DNS rebinding attack (resolving an external hostname to the local or container IP), sending requests with an externalHostheader directly to the unauthenticated or weakly authenticated MCP server.In designing production guardrails for MCP servers, we found that addressing this requires three concrete architectural patterns:
1. Robust IPv6 Bracket-Aware Host Header Parsing
A naive
host.split(':')fails on bracketed IPv6 literals (e.g.[::1]:3000or[2001:db8::1]) and doesn't handle port normalization:2. Dual-Layer Origin & Wildcard Host Whitelisting
To allow legitimate developer workflows while stopping browser pivots:
Host: 0.0.0.0or::must be rejected immediately (wildcard IPs are bind addresses, never valid client target hosts).Originheader. The middleware should allow missingOriginheaders by default (allowNoOrigin: true), but strictly block untrusted browser origins andOrigin: null(sandboxed iframe exploits).mcp.internal) and wildcard subdomains (*.corp.net).3. Modern JSON-RPC Error Envelopes (Avoiding Legacy -32000)
As noted in recent spec discussions (e.g. #3185), transport-level Host/Origin rejections on modern MCP paths should avoid legacy
-32000and return standard JSON-RPC 2.0-32600(Invalid Request) accompanied by HTTP 400 (malformed header) or 403 (unauthorized host/origin):This prevents silent bypasses on containerized binds while ensuring clients receive actionable, spec-compliant diagnostic responses rather than opaque drops.
Disclosure: Maintainer of mcp-production-kit (open-source TypeScript kit for MCP servers with automated DNS rebinding protection, secret redaction, audit logging, and stdio stream isolation).