cd /news/ai-agents/your-mcp-server-s-fetch-url-tool-is-… · home › topics › ai-agents › article
[ARTICLE · art-174161] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Your MCP server's fetch_url tool is an SSRF hole — the guard layer most templates skip

A developer built and is selling a minimal stdio MCP server kit in which the SSRF and path-traversal guard layer is the core feature rather than an afterthought. The kit's fetch_url tool resolves hostnames via getaddrinfo before connecting and validates every returned address against private, loopback, link-local, multicast and reserved ranges, while read_file resolves real paths, rejects '..' escapes, refuses symlinks pointing outside the allowed root and caps file size. The developer acknowledges a residual DNS-rebinding gap between the resolve-time check and the actual connection, recommending egress pinning or connect-time re-validation for adversarial environments, and ships a five-case unittest suite that stands up a real localhost HTTP server to prove fetch_url refuses to touch it.

recommendation

Validate every resolved address at connect time and pin egress, because a resolve-time-only check leaves a DNS-rebinding gap between validation and connection.

more in playbook: Securing agents and AI tools
by read2 min views3 publishedNov 22, 2026

Every "build an MCP server in 50 lines" tutorial ships the same two tools: fetch_url and read_file. Almost none of them guard them. That means the demo server you copied into your client config last weekend will happily fetch http://169.254.169.254/latest/meta-data/ on EC2, or read ../../.ssh/id_rsa if you pointed read_file at the wrong root.

I got burned enough by config footguns to start selling lint kits, so when MCP tooling took off I built the thing I actually wanted: a minimal stdio MCP server where the guard layer is the product, not an afterthought.

fetch_url looks harmless — it's a GET request. But an MCP client will call it with whatever URL the model produces, and models produce URLs from tool output, docs, and — increasingly — attacker-controlled content. That's a Server-Side Request Forgery primitive handed to an LLM:

http://127.0.0.1:8080/admin — internal serviceshttp://169.254.169.254/ — cloud metadata credentialshttp://[::1]/, 10.x, 192.168.x, link-local, multicast — the whole private range file:///etc/passwd — scheme confusion if you don't whitelist read_file is the quieter one: path traversal (../../), symlink escapes, and unbounded reads that will happily slurp a 4GB log into the model's context.

The naive fix — a regex blocklist of "localhost" and "127.0.0.1" — misses decimal IP notation (2130706433), hex ( 0x7f000001), IPv6 loopback, DNS names that resolve to private addresses, and every redirect target. The check that works resolves the hostname via getaddrinfo before connecting and validates every returned address against private/loopback/link-local/multicast/reserved ranges.

For read_file: resolve the real path, reject .. escapes, refuse symlinks that point outside the allowed root, cap file size. I want to be straight about the residual gap, because it's the one that matters in hostile environments: checking the resolved IP and then connecting are two different moments. A hostname can pass the check and re-resolve to a private IP before the connection opens — DNS rebinding. For most internal tooling the resolve-time check is enough; for anything facing adversarial input you pin egress or re-validate at connect time. Any vendor claiming "SSRF-proof" without mentioning this is selling something.

The thing I cared about most: the guards should be tested, not asserted. The kit ships a 5-case unittest suite — including one that stands up a real localhost HTTP server and proves fetch_url refuses to touch it. If you add tools, the suite shows you exactly what a guard test looks like.

What's inside:

server/mcp_server.py — dependency-free JSON-RPC 2.0 over stdio (Python 3.8+, no FastMCP, no Node)tests/test_server.py — 5 tests, all passingexamples/client-config.json — Claude Desktop / Cursor stdio snippetDEPLOY.md + Dockerfile — because "works on my machine" isn't a deployment story It's a template, not audited infrastructure — tools you add inherit nothing automatically, and it covers initialize/ping/tools only (no resources, prompts, or sampling). $19, BTC or EVM checkout:

[https://wesleygitari2-cloud.github.io/nexus-store-redirect/p/mcp-secure-server-kit](https://wesleygitari2-cloud.github.io/nexus-store-redirect/p/mcp-secure-server-kit)

If you just want to poke at the guard behavior first, the test file is the fastest way — it demonstrates the SSRF block live without installing anything.
── more in #ai-agents 4 stories · sorted by recency
── more on @mcp 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/your-mcp-server-s-fe…] indexed:0 read:2min 2026-11-22 · —