The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(a2a): serve loopback literals and the A2A_PUBLIC_URL host in the no-token Host check
unsupportedpastels544edcf794f6
diff --git a/plugins/platforms/a2a/README.md b/plugins/platforms/a2a/README.mdindex 5b89d391a76..551a6f82c0a 100644--- a/plugins/platforms/a2a/README.md+++ b/plugins/platforms/a2a/README.md@@ -77,7 +77,7 @@ via `tasks/get`.|---|---|---|| `A2A_PEER_TOKENS` | _(unset)_ | Per-peer credentials `name:token,…` (preferred). || `A2A_BEARER_TOKEN` | _(unset)_ | Shared token; identity falls back to caller IP. |-| `A2A_HOST` | `127.0.0.1` | Bind host. Only widens with a token set. Without a token, requests must name `localhost`, `127.0.0.1` or `[::1]` in `Host`. |+| `A2A_HOST` | `127.0.0.1` | Bind host. Only widens with a token set. Without a token, `Host` must be a loopback name (`localhost`, `127.x.x.x`, `[::1]`) or the `A2A_PUBLIC_URL` host. || `A2A_PORT` | `9900` | Inbound port. || `A2A_AGENT_NAME` | hostname-derived | Name on the Agent Card. || `A2A_PUBLIC_URL` | _(unset)_ | Routable URL advertised on the card (reverse proxies). |diff --git a/plugins/platforms/a2a/adapter.py b/plugins/platforms/a2a/adapter.pyindex 6821e4f13ef..b0c7a8850d2 100644--- a/plugins/platforms/a2a/adapter.py+++ b/plugins/platforms/a2a/adapter.py@@ -163,8 +163,11 @@ class A2ARequestHandler(BaseHTTPRequestHandler):listener and could otherwise read its served-agent list and Agent Card."""if not super().parse_request():return False- if self.adapter._security_context.localhost_only() and not security.is_loopback_host_header(self.headers.get("Host")):- self._error(403, None, protocol.ERR_UNAUTHORIZED, "Host must be localhost, 127.0.0.1 or [::1] (no A2A token configured)")+ adapter = self.adapter+ if adapter._security_context.localhost_only() and not security.is_loopback_host_header(+ self.headers.get("Host"), adapter._public_url):+ self._error(403, None, protocol.ERR_UNAUTHORIZED,+ "Host must be a loopback name or the A2A_PUBLIC_URL host (no A2A token configured)")return Falsereturn Truediff --git a/plugins/platforms/a2a/security.py b/plugins/platforms/a2a/security.pyindex 4fd3f5dcdce..040de35d2f3 100644--- a/plugins/platforms/a2a/security.py+++ b/plugins/platforms/a2a/security.py@@ -204,21 +204,21 @@ _BLOCKED_PREFIXES = ("169.254.", "127.", "10.", *(f"172.{i}." for i in range(16,"0.0.0.0", "::1", "fe80:", "fc00:", "fd00:")-_LOOPBACK_HOST_NAMES = frozenset({"localhost", "127.0.0.1", "::1"})---def is_loopback_host_header(host_header: Optional[str]) -> bool:- """True when an HTTP ``Host`` value names a loopback address (any port); malformed fails closed."""+def is_loopback_host_header(host_header: Optional[str], public_url: str = "") -> bool:+ """True when an HTTP ``Host`` value names a loopback address or the ``A2A_PUBLIC_URL`` host+ (any port); malformed fails closed."""value = (host_header or "").strip()if not value or any(c in value for c in "@/\\?# \t"):return Falsetry:parts = urllib.parse.urlsplit("//" + value)- parts.port # noqa: B018 -- raises ValueError on a malformed port+ parts.port # raises ValueError on a malformed port+ public_host = (urllib.parse.urlsplit(public_url or "").hostname or "").lower().rstrip(".")except ValueError:return False# ``localhost.`` is the absolute form of ``localhost``; a rebound name stays foreign either way.- return (parts.hostname or "").lower().rstrip(".") in _LOOPBACK_HOST_NAMES+ host = (parts.hostname or "").lower().rstrip(".")+ return is_loopback_host(host) or (bool(public_host) and host == public_host)def is_safe_callback_url(url: str, *, localhost_mode: Optional[bool] = None) -> bool:diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.pyindex 08e4ca328f0..33e116f054f 100644--- a/tests/plugins/test_a2a_plugin.py+++ b/tests/plugins/test_a2a_plugin.py@@ -1333,6 +1333,7 @@ class TestInboundRoundTrip:("localhost", True),("[::1]", True),("localhost.", True), # absolute form of localhost+ ("127.0.0.2", True), # any loopback literal("rebound.example", False),("rebound.example.", False), # a page's hostname re-resolved to 127.0.0.1])@@ -1365,6 +1366,30 @@ def test_no_token_listener_serves_only_loopback_host_names(monkeypatch, host, seassert bool(seen) is served+def test_no_token_listener_serves_its_public_url_host(monkeypatch):+ """A local reverse proxy forwarding the ``A2A_PUBLIC_URL`` host is served; other names stay refused."""+ monkeypatch.delenv("A2A_BEARER_TOKEN", raising=False)+ monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)+ monkeypatch.setenv("A2A_PUBLIC_URL", "https://agent.example.test/")+ adapter, base = _make_live_adapter(monkeypatch)++ def status(host):+ try:+ _get_json(base + "/health", {"Host": host})+ return 200+ except urllib.error.HTTPError as exc:+ return exc.code++ async def run():+ assert await adapter.connect() is True+ try:+ return [await asyncio.to_thread(status, host) for host in ("agent.example.test", "rebound.example")]+ finally:+ await adapter.disconnect()++ assert asyncio.run(run()) == [200, 403]++# --------------------------------------------------------------------------# Push notifications end-to-end (inline config in message/send)# --------------------------------------------------------------------------diff --git a/website/docs/user-guide/messaging/a2a.md b/website/docs/user-guide/messaging/a2a.mdindex e745879fae9..925fff8c713 100644--- a/website/docs/user-guide/messaging/a2a.md+++ b/website/docs/user-guide/messaging/a2a.md@@ -156,5 +156,6 @@ curl -X POST http://your-host:9900/ \- **Peers can't reach the card URL** — the card was advertising your bind address; set `A2A_PUBLIC_URL` to the externally routable URL.- **`401 Unauthorized`** — token mismatch; check `A2A_PEER_TOKENS`/`A2A_BEARER_TOKEN` on the server and the peer's `auth:` block.- **Server won't bind non-localhost** — by design: set a bearer token first, then `A2A_HOST=0.0.0.0`.-- **`403` "Host must be localhost…" with no token** — without a token the server answers only requests addressed to `localhost`, `127.0.0.1` or `[::1]`, so a web page on another hostname that resolves to your machine cannot read the card or the served-agent list. Call it by one of those names, or configure a token.+- **`403` "Host must be a loopback name…" with no token** — without a token the server answers only requests addressed to a loopback name (`localhost`, `127.x.x.x`, `[::1]`) or the `A2A_PUBLIC_URL` host, so a web page on another hostname that resolves to your machine cannot read the card or the served-agent list. Call it by one of those names, set `A2A_PUBLIC_URL` to the name a local proxy forwards, or configure a token.+- **`403` "Content-Type must be application/json" with no token** — plain `curl -d` sends a form type; add `-H 'Content-Type: application/json'`.- **Replies time out on long tasks** — raise `A2A_REPLY_TIMEOUT` (the orphan sweep follows it, so a late reply is stored, not discarded), or have the caller register a push-notification config and poll `GetTask`.