Skip to content

fix(http)!: bind local HTTP mode to 127.0.0.1 by default (SEC-974) - #261

Open
Gerardo Sabetta (gerardosabetta) wants to merge 2 commits into
mainfrom
gerardosabetta/sec-974-http-loopback-default
Open

Gerardo Sabetta (gerardosabetta) wants to merge 2 commits into
mainfrom
gerardosabetta/sec-974-http-loopback-default

Conversation

@gerardosabetta

@gerardosabetta Gerardo Sabetta (gerardosabetta) commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the remaining local part of SEC-974.

What changed

socket-mcp --http called httpServer.listen(port, …) with no host when MCP_HOST was unset. Node then binds the dual-stack wildcard, so the server accepted connections on every IPv4 and IPv6 interface.

  • HTTP mode now binds 127.0.0.1 by default (DEFAULT_MCP_HOST in lib/env.mts).
  • New --host <address> / --host=<address> CLI flag. It takes precedence over MCP_HOST, and both opt in to another address (0.0.0.0, ::, or one interface). A bare --host with no value exits 1.
  • A non-loopback bind logs a warning. The Connect to: banner prints a URL that matches the bind; it used to print localhost whatever the bind was.
  • docs/commands.md and README.md document the new default, the opt-in, and 127.0.0.1 client 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

  • Behavior change for self-hosted HTTP. A server that has to be reachable from other machines, such as one in a container, now needs --host 0.0.0.0 or MCP_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.
  • IPv4 loopback only. There is no ::1 listener, because binding both would need two servers. The hosted parent and the Host-header allowlist already use 127.0.0.1.
  • Hosted mcp.socket.dev needs no depscan change. workspaces/hosted-mcp spawns node <entry> --http with process.env plus MCP_PORT, and never sets MCP_HOST in code or in tanka. Its healthcheck and both proxy targets use http://127.0.0.1:<childPort>. A simulated hosted spawn of the built dist/index.cjs bound 127.0.0.1 and 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_HOST passthrough, --host precedence, the --host= form, a missing value, parseHostFlag, the default bind address, a 0.0.0.0 bind with its warning, isLoopbackHost and formatConnectUrl.
  • pnpm run lint, pnpm run repo:check and pnpm run check (format, lint, types, build, versions, content scan) all pass.
  • Local listen checks with lsof:
    • default → 127.0.0.1:3456
    • --host 0.0.0.0 → *:3457, with a warning
    • MCP_HOST=0.0.0.0 → *:3458, with a warning
    • MCP_HOST=0.0.0.0 --host 127.0.0.1 → 127.0.0.1:3459
  • Not covered: depscan's hosted-mcp test suite against this build (it pins the published 0.7.0), and a real container deployment.

Slides

cover

gap

resolve

hosted

headsup

verify

🤖 Generated with Claude Code

`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.
Gerardo Sabetta (gerardosabetta) added a commit that referenced this pull request Dec 2, 2026
@gerardosabetta
Gerardo Sabetta (gerardosabetta) marked this pull request as ready for review December 3, 2026 17:22
@cursor

cursor Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Breaking change for self-hosted HTTP deployments that relied on the old default wildcard bind; security-sensitive networking posture with required operator migration via --host or MCP_HOST for non-local access.

Overview
Local HTTP mode no longer listens on all network interfaces by default. socket-mcp --http now binds 127.0.0.1 when neither MCP_HOST nor --host is set (addresses SEC-974), replacing the previous behavior where an unset host let Node accept connections on every interface.

Operators who need remote or container access must opt in with --host 0.0.0.0 / --host=:: or MCP_HOST. The CLI resolves bind order as --host → MCP_HOST → DEFAULT_MCP_HOST, rejects a bare --host with exit 1, and logs a warning when binding a non-loopback address. Startup Connect to: URLs use formatConnectUrl (e.g. 127.0.0.1 instead of always localhost).

README and docs/commands.md document the new default, recommend 127.0.0.1 in client URLs, and update the MCP_HOST env table default from “all interfaces” to 127.0.0.1.

Reviewed by Cursor Bugbot for commit f1155af. Configure here.

This branch has not been deployed

No deployments
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.

2 participants