Local MCP servers running on http://127.0.0.1:port look harmless. They are not. Without explicit defenses, a webpage in any browser tab can talk to your local MCP server and steal data — through DNS rebinding, malicious origin headers, or sloppy CORS.
The MCP spec is explicit: a server bound to localhost MUST validate the Origin header on every request and reject anything that isn't an allowlisted origin. The default allowlist is empty. Without it, a webpage at https://evil.example.com can fetch('http://127.0.0.1:1234/mcp', {…}) and your server will dutifully serve every tool the user installed.
DNS rebinding is the more sophisticated attack. The attacker registers a domain whose DNS responses flap between an external IP (for the initial page load) and 127.0.0.1 (after a low TTL). The browser-cached origin still says "evil.example.com" but the network calls land on the user's local server. Validating the Host header against an allowlist (e.g. only localhost and 127.0.0.1) blocks this; sole reliance on Origin does not.
Bind explicitly to 127.0.0.1, never 0.0.0.0, on local servers. Validate Origin and Host on every request. Refuse requests whose Origin is missing on a non-CORS-preflight path. This is roughly six lines of middleware and zero of them is optional.