Skip to content

bug(server): allowed_hosts / allowed_origins only protect the MCP leg; A2A requests get no Host or Origin check #1301

Closed

Description

@bokelley

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

  1. 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_app and _build_a2a_app, using FastMCP's matching rules. At minimum, warn when transport="a2a" drops the settings.
  2. Make the Origin check independent of the Host check: enforce Origin whenever allowed_origins is set, even if Host validation is off. Then the SubdomainTenantMiddleware guidance 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

  1. added
    bugSomething isn't working
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
  2. bokelley commented on Oct 2, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug (security)
    Bucket(s): middleware, handlers (no security label exists in this repo — flagged as gap)
    Status: ready-for-human
    Milestone: omitted (no version target specified)

    What the experts said:

    • security-reviewer: BLOCKER — host/origin settings are silently dropped for transport="a2a"; any outer ASGI check must exempt /.well-known/agent*.json card paths (GET, no Origin header) or it will break A2A discovery; the SubdomainTenantMiddleware guidance that sets enable_dns_rebinding_protection=False must not also kill Origin checks; Origin and Host enforcement must be independently configurable.
    • code analysis (confirmed): _build_mcp_and_a2a_app passes allowed_hosts/allowed_origins/enable_dns_rebinding_protection to create_mcp_server but not to create_a2a_server (serve.py:2201-2220); _build_a2a_app and create_a2a_server have 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) Add allowed_hosts, allowed_origins, enable_dns_rebinding_protection to _build_a2a_app and 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 a warnings.warn when transport="a2a" is used with any of these params set; (4) fix/annotate the SubdomainTenantMiddleware comment (lines 2688-2697) to clarify that enable_dns_rebinding_protection=False also disables FastMCP's Origin check, and recommend passing allowed_origins to the new outer layer instead.
    • src/adcp/server/a2a_server.py — create_a2a_server may not need changes if the enforcement is in the _build_* wrappers, but add host/origin params here too for direct users of create_a2a_server.
    • The second ask (independent Origin/Host check on the FastMCP side) depends on upstream work (Make Origin validation opt-in in the app factories (keep Host validation on for localhost) modelcontextprotocol/python-sdk#3576) and can be tracked separately once that lands.

    Triaged by Claude Code. Session: https://claude.ai/code/session_01EbwjfucpPYqdKRRbqgrodW


    Generated by Claude Code

  3. added and removed
    claude-triagingTriage routine is actively working on this issue (1-3 min)
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions