CVE-2026–42559: DNS Rebinding in rmcp’s Streamable HTTP Server Transport
Before version 1.4.0, the Streamable HTTP transport in rmcp never checked the incoming Host header, so a malicious web page could use DNS rebinding to reach a locally running MCP server. An attacker could then list and invoke the server's tools, potentially leading to file writes, shell execution or full code execution on the victim's machine.
Published on medium.com
Anthropic Claude
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
rmcp is Anthropic's official Rust SDK for the Model Context Protocol (MCP). It implements the transport layer between LLM clients and the MCP servers that expose tools to them. Servers built with this SDK almost always run on a developer's own machine ([redacted]), exposing powerful tools such as filesystem access, shell execution and browser control over that loopback interface.
The component at issue is the Streamable HTTP server transport. Prior to version 1.4.0 it never validated the incoming Host header at all. That single missing check, combined with a DNS rebinding attack, is enough for a malicious web page to invoke arbitrary tools on a locally running MCP server the moment a victim opens it in a browser. The issue is tracked as GitHub security advisory GHSA-89vp-x53w-74fx.

Setup
No accounts, credentials or special roles are needed. The preconditions are:
- A victim runs an MCP server built with
rmcpbefore 1.4.0, listening on loopback ([redacted]). - The server exposes tools with real capability: filesystem, shell, browser automation, language servers.
- The victim opens an attacker-controlled web page in a browser on the same machine.
- The attacker controls a domain with a very short DNS TTL.
The server runs with the user's own privileges, which is what makes the reachable tool set interesting.
Finding it
A browser's Same-Origin Policy (SOP) decides trust based on a domain name, while the actual destination of a request is whatever IP DNS happens to resolve that name to at that moment. DNS rebinding exploits exactly this gap. The Streamable HTTP transport implicitly trusted any request that reached the loopback socket, without ever asking who the request was actually from.
Exploitation
Step 1: short TTL on an attacker domain
The attacker sets a very short DNS TTL (for example 1 second) on a domain they control (attacker.example).
Step 2: first resolution is legitimate
When the victim visits the domain, the first DNS answer is a legitimate public IP, so the page loads normally.
Step 3: rebind to loopback
Once the TTL expires, in-page JavaScript re-requests the same domain, and this time the attacker's DNS answers with [redacted] (or another private address).
Step 4: SOP is satisfied
From the browser's perspective it is still the same origin (attacker.example), so SOP is satisfied, but the TCP connection now actually goes to the victim's own machine.
Step 5: the request reaches the MCP server
The HTTP request still carries Host: attacker.example, but the server receiving it is the local MCP server started via rmcp. If the server had simply checked the Host header against a list of names it recognises (localhost, [redacted], etc.) and rejected anything else, the attack would be stopped right at this step. Prior to the patch, rmcp had no such check at all.

