Repository navigation
fix(http)!: bind local HTTP mode to 127.0.0.1 by default (SEC-974) - #261
Gerardo Sabetta (gerardosabetta) wants to merge 2 commits into
Conversation
`socket-mcp --http` called `listen(port)` with no host when MCP_HOST was unset, so Node bound the dual-stack wildcard and the server was reachable from every interface. HTTP mode now binds 127.0.0.1 unless the operator opts in with the new `--host <address>` flag or MCP_HOST, which `--host` overrides. A non-loopback bind logs a warning, and the start banner prints the URL that matches the bind. BREAKING CHANGE: self-hosted HTTP servers that must accept connections from other machines, such as in a container, need `--host 0.0.0.0` or MCP_HOST=0.0.0.0.
PR SummaryHigh Risk Overview Operators who need remote or container access must opt in with README and Reviewed by Cursor Bugbot for commit f1155af. Configure here. |
Fixes the remaining local part of SEC-974.
What changed
socket-mcp --httpcalledhttpServer.listen(port, …)with no host whenMCP_HOSTwas unset. Node then binds the dual-stack wildcard, so the server accepted connections on every IPv4 and IPv6 interface.127.0.0.1by default (DEFAULT_MCP_HOSTinlib/env.mts).--host <address>/--host=<address>CLI flag. It takes precedence overMCP_HOST, and both opt in to another address (0.0.0.0,::, or one interface). A bare--hostwith no value exits 1.Connect to:banner prints a URL that matches the bind; it used to printlocalhostwhatever the bind was.docs/commands.mdandREADME.mddocument the new default, the opt-in, and127.0.0.1client URLs.Before (origin/main
f3d94fa):TCP *:3456 (LISTEN)on an IPv6 dual-stack socket.After:
TCP 127.0.0.1:3456 (LISTEN).Heads-up for reviewers
--host 0.0.0.0orMCP_HOST=0.0.0.0. The release notes should say so. CHANGELOG.md is generated at release time, so this PR doesn't edit it.::1listener, because binding both would need two servers. The hosted parent and the Host-header allowlist already use127.0.0.1.workspaces/hosted-mcpspawnsnode <entry> --httpwithprocess.envplusMCP_PORT, and never setsMCP_HOSTin code or in tanka. Its healthcheck and both proxy targets usehttp://127.0.0.1:<childPort>. A simulated hosted spawn of the builtdist/index.cjsbound127.0.0.1and returned healthy on/health. As a side effect, the child is no longer also exposed on the pod IP.How it was tested
pnpm test: 751 tests passed across 76 files. New tests cover the default host,MCP_HOSTpassthrough,--hostprecedence, the--host=form, a missing value,parseHostFlag, the default bind address, a0.0.0.0bind with its warning,isLoopbackHostandformatConnectUrl.pnpm run lint,pnpm run repo:checkandpnpm run check(format, lint, types, build, versions, content scan) all pass.lsof:127.0.0.1:3456--host 0.0.0.0→*:3457, with a warningMCP_HOST=0.0.0.0→*:3458, with a warningMCP_HOST=0.0.0.0 --host 127.0.0.1→127.0.0.1:3459Slides
🤖 Generated with Claude Code