The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(a2a): cover token-mode Host, malformed Host and missing Content-Type
unsupportedpastels1ae3c55e4bb1
diff --git a/plugins/platforms/a2a/README.md b/plugins/platforms/a2a/README.mdindex 551a6f82c0a..904811817c4 100644--- a/plugins/platforms/a2a/README.md+++ b/plugins/platforms/a2a/README.md@@ -58,7 +58,11 @@ via `tasks/get`.- **No token ⇒ localhost only.** The server binds `127.0.0.1` and refuses towiden unless you configure a token *and* set `A2A_HOST`.Without a token it also refuses browser-originated POSTs (`Origin`,- cross-site `Sec-Fetch-Site`, non-JSON `Content-Type`).+ cross-site `Sec-Fetch-Site`, a missing or non-JSON `Content-Type`).+- **No token ⇒ loopback `Host` only.** Every route refuses a `Host` that is+ not a loopback name (`localhost`, `127.x.x.x`, `[::1]`) or the+ `A2A_PUBLIC_URL` host, so a DNS-rebound page cannot reach it. Only set+ `A2A_PUBLIC_URL` to a name you control.- **Per-peer tokens**: `A2A_PEER_TOKENS="alice:tok1,bob:tok2"` gives eachremote agent its own credential; that authenticated name (never anythingin the request body) drives rate limiting, trust, and audit.@@ -77,7 +81,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, `Host` must be a loopback name (`localhost`, `127.x.x.x`, `[::1]`) or the `A2A_PUBLIC_URL` host. |+| `A2A_HOST` | `127.0.0.1` | Bind host. Only widens with a token set. || `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/tests/plugins/test_a2a_no_token_guards.py b/tests/plugins/test_a2a_no_token_guards.pynew file mode 100644index 00000000000..8247a57ec28--- /dev/null+++ b/tests/plugins/test_a2a_no_token_guards.py@@ -0,0 +1,46 @@+"""Edges of the A2A no-token browser and Host guards: malformed Host values fail closed, a POST+without a Content-Type is refused, and a token-authenticated listener is left unchanged."""++from __future__ import annotations++import asyncio+from email.message import Message++import pytest++from plugins.platforms.a2a import security+from tests.plugins.test_a2a_plugin import _get_json, _make_live_adapter, _post_json, _send_body++[email protected]("value", ["", "[::1", "127.0.0.1:notaport", "[email protected]", "127.0.0.1, rebound.example"])+def test_no_token_host_check_fails_closed_on_malformed_values(value):+ assert security.is_loopback_host_header(value, "https://agent.example.test/") is False+++def test_no_token_post_without_content_type_is_refused():+ headers = Message()+ assert security.browser_post_refusal(headers)+ headers["Content-Type"] = "application/json; charset=utf-8"+ assert security.browser_post_refusal(headers) is None+++def test_token_listener_keeps_serving_any_host(monkeypatch):+ """The Host and browser guards apply only without a token; an authenticated listener is unchanged."""+ monkeypatch.setenv("A2A_BEARER_TOKEN", "topsecret")+ monkeypatch.setenv("A2A_HOST", "127.0.0.1")+ adapter, base = _make_live_adapter(monkeypatch)++ async def run():+ assert await adapter.connect() is True+ try:+ health = await asyncio.to_thread(_get_json, base + "/health", {"Host": "rebound.example"})+ resp = await asyncio.to_thread(+ _post_json, base + "/", _send_body("hello"),+ {"Host": "rebound.example", "Authorization": "Bearer topsecret"})+ return health, resp+ finally:+ await adapter.disconnect()++ health, resp = asyncio.run(run())+ assert health["status"] == "ok"+ assert resp["result"]["status"]["state"] == "TASK_STATE_COMPLETED"diff --git a/website/docs/user-guide/messaging/a2a.md b/website/docs/user-guide/messaging/a2a.mdindex 925fff8c713..c6e26aebbf7 100644--- a/website/docs/user-guide/messaging/a2a.md+++ b/website/docs/user-guide/messaging/a2a.md@@ -157,5 +157,6 @@ curl -X POST http://your-host:9900/ \- **`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 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'`.+- **`403` "Content-Type must be application/json" with no token** — the POST had a missing or non-JSON `Content-Type` (plain `curl -d` sends a form type); add `-H 'Content-Type: application/json'`.+- **`403` "browser-originated" or "cross-site request refused" with no token** — the request carried an `Origin` header or a cross-site `Sec-Fetch-Site`, which only browsers send. Call it from a local script or SDK, or configure a token.- **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`.