Root cause
Per the advisory, pre-1.4.0 versions of the Streamable HTTP server went straight from protocol-version checks (MCP-Protocol-Version), session-ID lookup and JSON-RPC parsing into request handling. There was no step anywhere in the pipeline that compared Host or Origin against anything. Conceptually, the handler looked like this:
pub async fn handle<B>(&self, request: Request<B>) -> Response<BoxBody<Bytes, Infallible>>where B: Body + Send + 'static, B::Error: Display,{ let method = request.method().clone(); let result = match method { Method::POST => self.handle_post(request).await, Method::GET => self.handle_get(request).await, Method::DELETE => self.handle_delete(request).await, _ => , }; }
The server only asked whether a request conformed to the MCP protocol, never who the request was actually from. It implicitly trusted any request that reached the loopback socket, and DNS rebinding is precisely the technique that breaks the assumption that "arrived on loopback" and "the Host header names the real caller" are the same thing.
Impact
Per the advisory, the blast radius is broad. An attacker can:
- Enumerate (
tools/list) and invoke (tools/call) every tool the server exposes. - Read resources, prompts and any state reachable through the session.
- Trigger side effects the tools support: file writes, shell execution, arbitrary outbound API calls.
Because MCP servers typically run with the user's own privileges and often expose developer tooling (filesystem, shell, browser automation, language servers), the practical impact can extend to full code execution on the victim's machine.
Fix
The fix has three parts: a secure-by-default allowlist for hostnames, a validate_dns_rebinding_headers gate that every request now passes through, and optional Origin validation as defence in depth. The deployed source is in tower.rs.
1) A secure default: StreamableHttpServerConfig
pub struct StreamableHttpServerConfig { pub allowed_hosts: Vec<String>, pub allowed_origins: Vec<String>, validate_empty_origin_allowlist: bool, }impl Default for StreamableHttpServerConfig { fn default() -> Self { Self { allowed_hosts: vec!["localhost".into(), "[redacted]".into(), "::1".into()], allowed_origins: vec![], validate_empty_origin_allowlist: false, } }}
The Default impl is the load-bearing part. Just calling StreamableHttpServerConfig::default(), with no extra configuration, populates allowed_hosts with localhost, [redacted] and ::1. That flip from insecure by default to secure by default is the design philosophy behind the patch. A developer deploying publicly has to explicitly widen it via with_allowed_hosts(["mcp.example.com"]), and turning validation off entirely requires an equally explicit disable_allowed_hosts().
impl StreamableHttpServerConfig { pub fn with_allowed_hosts( mut self, allowed_hosts: impl IntoIterator<Item = impl Into<String>>, ) -> Self { self.allowed_hosts = allowed_hosts.into_iter().map(Into::into).collect(); self } pub fn disable_allowed_hosts(mut self) -> Self { self.allowed_hosts.clear(); self }}
An empty allowed_hosts vector is exactly what host_is_allowed treats as "allow everything", so disable_allowed_hosts() is a literal opt-out of the whole protection.
2) Enforcement at the entry point
pub async fn handle<B>(&self, request: Request<B>) -> Response<BoxBody<Bytes, Infallible>>where B: Body + Send + 'static, B::Error: Display,{ if let Err(response) = validate_dns_rebinding_headers(request.uri(), request.headers(), &self.config) { return response.into_response(); } ...}
Placement is the key detail: validate_dns_rebinding_headers runs at the very top of handle(), ahead of both method dispatch and session lookup. A failed check returns immediately, before the server ever touches session state or parses the JSON-RPC body, shrinking the attack surface to before the request reaches any internal logic at all.
3) Parsing the Host header: parse_host_header
fn parse_host_header(uri: &http::Uri, headers: &HeaderMap) -> HttpResult<NormalizedAuthority> { if let Some(host) = headers.get(http::header::HOST) { let host_str = host .to_str() .map_err(|_| bad_request_response("Bad Request: Invalid Host header encoding"))?; let authority = http::uri::Authority::try_from(host_str) .map_err(|_| bad_request_response("Bad Request: Invalid Host header"))?; return Ok(normalize_authority(authority.host(), authority.port_u16())); } let authority = uri.authority().ok_or_else(|| { bad_request_response("Bad Request: missing Host header") })?; Ok(normalize_authority(authority.host(), authority.port_u16()))}
The HTTP/2 fallback matters. HTTP/1.1 names the target via the Host: header, but HTTP/2 replaces it with the :authority pseudo-header on the request line, and some middleware (for example axum::Router::nest) can strip the Host header hyper synthesises from it during routing. So instead of "no Host header means allow", the code falls back to the URI's authority, meaning a missing header still gets checked against something and is never silently skipped.
4) Normalising the host: case and IPv6 brackets
fn normalize_host(host: &str) -> String { host.trim_matches('[') .trim_matches(']') .to_ascii_lowercase()}struct NormalizedAuthority { host: String, port: Option<u16>,}fn normalize_authority(host: &str, port: Option<u16>) -> NormalizedAuthority { NormalizedAuthority { host: normalize_host(host), port }}
DNS names are case-insensitive (Localhost and localhost are the same host), and IPv6 literals appear bracketed in a URI ([::1]). Without normalising both, an attacker could try bypassing the allowlist comparison with variants like Host: LOCALHOST or Host: [::1]. normalize_host handles both in one place so every later comparison can be a plain string ==.
5) Allowlist matching: host_is_allowed
fn parse_allowed_authority(allowed: &str) -> Option<NormalizedAuthority> { let allowed = allowed.trim(); if allowed.is_empty() { return None; } if let Ok(authority) = http::uri::Authority::try_from(allowed) { return Some(normalize_authority(authority.host(), authority.port_u16())); } Some(normalize_authority(allowed, None))}fn host_is_allowed(host: &NormalizedAuthority, allowed_hosts: &[String]) -> bool { if allowed_hosts.is_empty() { return true; } allowed_hosts .iter() .filter_map(|allowed| parse_allowed_authority(allowed)) .any(|allowed| { allowed.host == host.host && match allowed.port { Some(port) => host.port == Some(port), None => true, } })
Each allowlist entry ("example.com", "example.com:8080", etc.) is parsed into a host/port pair before comparison. An entry with no port ("localhost") matches that host on any port; an entry with a port ("example.com:8080") only matches that exact port. This lets a developer keep localhost wide open (any port) during development while locking a production deployment down to example.com:443.
6) The gate itself: validate_dns_rebinding_headers
fn validate_dns_rebinding_headers( uri: &http::Uri, headers: &HeaderMap, config: &StreamableHttpServerConfig,) -> HttpResult<()> { let host = parse_host_header(uri, headers)?; if !host_is_allowed(&host, &config.allowed_hosts) { tracing::warn!( host = ?host, "rejected request with disallowed Host header (possible DNS rebinding attempt)", ); return Err(forbidden_response("Forbidden: Host header is not allowed").into()); } validate_origin_header(headers, config)?; Ok(())}
This single function is the fix. It parses Host, and if it is not on the allowlist it returns 403 Forbidden immediately, logging a tracing::warn! that flags the possibility of a DNS rebinding attempt. Step 5's request arriving with Host: attacker.example is stopped right here, because attacker.example is not in the default allowlist (localhost, [redacted], ::1).
7) Origin validation: defence in depth
fn validate_origin_header( headers: &HeaderMap, config: &StreamableHttpServerConfig,) -> HttpResult<()> { if !config.validate_empty_origin_allowlist && config.allowed_origins.is_empty() { return Ok(()); } let Some(origin_header) = headers.get(http::header::ORIGIN) else { return Ok(()); }; let origin_str = origin_header .to_str() .map_err(|_| forbidden_response("Forbidden: Invalid Origin header encoding"))?; let origin = parse_origin_value(origin_str) .ok_or_else(|| forbidden_response("Forbidden: Invalid Origin header"))?; if !origin_is_allowed(&origin, &config.allowed_origins) { tracing::warn!(origin = ?origin, "rejected request with disallowed Origin header"); return Err(forbidden_response("Forbidden: Origin header is not allowed").into()); } Ok(())}
As the advisory states explicitly, the root cause here is purely the missing Host check. Origin validation is not required to stop this specific attack, since a browser cannot forge the Host header it sends to the rebound target; the Host allowlist alone is sufficient. Origin checking was added anyway as defence in depth: by default, an empty allowed_origins list skips validation entirely (preserving backward compatibility), while calling enforce_origin_validation() switches to a strict mode that rejects any request carrying an Origin header, even with an empty allowlist.
Remediation
- Upgrade to rmcp 1.4.0 or later. The default configuration alone already blocks any request whose
Hostis not a loopback address. - If you are deploying an MCP server under a public domain, register it explicitly:
StreamableHttpServerConfig::default().with_allowed_hosts(["mcp.example.com"]). - If upgrading is not immediately possible, put a reverse proxy (nginx, Caddy, etc.) in front that rejects requests with an unexpected
Hostheader, and do not bind the MCP server directly to[redacted]. - Avoid
disable_allowed_hosts(), which reverts you to the pre-patch, unprotected state, unless an upstream proxy is already validatingHoston your behalf.
Variants to test
- Other loopback-bound developer servers. Look for local services that expose powerful actions over HTTP and never compare
Hostagainst a known name. A positive result is a request withHost: attacker.examplereaching the handler and returning a normal response rather than403. - Case and bracket variants. Send
Host: LOCALHOSTandHost: [::1]against a server that does have an allowlist. A positive result is either variant being accepted or rejected inconsistently with its lowercase or unbracketed form, which points to missing normalisation. - Missing
Hoston HTTP/2. Route a request through middleware that strips the synthesisedHostheader. A positive result is the server treating the absent header as trusted instead of falling back to the URI authority. - Port-scoped allowlist entries. Configure an entry with an explicit port and probe other ports on the same host. A positive result is a match on a port that should not have been allowed.
- Empty allowlist semantics. Check what an empty
allowed_hostslist does. A positive result is an empty list being interpreted as allow-all rather than deny-all. Originenforcement mode. Withenforce_origin_validation()enabled, send requests with noOrigin, a malformedOriginand a disallowedOrigin. A positive result is any of these reaching the handler.
What happened, in plain words
Anthropic publishes a toolkit called rmcp. It is written in a programming language called Rust, and it is the official building kit for something called the Model Context Protocol, or MCP. MCP is a way for an AI assistant (the "client") to talk to small helper programs (the "servers") that give it abilities: reading files, running commands, driving a browser. rmcp is the part that carries the messages back and forth between the two, which people call the transport layer.
These MCP servers almost always run on the same computer as the person using them, at the address [redacted]. That address is a special one: it always means "this very machine", and nothing outside it can reach it directly. Because the server sits on the user's own machine, it runs with the user's own permissions, and the tools it offers are powerful: filesystem access, shell execution, browser control.
Before version 1.4.0, the part of rmcp that accepts web requests, the Streamable HTTP server transport, never looked at one particular piece of every request: the Host header. A header is a small labelled line of text that travels with a web request, like the address block on an envelope. The Host header says which website name the request was aimed at.
That one missing check, combined with a trick called DNS rebinding, is enough for a malicious web page to call any tool on a local MCP server the moment the victim opens that page in a browser. The problem is tracked as GitHub security advisory GHSA-89vp-x53w-74fx.

