robots.txt enforcement bypass via HTTP redirects in mcp-server-fetch
Description
mcp-server-fetch checks robots.txt for the URL the model asks for, then lets httpx follow redirects without checking robots.txt again. A page on a host that allows autonomous fetching can redirect to a URL that robots.txt forbids, on another host or on the same one, and the server fetches it and returns the content to the model. This is the default configuration and applies to fetches made through the fetch tool, which is where the README says robots.txt is obeyed. The attacker needs the model to fetch a URL they control, or a site that redirects on its own.
Details
robots.txt is checked once, for the URL passed to the fetch tool, in the tool handler (server.py#L452-L465):
page_url = str(url)
if not ignore_robots_txt:
await check_may_autonomously_fetch_url(
page_url, user_agent_autonomous, proxy_url, allow_private_ips
)
content, prefix = await fetch_url(
page_url,
user_agent_autonomous,
force_raw=raw,
proxy_url=proxy_url,
allow_private_ips=allow_private_ips,
)check_may_autonomously_fetch_url (L247-L293) downloads /robots.txt from that URL's host and calls can_fetch() for that one URL. fetch_url (L296-L317) then fetches it with redirects on:
async with make_client(proxy_url) as client:
if not allow_private_ips:
client.event_hooks = {"request": [_refuse_private_destination]}
try:
response = await client.get(
url,
follow_redirects=True,
headers={"User-Agent": user_agent},
timeout=30,
)httpx follows the 3xx chain inside that get(). The only thing that runs per hop is _refuse_private_destination (unless --allow-private-ips is set), the private-address hook from #5033. Nothing reads robots.txt for a hop's URL, so the server fetches wherever the chain ends. robots.txt belongs to one origin (RFC 9309 section 2.3 gives its URI as scheme:[//authority]/robots.txt), which leaves two cases open:
- The requested URL is on a host that allows it (or has no robots.txt) and redirects to another host whose robots.txt says
Disallow: /, or answers 401/403, which this server treats as "not allowed" (L274-L277). The second host's robots.txt is never requested. - The requested URL redirects within the same host to a path that the host's own robots.txt disallows. The rules were downloaded, but
can_fetch()only ran for the original path.
The private-address guard still runs on every hop, so this is only about robots.txt.
The server.py in the PyPI 2026.10.19 wheel is identical to this commit's. The same script also reproduces on 2026.8.18, 2025.4.7, 2025.1.14 and 0.6.2, with --allow-private-ips dropped (it doesn't exist before 2026.10.10) and isError for is_error (SDK 1.x client). The last three ran with mcp==1.9.0 and pydantic==2.10.6. On 0.6.2 and 2025.1.14 the control calls fail with an unrelated McpError constructor error under that SDK and return no content.
The existing test
tests/test_protocol.py pins the current behaviour, inside test_allow_private_ips_follows_redirect_to_private_address (L845-L861):
# robots.txt is only consulted for the original host, never the target.
assert web.urls() == [ROBOTS, PAGE, metadata, metadata]I read that as a record of what the code does today, in a test whose subject is --allow-private-ips, not as a decision that redirects are exempt. The line came in with #4971 (merged 2026-10-04), whose description lists it under "Characterized (pinned, not fixed)" and says each pinned item carries a comment "so the fixing PR knows which assertion to change". There the item is filed under #4838, and #5033, which closed #4838, only dealt with the private-address half.
The README's robots.txt section (README.md#L168-L172) says:
By default, the server will obey a websites robots.txt file if the request came from the model (via a tool), but not if the request was user initiated (via a prompt).
and nothing about redirects, while the CAUTION at the top of the same file (L14) says the private-address guard "checks every redirect hop the same way". SECURITY.md (L63-L65) names robots.txt among the boundaries a server claims to enforce: "A way around a boundary a server claims to enforce (its allowed directories, the client's Roots, or robots.txt, for example) is a vulnerability". From the site's side, a model-initiated request for its URL is an autonomous fetch however the request got there. If redirects are meant to be exempt, the README should say so; if not, that assertion is what changes, and the patch updates it.
Related work
#4838 was fixed by #5033, which registered _refuse_private_destination as a request hook so every hop goes through the address guard. robots.txt was not part of that change. Three older open PRs for the same address problem (#4497, #4773, #4803) replace automatic redirects with a manual loop; none of them checks robots.txt inside the loop either. I found no issue, PR or published advisory in this repo about robots.txt and redirects. #5197 is about 5xx responses on robots.txt, a different bug.
Suggested fix
Check robots.txt in a second request hook, for every request after the first (the handler has already checked the first one), and only when the caller asked for robots.txt enforcement:
diff --git a/src/fetch/src/mcp_server_fetch/server.py b/src/fetch/src/mcp_server_fetch/server.py
index bdac272..9618251 100644
--- a/src/fetch/src/mcp_server_fetch/server.py
+++ b/src/fetch/src/mcp_server_fetch/server.py
@@ -299,15 +299,31 @@ async def fetch_url(
force_raw: bool = False,
proxy_url: str | None = None,
allow_private_ips: bool = False,
+ check_robots_txt: bool = False,
) -> Tuple[str, str]:
"""
Fetch the URL and return the content in a form ready for the LLM, as well as a prefix string with status information.
"""
from httpx import HTTPError
+ initial_url = str(httpx.URL(url))
+
+ async def _check_redirect_robots(request: httpx.Request) -> None:
+ # The caller has already checked robots.txt for the requested URL;
+ # this checks the URL of every redirect hop after it.
+ if str(request.url) != initial_url:
+ await check_may_autonomously_fetch_url(
+ str(request.url), user_agent, proxy_url, allow_private_ips
+ )
+
async with make_client(proxy_url) as client:
+ hooks = []
if not allow_private_ips:
- client.event_hooks = {"request": [_refuse_private_destination]}
+ hooks.append(_refuse_private_destination)
+ if check_robots_txt:
+ hooks.append(_check_redirect_robots)
+ if hooks:
+ client.event_hooks = {"request": hooks}
try:
response = await client.get(
url,
@@ -462,6 +478,7 @@ def create_server(
force_raw=raw,
proxy_url=proxy_url,
allow_private_ips=allow_private_ips,
+ check_robots_txt=not ignore_robots_txt,
)
original_length = len(content)
if start_index >= original_length:The fetch prompt and --ignore-robots-txt don't pass the flag, so they behave as before. Behaviour change to be aware of: one extra robots.txt request per redirect hop, same-host hops included (I didn't add caching, to keep the diff small), and a redirect target whose robots.txt can't be fetched or answers 401/403 now fails the fetch, the same way it already does for the requested URL.
The full patch also adds four tests to tests/test_protocol.py and changes the assertion quoted above. I can post it here in full or open a PR against the private fork.
Proof of concept
Tested at 51b6382a3e827aceb6bce430b1208d69b93d95ea (mcp-server-fetch 2026.10.19) on Linux with Python 3.11.14, mcp 2.3.0 and httpx 0.27.2 (the last two as locked in src/fetch/uv.lock). The server is started as python -m mcp_server_fetch --allow-private-ips, with no other arguments and no proxy. robots.txt enforcement is on (the default); --allow-private-ips is only there because the two test sites listen on 127.0.0.1. The client is the Python MCP SDK's stdio client, not a desktop client.
git clone https://github.com/modelcontextprotocol/servers.git
cd servers && git checkout 51b6382a3e827aceb6bce430b1208d69b93d95ea
cd src/fetch && uv sync --frozen
# save the script below as poc_redirect_robots.py in this directory, then:
uv run --frozen python poc_redirect_robots.pyThe script starts two local sites on different ports (so they are different origins). Site B's robots.txt disallows everything. Site A's disallows /private; A has /go, which redirects to B, and /public, which redirects to A's own /private/report. It calls the fetch tool on B and on A's /private/report directly (controls), then on the two redirecting URLs.
"""mcp-server-fetch: robots.txt is checked for the requested URL, not for redirect targets.
Two local sites on different ports (so two origins). Run from an environment where
mcp-server-fetch is installed: python poc_redirect_robots.py [server args...]
With no arguments the server is started with --allow-private-ips (needed only
because the sites are on 127.0.0.1).
"""
import asyncio
import os
import sys
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from threading import Thread
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
HITS = [] # "site path" for every request the two sites receive
def serve(name, routes):
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
HITS.append(f"{name}{self.path}")
status, headers, body = routes(self.path)
self.send_response(status)
self.send_header("Content-Type", "text/plain")
for k, v in headers.items():
self.send_header(k, v)
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *args):
pass
httpd = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
Thread(target=httpd.serve_forever, daemon=True).start()
return httpd.server_port
# Site B disallows everything.
def site_b(path):
if path == "/robots.txt":
return 200, {}, b"User-agent: *\nDisallow: /\n"
if path == "/secret":
return 200, {}, b"SECRET-FROM-B"
return 404, {}, b"not found"
port_b = serve("B", site_b)
# Site A allows everything except /private, and has two redirects.
def site_a(path):
if path == "/robots.txt":
return 200, {}, b"User-agent: *\nDisallow: /private\n"
if path == "/go": # cross-origin: -> site B
return 302, {"Location": f"http://127.0.0.1:{port_b}/secret"}, b""
if path == "/public": # same origin: -> a disallowed path
return 302, {"Location": "/private/report"}, b""
if path == "/private/report":
return 200, {}, b"PRIVATE-REPORT"
return 404, {}, b"not found"
port_a = serve("A", site_a)
CASES = [
# (label, url, redirects?)
("control B/secret (robots Disallow: /)", f"http://127.0.0.1:{port_b}/secret", False),
("control A/private/report (robots Disallow: /private)", f"http://127.0.0.1:{port_a}/private/report", False),
("redirect A/go -> B/secret", f"http://127.0.0.1:{port_a}/go", True),
("redirect A/public -> A/private/report", f"http://127.0.0.1:{port_a}/public", True),
]
async def main():
args = sys.argv[1:] or ["--allow-private-ips"]
params = StdioServerParameters(
command=sys.executable, args=["-m", "mcp_server_fetch", *args]
)
leaked = False
with open(os.devnull, "w") as devnull:
async with stdio_client(params, errlog=devnull) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
for label, url, is_redirect in CASES:
result = await session.call_tool("fetch", {"url": url})
text = result.content[0].text
if not result.is_error:
outcome = "FETCHED"
elif "robots.txt" in text and "not allowed" in text:
outcome = "BLOCKED by robots.txt"
else:
outcome = f"ERROR: {text[:80]}"
print(f"{label:58} -> {outcome}")
if not result.is_error:
print(f" {text.splitlines()[-1]}")
leaked |= is_redirect and not result.is_error
print("requests seen by the sites:", HITS)
print("VULNERABLE" if leaked else "OK: redirect targets are checked")
sys.exit(1 if leaked else 0)
asyncio.run(main())Expected: all four calls refused. Actual at that commit:
control B/secret (robots Disallow: /) -> BLOCKED by robots.txt
control A/private/report (robots Disallow: /private) -> BLOCKED by robots.txt
redirect A/go -> B/secret -> FETCHED
SECRET-FROM-B
redirect A/public -> A/private/report -> FETCHED
PRIVATE-REPORT
requests seen by the sites: ['B/robots.txt', 'A/robots.txt', 'A/robots.txt', 'A/go', 'B/secret', 'A/robots.txt', 'A/public', 'A/private/report']
VULNERABLEIn the request log, B's robots.txt is requested for the direct call only; after A/go the server goes straight to B/secret. With the patch from the Details section applied the script exits 0:
control B/secret (robots Disallow: /) -> BLOCKED by robots.txt
control A/private/report (robots Disallow: /private) -> BLOCKED by robots.txt
redirect A/go -> B/secret -> BLOCKED by robots.txt
redirect A/public -> A/private/report -> BLOCKED by robots.txt
requests seen by the sites: ['B/robots.txt', 'A/robots.txt', 'A/robots.txt', 'A/go', 'B/robots.txt', 'A/robots.txt', 'A/public', 'A/robots.txt']
OK: redirect targets are checkedThe same scenario is also in the patch as in-process tests, which run with the default private-address guard on (no --allow-private-ips). The fetch suite is 145 passed at HEAD and 149 with the patch. With only the test changes applied on HEAD, 4 tests fail: three of the new ones and the updated assertion (the fourth new test guards --ignore-robots-txt). ruff check, ruff format --check and pyright are clean with the patch.
Impact
Anyone running mcp-server-fetch with robots.txt enforcement on (the default), for fetches the model makes through the fetch tool. The fetch prompt skips robots.txt by design and is not affected.
The attacker needs a URL the model will fetch and that the robots.txt check lets through: a page they host on a host with no robots.txt or a permissive one, answering with a redirect. A site can also trip it without any attacker, with an ordinary redirect from an allowed path to a disallowed one. In both cases the final URL is never checked against the robots.txt of the host it ends up on.
What they get is content from URLs whose site asked autonomous agents to stay away, including hosts whose robots.txt answers 401/403. I'm not claiming access to anything non-public: robots.txt is a request to crawlers, not access control, and the private-address guard still applies on every hop. The harm is to the person running the server, who has been told robots.txt is obeyed, and to the site owners whose policy gets ignored.