Skip to main content

Localhost is not a boundary: dev servers, AI coding agents and cross-origin WebSockets

A developer laptop runs a surprising number of servers: the front-end dev server, a hot-reload socket, a debugger, an IDE extension that lets an AI coding agent read open files, a local MCP server, a database console. Most of them listen on 127.0.0.1 and assume that makes them private. It does not. Every web page open in your browser runs on the same machine and can send requests to those ports.

In 2025 this assumption produced real CVEs in tools developers use every day. This post explains how a web page reaches a local server, what went wrong in those cases, and the three checks every local server needs.

How a web page reaches your loopback port

The same-origin policy stops a page from reading most cross-origin responses. It does not stop the page from sending requests, and it does not cover every channel.

Channel What a malicious page can do
Simple requests (form POST, fetch with no-cors, <img>) Send a request with side effects. It cannot read the reply, but the action happens
WebSocket Open a socket to ws://127.0.0.1:PORT. CORS does not apply; the server sees an Origin header and must decide for itself (RFC 6455, section 10.2)
DNS rebinding Serve a page from attacker.example, then make that name resolve to 127.0.0.1. The browser now treats your local server as same-origin with the attacker's page
<script src> Load a local JavaScript file and run it in the attacker's page, which can expose its contents

A server that only listens on loopback stops other machines. It does nothing about a browser tab on the same machine.

What went wrong in 2025

An AI coding agent's IDE bridge. CVE-2025-52882 affected the Claude Code extensions for VS Code (and forks such as Cursor, Windsurf and VSCodium) and JetBrains IDEs. The advisory says they were "vulnerable to unauthorized websocket connections from an attacker when visiting attacker-controlled webpages". In VS Code an attacker could read arbitrary files, see open files and get selection and diagnostics events. It was rated High (CVSS 4.0 score 8.8) and fixed in 1.0.24 for VS Code and 0.1.9 for JetBrains.

A local MCP debugging tool. CVE-2025-49596 in the MCP Inspector, a tool for testing MCP servers, was rated Critical (CVSS 4.0 score 9.4). Versions below 0.14.1 had no authentication between the Inspector client and its proxy, which allowed unauthenticated requests to launch MCP commands over stdio: remote code execution on the developer's machine.

A dev server with an incomplete Origin check. CVE-2025-30360 in webpack-dev-server is a good lesson in partial fixes. The server already checked Origin to block cross-site WebSocket hijacking, but it always accepted Origin values that were IP addresses. A malicious site served from an IP address could open the socket and read hot-reload messages, exposing source code. It was fixed in 5.2.1.

The pattern is the same each time: a server trusted the network location of the caller instead of checking who the caller was.

Browsers help, but do not rely on them

Chrome now gates requests from public sites to local and loopback addresses behind a Local Network Access permission, and its guidance says these restrictions "also govern WebSocket and WebTransport connections". The webpack-dev-server advisory notes that Chromium's earlier private network restrictions are why Chrome users were not affected. That is a welcome layer, but other browsers behave differently, users click "Allow", and DNS rebinding and older browser versions still exist. The server has to defend itself.

Three checks every local server needs

The MCP specification puts it plainly for its HTTP transport (Streamable HTTP, security and endpoint): servers "MUST validate the Origin header on all incoming connections", "SHOULD bind only to localhost", and "SHOULD implement proper authentication for all connections". That advice applies to any local server.

  1. Validate Host. Accept only localhost, 127.0.0.1, [::1] (with your port) and any name you configure. A DNS rebinding request arrives with Host: attacker.example, so this one check defeats it.
  2. Validate Origin. If the header is present and not on an exact allowlist, reject with 403. Compare full origins, not prefixes or substrings, and do not make exceptions for IP addresses.
  3. Require a session token. Generate a random token at start-up, give it to the legitimate client out of band (a file with 0600 permissions, a printed URL, an environment variable) and require it on every request and on the WebSocket handshake. Compare it in constant time.