The pieces you need to know first
Before the attack makes sense, four everyday ideas need to be clear.
An API is a way for one program to ask another program to do something, without a human clicking anything. Think of a restaurant: you do not walk into the kitchen, you order from a menu, and the kitchen does the work. An API is the menu and the waiter. An MCP server is a small restaurant of this kind, and its menu is the list of tools it offers.
A DNS name is a human-friendly label such as example.com. Computers do not actually use names to find each other; they use IP addresses, which are strings of numbers. DNS is the phone book that turns a name into a number. When you type a name into a browser, the browser asks DNS "what number is this?" and then connects to the answer.
A TTL (time to live) is how long a DNS answer may be kept and reused before the browser has to ask again. A long TTL means the answer is trusted for a long time. A very short TTL, one second for instance, means the browser will ask again almost immediately, and it may get a different answer.
The Same-Origin Policy (SOP) is a safety rule built into every browser. It says that a page loaded from one website name may not freely read data from a different website name. The browser decides what counts as "the same" by looking at the name, not at the number the name resolved to. This rule is what normally stops a random web page from talking to your bank, or to a program on your own computer.
Setting the scene
No accounts, passwords or special roles are involved. The conditions for the attack are:
- A victim runs an MCP server built with
rmcpbefore 1.4.0, listening on loopback ([redacted]). - The server exposes tools with real capability: filesystem, shell, browser automation, language servers.
- The victim opens an attacker-controlled web page in a browser on the same machine.
- The attacker controls a domain with a very short DNS TTL.
The server runs with the user's own privileges, which is what makes the reachable tool set interesting. If the server can write files, the attacker can write files, because the server is doing the work on the attacker's behalf.
Finding it
A browser's Same-Origin Policy decides trust based on a domain name, while the actual destination of a request is whatever IP address DNS happens to resolve that name to at that moment. DNS rebinding exploits exactly this gap. The Streamable HTTP transport implicitly trusted any request that reached the loopback socket, without ever asking who the request was actually from.
In other words: the server checked that the request had arrived on the private door of the machine, and assumed that anything arriving there must be friendly. That assumption is the bug.
How the attack works, step by step
Step 1: short TTL on an attacker domain
The attacker sets a very short DNS TTL (for example 1 second) on a domain they control (attacker.example).
Why: the attacker wants the browser to ask DNS again very soon, so that the answer can be changed. A long TTL would freeze the first answer for hours.
Step 2: first resolution is legitimate
When the victim visits the domain, the first DNS answer is a legitimate public IP, so the page loads normally.
Why: the page has to load from a real, harmless server first. That server delivers the JavaScript that will later do the damage. If the first answer pointed at the victim's own machine, there would be no page to run.
Step 3: rebind to loopback
Once the TTL expires, in-page JavaScript re-requests the same domain, and this time the attacker's DNS answers with [redacted] (or another private address).
Why: the script is still asking for the same name, but the phone book now gives a different number. The name has not changed; the destination has.
Step 4: SOP is satisfied
From the browser's perspective it is still the same origin (attacker.example), so SOP is satisfied, but the TCP connection now actually goes to the victim's own machine.
Why: the browser compares names, and the name is unchanged. The safety rule sees no crossing of boundaries, so it lets the request through. The connection, however, lands on the victim's own computer.
Step 5: the request reaches the MCP server
The HTTP request still carries Host: attacker.example, but the server receiving it is the local MCP server started via rmcp. If the server had simply checked the Host header against a list of names it recognises (localhost, [redacted], etc.) and rejected anything else, the attack would be stopped right at this step. Prior to the patch, rmcp had no such check at all.
Why this matters: the request itself still says, in its Host header, that it is aimed at attacker.example. The local server could have noticed that this name is not one of its own and refused. It did not look.

