Repository navigation
Description
Summary
serve() accepts allowed_hosts, allowed_origins and enable_dns_rebinding_protection, but only the MCP leg uses them. With transport="both" they are passed to create_mcp_server (adcp/server/serve.py:2141-2161) and from there into FastMCP's TransportSecuritySettings (serve.py:2672-2718). create_a2a_server has no host or origin parameters (adcp/server/a2a_server.py:1188-1210), and the call at serve.py:2201-2220 passes none. transport="a2a" drops all three settings with no warning (serve.py:1257-1283). So a seller who sets an allowlist has DNS-rebinding and cross-site-request protection on /mcp but none on /.
A second problem: the comment at serve.py:2688-2697 tells sellers that use SubdomainTenantMiddleware to set enable_dns_rebinding_protection=False. In FastMCP that flag also controls the Origin check (mcp/server/transport_security.py:102-114), and SubdomainTenantMiddleware only looks at Host. So following that advice turns off Origin checks on both legs.
Reproduction (adcp 8.0.0)
import json
from starlette.testclient import TestClient
from adcp.server import ADCPHandler
from adcp.server.serve import _build_mcp_and_a2a_app # the builder serve(transport="both") uses
calls = []
class Seller(ADCPHandler):
async def get_products(self, params, context=None):
calls.append("get_products")
return {"products": []}
def build(protection):
return _build_mcp_and_a2a_app(
Seller(), name="seller", port=3001, host="0.0.0.0",
instructions=None, test_controller=None, validation=None,
allowed_hosts=["seller.example"],
allowed_origins=["https://seller.example"],
enable_dns_rebinding_protection=protection,
)
JSON = {"content-type": "application/json", "accept": "application/json, text/event-stream"}
CASES = {"bad Origin": {"host": "seller.example", "origin": "https://evil.example"},
"bad Host": {"host": "rebound.evil.example"}}
MCP_INIT = {"jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": {"protocolVersion": "2025-06-18", "capabilities": {},
"clientInfo": {"name": "x", "version": "1"}}}
A2A_SEND = {"jsonrpc": "2.0", "id": 1, "method": "SendMessage", "params": {"message": {
"messageId": "m1", "role": "ROLE_USER",
"parts": [{"data": {"skill": "get_products",
"parameters": {"buying_mode": "brief", "brief": "video"}}}]}}}
for protection in (True, False):
with TestClient(build(protection), base_url="http://seller.example") as client:
for label, headers in CASES.items():
mcp = client.post("/mcp", headers={**JSON, **headers}, content=json.dumps(MCP_INIT))
a2a = client.post("/", headers={**JSON, **headers, "A2A-Version": "1.0"}, content=json.dumps(A2A_SEND))
print(f"protection={protection!s:5} {label:10}: MCP {mcp.status_code} | "
f"A2A {a2a.status_code}, handler ran={calls == ['get_products']}")
calls.clear()Output:
protection=True bad Origin: MCP 403 | A2A 200, handler ran=True
protection=True bad Host : MCP 421 | A2A 200, handler ran=True
protection=False bad Origin: MCP 200 | A2A 200, handler ran=True
protection=False bad Host : MCP 200 | A2A 200, handler ran=True
Why an adopter hits this
Embedded Sales Agent serves transport="both" with one subdomain per tenant. SubdomainTenantMiddleware validates Host on both legs, so ESA follows the SDK comment and turns the MCP flag off. That leaves no Origin check anywhere. ESA added BuyerProtocolOriginGuardMiddleware (core/middleware/origin_guard.py, 73 LOC), wired through asgi_middleware in core/main.py (_serve_kwargs). It re-implements FastMCP's Origin matching for /mcp and the A2A paths. Without it, a browser page could send JSON-RPC to the A2A leg with an ambient credential, and the seller would have no way to tell.
Ask
- Apply one Host/Origin policy to both legs from the existing
serve()settings. For example, use a single outer ASGI check in_build_mcp_and_a2a_appand_build_a2a_app, using FastMCP's matching rules. At minimum, warn whentransport="a2a"drops the settings. - Make the Origin check independent of the Host check: enforce Origin whenever
allowed_originsis set, even if Host validation is off. Then theSubdomainTenantMiddlewareguidance no longer turns off Origin checks. (The upstream MCP equivalent is Make Origin validation opt-in in the app factories (keep Host validation on for localhost) modelcontextprotocol/python-sdk#3576.)
Activity
bokelley commentedon Oct 2, 2026
Triage
Classification: Bug (security)
Bucket(s): middleware, handlers (no
securitylabel exists in this repo — flagged as gap)Status: ready-for-human
Milestone: omitted (no version target specified)
What the experts said:
transport="a2a"; any outer ASGI check must exempt/.well-known/agent*.jsoncard paths (GET, no Origin header) or it will break A2A discovery; theSubdomainTenantMiddlewareguidance that setsenable_dns_rebinding_protection=Falsemust not also kill Origin checks; Origin and Host enforcement must be independently configurable._build_mcp_and_a2a_apppassesallowed_hosts/allowed_origins/enable_dns_rebinding_protectiontocreate_mcp_serverbut not tocreate_a2a_server(serve.py:2201-2220);_build_a2a_appandcreate_a2a_serverhave no host/origin params;_serve_a2a(serve.py:1258-1283) silently drops all three.My take: Both bugs are confirmed. This is security-sensitive (DNS rebinding + cross-site JSON-RPC) so it goes to human review regardless of implementation clarity. The fix is well-scoped but the agent-card exemption and Origin/Host decoupling require careful judgment a human should own.
Implementation scope:
src/adcp/server/serve.py— (1) Addallowed_hosts,allowed_origins,enable_dns_rebinding_protectionto_build_a2a_appand pass them through_build_mcp_and_a2a_app; (2) implement an outer ASGI middleware (_HostOriginCheckMiddleware) that enforces Host/Origin on POST requests, passes GETs through without an Origin check (exempting/.well-known/agent.json,/.well-known/agent-card.json), and applies to both legs; (3) add awarnings.warnwhentransport="a2a"is used with any of these params set; (4) fix/annotate theSubdomainTenantMiddlewarecomment (lines 2688-2697) to clarify thatenable_dns_rebinding_protection=Falsealso disables FastMCP's Origin check, and recommend passingallowed_originsto the new outer layer instead.src/adcp/server/a2a_server.py—create_a2a_servermay not need changes if the enforcement is in the_build_*wrappers, but add host/origin params here too for direct users ofcreate_a2a_server.Triaged by Claude Code. Session: https://claude.ai/code/session_01EbwjfucpPYqdKRRbqgrodW
Generated by Claude Code
fix(server)!: enforce shared Host and Origin policy across HTTP trans…