{"slug": "your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates", "title": "Your MCP server's fetch_url tool is an SSRF hole — the guard layer most templates skip", "summary": "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.", "body_md": "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.\n\nI 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.\n\n`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:\n\n`http://127.0.0.1:8080/admin` — internal services`http://169.254.169.254/` — cloud metadata credentials`http://[::1]/`, `10.x`, `192.168.x`, link-local, multicast — the whole private range` file:///etc/passwd` — scheme confusion if you don't whitelist\n`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.\n\nThe 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.\n\nFor `read_file`: resolve the real path, reject `..` escapes, refuse symlinks that point outside the allowed root, cap file size.\n\nI 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.\n\nThe 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.\n\nWhat's inside:\n\n`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 passing`examples/client-config.json` — Claude Desktop / Cursor stdio snippet`DEPLOY.md` + `Dockerfile` — because \"works on my machine\" isn't a deployment story\nIt'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:\n\n[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)\n\nIf 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.", "url": "https://wpnews.pro/news/your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates", "canonical_source": "https://dev.to/nexusfoundry/your-mcp-servers-fetchurl-tool-is-an-ssrf-hole-the-guard-layer-most-templates-skip-58nl", "published_at": "2026-11-22 12:09:16+00:00", "updated_at": "2026-11-22 12:12:37.452801+00:00", "lang": "en", "topics": ["ai-agents", "agent-protocols", "ai-safety", "ai-tools", "developer-tools"], "entities": ["MCP", "Claude Desktop", "Cursor", "Python", "Docker"], "also_reported_by": [], "takeaway": "Resolve a fetch_url hostname with getaddrinfo before connecting and validate every returned address against private, loopback, link-local, multicast and reserved ranges, since blocklists miss decimal, hex and IPv6 loopback forms and redirect targets.", "recommendation": {"advice": "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.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates", "markdown": "https://wpnews.pro/news/your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates.md", "text": "https://wpnews.pro/news/your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates.txt", "jsonld": "https://wpnews.pro/news/your-mcp-server-s-fetch-url-tool-is-an-ssrf-hole-the-guard-layer-most-templates.jsonld"}}