The root cause
Per the advisory, pre-1.4.0 versions of the Streamable HTTP server went straight from protocol-version checks (MCP-Protocol-Version), session-ID lookup and JSON-RPC parsing into request handling. There was no step anywhere in the pipeline that compared Host or Origin against anything.
A session ID is a short label the server hands out so it can remember which conversation a request belongs to, a bit like a coat-check ticket. JSON-RPC is the message format MCP uses: a structured text message that says "call this tool with these arguments". The server checked the message format, found the right session, and then did the work. It never asked where the request came from.
Conceptually, the handler looked like this:
pub async fn handle<B>(&self, request: Request<B>) -> Response<BoxBody<Bytes, Infallible>>where B: Body + Send + 'static, B::Error: Display,{ let method = request.method().clone(); let result = match method { Method::POST => self.handle_post(request).await, Method::GET => self.handle_get(request).await, Method::DELETE => self.handle_delete(request).await, _ => , }; }
Line by line, in plain words:
pub async fn handle<B>(&self, request: Request<B>) -> Response<BoxBody<Bytes, Infallible>>declares the function that receives every incoming web request and produces a reply.asyncmeans it can wait for slow work without blocking everything else.where B: Body + Send + 'static, B::Error: Display,lists requirements on the request body type: it must be a body, it must be safe to move between threads, and its errors must be printable.let method = request.method().clone();reads the HTTP method, the verb of the request (POST, GET, DELETE), and keeps a copy.let result = match method {starts choosing what to do based on that verb.Method::POST => self.handle_post(request).await,sends POST requests, which usually carry data, to the POST handler.Method::GET => self.handle_get(request).await,sends GET requests, which usually ask for data, to the GET handler.Method::DELETE => self.handle_delete(request).await,sends DELETE requests to the DELETE handler._ => ,is the catch-all branch for any other verb.
The important thing is what is absent: nowhere in this function is the Host header read, and nowhere is it compared with anything. The server only asked whether a request conformed to the MCP protocol, never who the request was actually from. It implicitly trusted any request that reached the loopback socket, and DNS rebinding is precisely the technique that breaks the assumption that "arrived on loopback" and "the Host header names the real caller" are the same thing.
What an attacker could do
Per the advisory, the blast radius is broad. An attacker can:
- Enumerate (
tools/list) and invoke (tools/call) every tool the server exposes. - Read resources, prompts and any state reachable through the session.
- Trigger side effects the tools support: file writes, shell execution, arbitrary outbound API calls.
tools/list is the request that asks the server "what can you do?", and tools/call is the request that says "do this one". Together they mean the attacker can first read the menu and then order anything on it.
Because MCP servers typically run with the user's own privileges and often expose developer tooling (filesystem, shell, browser automation, language servers), the practical impact can extend to full code execution on the victim's machine. Full code execution means the attacker can run any program the victim could run, which is about as bad as it gets on a single computer.
The fix
The fix has three parts: a secure-by-default allowlist for hostnames, a validate_dns_rebinding_headers gate that every request now passes through, and optional Origin validation as defence in depth. The deployed source is in tower.rs.
An allowlist is the opposite of a blocklist: instead of naming what is forbidden, it names what is permitted, and everything else is refused. Defence in depth means adding a second lock even though the first one already works, in case the first one is ever picked.
1) A secure default: StreamableHttpServerConfig
pub struct StreamableHttpServerConfig { pub allowed_hosts: Vec<String>, pub allowed_origins: Vec<String>, validate_empty_origin_allowlist: bool, }impl Default for StreamableHttpServerConfig { fn default() -> Self { Self { allowed_hosts: vec!["localhost".into(), "[redacted]".into(), "::1".into()], allowed_origins: vec![], validate_empty_origin_allowlist: false, } }}
Line by line:
pub struct StreamableHttpServerConfig {begins the definition of a settings box for the server.pub allowed_hosts: Vec<String>,is a list of hostnames that are allowed to talk to the server.pub allowed_origins: Vec<String>,is a list of origins (website names) that are allowed to send requests.validate_empty_origin_allowlist: bool,is a true/false switch controlling what happens when the origin list is empty.impl Default for StreamableHttpServerConfig {defines what the settings box contains when nobody configures it.fn default() -> Self {is the function that builds that default box.allowed_hosts: vec!["localhost".into(), "[redacted]".into(), "::1".into()],fills the host list with three names that all mean "this machine":localhost,[redacted]and::1(the last is the IPv6 spelling of the same idea).allowed_origins: vec![],leaves the origin list empty.validate_empty_origin_allowlist: false,leaves the strict origin mode off.
The Default impl is the load-bearing part. Just calling StreamableHttpServerConfig::default(), with no extra configuration, populates allowed_hosts with localhost, [redacted] and ::1. That flip from insecure by default to secure by default is the design philosophy behind the patch. A developer deploying publicly has to explicitly widen it via with_allowed_hosts(["mcp.example.com"]), and turning validation off entirely requires an equally explicit disable_allowed_hosts().
impl StreamableHttpServerConfig { pub fn with_allowed_hosts( mut self, allowed_hosts: impl IntoIterator<Item = impl Into<String>>, ) -> Self { self.allowed_hosts = allowed_hosts.into_iter().map(Into::into).collect(); self } pub fn disable_allowed_hosts(mut self) -> Self { self.allowed_hosts.clear(); self }}
Line by line:
impl StreamableHttpServerConfig {adds two methods to the settings box.pub fn with_allowed_hosts(starts a method that replaces the host list.mut self,takes the settings box and allows it to be changed.allowed_hosts: impl IntoIterator<Item = impl Into<String>>,accepts anything that can be walked through as a sequence of things convertible to text, so a list of names works.) -> Self {says the method returns the settings box again, so calls can be chained.self.allowed_hosts = allowed_hosts.into_iter().map(Into::into).collect();converts each supplied name to text and stores the whole list.selfreturns the box.pub fn disable_allowed_hosts(mut self) -> Self {starts a method that switches the protection off.self.allowed_hosts.clear();empties the list.selfreturns the box.
An empty allowed_hosts vector is exactly what host_is_allowed treats as "allow everything", so disable_allowed_hosts() is a literal opt-out of the whole protection. The name is honest, but the effect is total.
2) Enforcement at the entry point
pub async fn handle<B>(&self, request: Request<B>) -> Response<BoxBody<Bytes, Infallible>>where B: Body + Send + 'static, B::Error: Display,{ if let Err(response) = validate_dns_rebinding_headers(request.uri(), request.headers(), &self.config) { return response.into_response(); } ...}
Line by line:
- The first lines are the same function signature as before: this is still the function that receives every request.
if let Err(response) =tries the check and captures the failure case.validate_dns_rebinding_headers(request.uri(), request.headers(), &self.config)calls the new gate, handing it the request's address information, its headers and the server settings.{ return response.into_response(); }means: if the gate says no, send its refusal back immediately and stop....stands for the rest of the original handling, which only runs when the gate says yes.
Placement is the key detail: validate_dns_rebinding_headers runs at the very top of handle(), ahead of both method dispatch and session lookup. A failed check returns immediately, before the server ever touches session state or parses the JSON-RPC body, shrinking the attack surface to before the request reaches any internal logic at all. Attack surface is simply the total set of ways in could be tried; making it smaller means fewer places to defend.
3) Parsing the Host header: parse_host_header
fn parse_host_header(uri: &http::Uri, headers: &HeaderMap) -> HttpResult<NormalizedAuthority> { if let Some(host) = headers.get(http::header::HOST) { let host_str = host .to_str() .map_err(|_| bad_request_response("Bad Request: Invalid Host header encoding"))?; let authority = http::uri::Authority::try_from(host_str) .map_err(|_| bad_request_response("Bad Request: Invalid Host header"))?; return Ok(normalize_authority(authority.host(), authority.port_u16())); } let authority = uri.authority().ok_or_else(|| { bad_request_response("Bad Request: missing Host header") })?; Ok(normalize_authority(authority.host(), authority.port_u16()))}
Line by line:
fn parse_host_header(uri: &http::Uri, headers: &HeaderMap) -> HttpResult<NormalizedAuthority> {declares a function that takes the request address and headers and returns either a cleaned-up host or an error.if let Some(host) = headers.get(http::header::HOST) {checks whether aHostheader is present.let host_str = hoststarts converting that header into readable text..to_str()performs the conversion..map_err(|_| bad_request_response("Bad Request: Invalid Host header encoding"))?;turns a conversion failure into a 400 Bad Request reply and stops.let authority = http::uri::Authority::try_from(host_str)tries to read the text as a host plus optional port..map_err(|_| bad_request_response("Bad Request: Invalid Host header"))?;turns a parse failure into a 400 reply and stops.return Ok(normalize_authority(authority.host(), authority.port_u16()));returns the host and port, cleaned up.let authority = uri.authority().ok_or_else(|| {is the fallback when there is noHostheader: take the authority from the request address instead.bad_request_response("Bad Request: missing Host header")is the error if even that is absent.})?;stops with that error if needed.Ok(normalize_authority(authority.host(), authority.port_u16()))returns the cleaned-up host and port from the address.
The HTTP/2 fallback matters. HTTP/1.1 names the target via the Host: header, but HTTP/2 replaces it with the :authority pseudo-header on the request line, and some middleware (for example axum::Router::nest) can strip the Host header hyper synthesises from it during routing. So instead of "no Host header means allow", the code falls back to the URI's authority, meaning a missing header still gets checked against something and is never silently skipped. Middleware is software that sits between the incoming request and the application, like a receptionist who can pass a message along or lose a detail from it.
4) Normalising the host: case and IPv6 brackets
fn normalize_host(host: &str) -> String { host.trim_matches('[') .trim_matches(']') .to_ascii_lowercase()}struct NormalizedAuthority { host: String, port: Option<u16>,}fn normalize_authority(host: &str, port: Option<u16>) -> NormalizedAuthority { NormalizedAuthority { host: normalize_host(host), port }}
Line by line:
fn normalize_host(host: &str) -> String {declares a function that takes a host name as text and returns a tidied version.host.trim_matches('[')removes any leading or trailing square bracket..trim_matches(']')removes the closing bracket as well..to_ascii_lowercase()converts every letter to lowercase.struct NormalizedAuthority {defines a small pair of host and port.host: String,holds the tidied host name.port: Option<u16>,holds an optional port number;Optionmeans it may be absent.fn normalize_authority(host: &str, port: Option<u16>) -> NormalizedAuthority {builds that pair.NormalizedAuthority { host: normalize_host(host), port }stores the tidied host and the port as given.
DNS names are case-insensitive (Localhost and localhost are the same host), and IPv6 literals appear bracketed in a URI ([::1]). Without normalising both, an attacker could try bypassing the allowlist comparison with variants like Host: LOCALHOST or Host: [::1]. normalize_host handles both in one place so every later comparison can be a plain string ==. This is the same reason a bouncer checks ID against a list of names written in one consistent style: if the list says "Smith" and the ID says "SMITH", a careless comparison lets the wrong person in.
5) Allowlist matching: host_is_allowed
fn parse_allowed_authority(allowed: &str) -> Option<NormalizedAuthority> { let allowed = allowed.trim(); if allowed.is_empty() { return None; } if let Ok(authority) = http::uri::Authority::try_from(allowed) { return Some(normalize_authority(authority.host(), authority.port_u16())); } Some(normalize_authority(allowed, None))}fn host_is_allowed(host: &NormalizedAuthority, allowed_hosts: &[String]) -> bool { if allowed_hosts.is_empty() { return true; } allowed_hosts .iter() .filter_map(|allowed| parse_allowed_authority(allowed)) .any(|allowed| { allowed.host == host.host && match allowed.port { Some(port) => host.port == Some(port), None => true, } })
Line by line:
fn parse_allowed_authority(allowed: &str) -> Option<NormalizedAuthority> {declares a function that turns one allowlist entry into a host and port pair, or nothing if the entry is blank.let allowed = allowed.trim();removes surrounding spaces.if allowed.is_empty() { return None; }ignores blank entries.if let Ok(authority) = http::uri::Authority::try_from(allowed) {tries to read the entry as host plus port.return Some(normalize_authority(authority.host(), authority.port_u16()));returns the tidied pair when that works.Some(normalize_authority(allowed, None))otherwise treats the whole entry as a host with no port.fn host_is_allowed(host: &NormalizedAuthority, allowed_hosts: &[String]) -> bool {declares the comparison function, returning true or false.if allowed_hosts.is_empty() { return true; }is the dangerous shortcut: an empty list means allow everything.allowed_hostsstarts walking the list..iter()goes through each entry..filter_map(|allowed| parse_allowed_authority(allowed))converts each entry to a pair and drops blanks..any(|allowed| {asks whether at least one entry matches.allowed.host == host.hostrequires the host names to be identical.&& match allowed.port {then checks the port.Some(port) => host.port == Some(port),if the entry names a port, the request must use exactly that port.None => true,if the entry names no port, any port is fine.
Each allowlist entry ("example.com", "example.com:8080", etc.) is parsed into a host/port pair before comparison. An entry with no port ("localhost") matches that host on any port; an entry with a port ("example.com:8080") only matches that exact port. This lets a developer keep localhost wide open (any port) during development while locking a production deployment down to example.com:443.
6) The gate itself: validate_dns_rebinding_headers
fn validate_dns_rebinding_headers( uri: &http::Uri, headers: &HeaderMap, config: &StreamableHttpServerConfig,) -> HttpResult<()> { let host = parse_host_header(uri, headers)?; if !host_is_allowed(&host, &config.allowed_hosts) { tracing::warn!( host = ?host, "rejected request with disallowed Host header (possible DNS rebinding attempt)", ); return Err(forbidden_response("Forbidden: Host header is not allowed").into()); } validate_origin_header(headers, config)?; Ok(())}
Line by line:
fn validate_dns_rebinding_headers(declares the gate function.uri: &http::Uri,receives the request address.headers: &HeaderMap,receives the request headers.config: &StreamableHttpServerConfig,receives the server settings.) -> HttpResult<()> {returns either success with nothing in it, or an error reply.let host = parse_host_header(uri, headers)?;extracts the host, stopping if it cannot.if !host_is_allowed(&host, &config.allowed_hosts) {checks the host against the allowlist.tracing::warn!(writes a warning to the server log.host = ?host,includes the offending host in the log line."rejected request with disallowed Host header (possible DNS rebinding attempt)",is the message, naming the suspected attack.return Err(forbidden_response("Forbidden: Host header is not allowed").into());sends a 403 Forbidden reply and stops.validate_origin_header(headers, config)?;then runs the optional origin check.Ok(())reports success.
This single function is the fix. It parses Host, and if it is not on the allowlist it returns 403 Forbidden immediately, logging a tracing::warn! that flags the possibility of a DNS rebinding attempt. Step 5's request arriving with Host: attacker.example is stopped right here, because attacker.example is not in the default allowlist (localhost, [redacted], ::1).
7) Origin validation: defence in depth
fn validate_origin_header( headers: &HeaderMap, config: &StreamableHttpServerConfig,) -> HttpResult<()> { if !config.validate_empty_origin_allowlist && config.allowed_origins.is_empty() { return Ok(()); } let Some(origin_header) = headers.get(http::header::ORIGIN) else { return Ok(()); }; let origin_str = origin_header .to_str() .map_err(|_| forbidden_response("Forbidden: Invalid Origin header encoding"))?; let origin = parse_origin_value(origin_str) .ok_or_else(|| forbidden_response("Forbidden: Invalid Origin header"))?; if !origin_is_allowed(&origin, &config.allowed_origins) { tracing::warn!(origin = ?origin, "rejected request with disallowed Origin header"); return Err(forbidden_response("Forbidden: Origin header is not allowed").into()); } Ok(())}
Line by line:
fn validate_origin_header(declares the origin check.headers: &HeaderMap,receives the headers.config: &StreamableHttpServerConfig,receives the settings.) -> HttpResult<()> {returns success or an error reply.if !config.validate_empty_origin_allowlist && config.allowed_origins.is_empty() {detects the default, permissive setup.return Ok(());and in that case skips the check entirely.let Some(origin_header) = headers.get(http::header::ORIGIN) else {looks for anOriginheader.return Ok(());and if there is none, allows the request.let origin_str = origin_headerstarts converting the header to text..to_str()performs the conversion..map_err(|_| forbidden_response("Forbidden: Invalid Origin header encoding"))?;turns a failure into a 403 reply and stops.let origin = parse_origin_value(origin_str)tries to read the text as an origin..ok_or_else(|| forbidden_response("Forbidden: Invalid Origin header"))?;turns a failure into a 403 reply and stops.if !origin_is_allowed(&origin, &config.allowed_origins) {checks the origin against its allowlist.tracing::warn!(origin = ?origin, "rejected request with disallowed Origin header");logs the rejection.return Err(forbidden_response("Forbidden: Origin header is not allowed").into());sends the 403 and stops.Ok(())reports success.
As the advisory states explicitly, the root cause here is purely the missing Host check. Origin validation is not required to stop this specific attack, since a browser cannot forge the Host header it sends to the rebound target; the Host allowlist alone is sufficient. Origin checking was added anyway as defence in depth: by default, an empty allowed_origins list skips validation entirely (preserving backward compatibility), while calling enforce_origin_validation() switches to a strict mode that rejects any request carrying an Origin header, even with an empty allowlist. Backward compatibility means existing setups keep working as before, so an upgrade does not break them.
Remediation
- Upgrade to rmcp 1.4.0 or later. The default configuration alone already blocks any request whose
Hostis not a loopback address. - If you are deploying an MCP server under a public domain, register it explicitly:
StreamableHttpServerConfig::default().with_allowed_hosts(["mcp.example.com"]). - If upgrading is not immediately possible, put a reverse proxy (nginx, Caddy, etc.) in front that rejects requests with an unexpected
Hostheader, and do not bind the MCP server directly to[redacted]. - Avoid
disable_allowed_hosts(), which reverts you to the pre-patch, unprotected state, unless an upstream proxy is already validatingHoston your behalf.
A reverse proxy is a program that sits in front of your server and forwards requests to it, like a doorman who can turn people away before they reach the desk. Binding to [redacted] means listening on every network interface, not just the private one, which exposes the server to the whole network.
Variants to test
If you want to look for the same class of bug elsewhere, these are the angles worth trying.
- Other loopback-bound developer servers. Look for local services that expose powerful actions over HTTP and never compare
Hostagainst a known name. A positive result is a request withHost: attacker.examplereaching the handler and returning a normal response rather than403. - Case and bracket variants. Send
Host: LOCALHOSTandHost: [::1]against a server that does have an allowlist. A positive result is either variant being accepted or rejected inconsistently with its lowercase or unbracketed form, which points to missing normalisation. - Missing
Hoston HTTP/2. Route a request through middleware that strips the synthesisedHostheader. A positive result is the server treating the absent header as trusted instead of falling back to the URI authority. - Port-scoped allowlist entries. Configure an entry with an explicit port and probe other ports on the same host. A positive result is a match on a port that should not have been allowed.
- Empty allowlist semantics. Check what an empty
allowed_hostslist does. A positive result is an empty list being interpreted as allow-all rather than deny-all. Originenforcement mode. Withenforce_origin_validation()enabled, send requests with noOrigin, a malformedOriginand a disallowedOrigin. A positive result is any of these reaching the handler.
Glossary
- API: a way for one program to ask another program to do something, without a human clicking anything.
- Allowlist: a list of things that are permitted, where everything not on the list is refused.
- Attack surface: the total set of ways an attacker could try to get in.
- Backward compatibility: keeping old setups working after a change, so an upgrade does not break them.
- Binding to
[redacted]: making a server listen on every network interface rather than only the private one. - CVE: a public identifier for a known security flaw, so people can refer to it unambiguously.
- Defence in depth: adding a second protection even though the first one already works.
- DNS: the phone book that turns a website name into an IP address.
- DNS rebinding: an attack that changes the IP address a name resolves to, so a browser keeps trusting the name while the connection goes somewhere else.
- Full code execution: the ability to run any program the victim could run on their machine.
- GHSA: a GitHub security advisory identifier for a published vulnerability.
- Header: a small labelled line of text sent with a web request or response, such as
HostorOrigin. Hostheader: the part of a request that names the website it was aimed at.- HTTP: the language browsers and servers use to exchange web requests and replies.
- HTTP/2: a newer version of HTTP that carries the target name in a
:authoritypseudo-header instead of aHostheader. - IP address: the numeric address a computer uses to find another computer.
- JSON-RPC: a structured text message format for asking a program to call a function with arguments.
- Loopback: the private network address that always means "this very machine", usually
[redacted]. - MCP (Model Context Protocol): a way for an AI assistant to talk to helper programs that give it abilities.
- MCP server: a helper program that offers tools to an AI assistant over MCP.
- Middleware: software that sits between an incoming request and the application, able to inspect or alter it.
Originheader: the part of a request that names the website the request came from.- Reverse proxy: a program in front of a server that receives requests and forwards them, able to reject some first.
rmcp: Anthropic's official Rust SDK for MCP, including the transport layer.- Rust: a programming language.
- SDK: a kit of ready-made code that developers use to build on a platform.
- Session ID: a short label the server hands out so it can remember which conversation a request belongs to.
- Same-Origin Policy (SOP): the browser rule that a page from one website name may not freely read data from another.
- Streamable HTTP server transport: the part of
rmcpthat accepts web requests for an MCP server. - TCP connection: the underlying network link between two computers over which a web request travels.
- Tool: an action an MCP server offers, such as reading a file or running a command.
- Transport layer: the part of a system that carries messages between two programs.
- TTL (time to live): how long a DNS answer may be reused before the browser must ask again.
tools/list: the MCP request that asks a server which tools it offers.tools/call: the MCP request that asks a server to run one of its tools.