Then the basics: bind to 127.0.0.1, not 0.0.0.0. Never send Access-Control-Allow-Origin: * from a local API. Never change state on GET. Where the client is a local process, prefer stdio or a Unix domain socket with tight file permissions, which a browser cannot reach at all.

Here is the shape for a Node WebSocket server using ws:

import { WebSocketServer } from 'ws';
import crypto from 'node:crypto';

const PORT = 7777;
const TOKEN = crypto.randomBytes(32).toString('hex'); // write to a 0600 file for the client
const ALLOWED_HOSTS = new Set([`127.0.0.1:${PORT}`, `localhost:${PORT}`, `[::1]:${PORT}`]);
const ALLOWED_ORIGINS = new Set([]); // a non-browser client sends no Origin

function tokenMatches(given) {
  const a = Buffer.from(String(given ?? ''));
  const b = Buffer.from(TOKEN);
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

const wss = new WebSocketServer({
  host: '127.0.0.1',
  port: PORT,
  verifyClient: (info, done) => {
    if (!ALLOWED_HOSTS.has(info.req.headers.host ?? '')) return done(false, 403);
    if (info.origin && !ALLOWED_ORIGINS.has(info.origin)) return done(false, 403);
    if (!tokenMatches(info.req.headers['x-session-token'])) return done(false, 401);
    done(true);
  },
});

Browsers cannot set custom headers on a WebSocket handshake, so a header token also shuts out every web page. If your legitimate client is itself a browser page, carry the token in the Sec-WebSocket-Protocol value or the first message, and close the socket if it is missing.

A checklist for your own machine

  • List what is listening: lsof -iTCP -sTCP:LISTEN -n -P on macOS and Linux.
  • For each one you did not write, check whether it binds to 0.0.0.0, whether it asks for a token, and whether its project has published advisories.
  • Keep dev tools, IDE extensions and agent bridges updated. Several of the fixes above shipped through auto-update, which only helps if the tool restarts.
  • Stop dev servers you are not using. A server that is not running cannot be reached.

What Vulkro checks

Vulkro Core flags the code side of this in the projects you scan:

Rule What it flags
ws-server-init A WebSocket server (ws, socket.io, Python websockets, FastAPI, Go gorilla and others) set up with no origin allowlist, or with CheckOrigin returning true
cors-wildcard-origin, cors-origin-reflection-with-credentials CORS that accepts any origin, or reflects the caller's origin with credentials
bind-all-interfaces A Python service bound to 0.0.0.0 (Low, because containers often need it)
MCP-005 An MCP endpoint in your agent config that is cleartext or HTTPS without auth (vulkro mcp-audit)
vulkro scan .
vulkro mcp-audit

It does not yet check whether a server validates the Host header, so treat DNS rebinding as a review item. Vulkro's own local console follows the three checks above: it binds to 127.0.0.1, requires a fresh token on every start, and answers 403 to a request with a foreign Origin or an unknown Host.

FAQ

Can a website really connect to a server on localhost?

Yes. A page can send requests and open WebSockets to 127.0.0.1 from your browser. It usually cannot read HTTP responses because of the same-origin policy, but WebSockets are not covered by CORS, and DNS rebinding can make the page same-origin with your local server.

Is binding to 127.0.0.1 enough to secure a dev server?

No. It stops other machines, not other web pages in your browser. Add a Host allowlist against DNS rebinding, an Origin allowlist for browser requests and a random session token on every request.

What is cross-site WebSocket hijacking?

A malicious page opens a WebSocket to a server that relies on cookies or network location for trust and never checks the Origin header. The socket then runs with the victim's access. The fix is an exact Origin allowlist plus a token the attacker's page cannot know.

See the AI coding agents use case and the WebSocket detection docs, or start a 14-day trial. Related: MCP servers are the new attack surface and writing a secure MCP server.