Skip to content

The agent that grows with you

fix(a2a): accept the bracketed [::1] spelling of an IPv6 A2A_HOST

John Paul Soliva1f0981bd8e52
diff --git a/plugins/platforms/a2a/security.py b/plugins/platforms/a2a/security.py
index 31871cf403a..a415e86aecf 100644
--- a/plugins/platforms/a2a/security.py
+++ b/plugins/platforms/a2a/security.py
@@ -51,6 +51,11 @@ def _configured_trusted_peers() -> frozenset[str]:
return frozenset()
+def _unbracket(host: str) -> str:
+ """``[::1]`` is the URL spelling of ``::1``; sockets and the loopback check need the bare literal."""
+ return host[1:-1] if host.startswith("[") and host.endswith("]") else host
+
+
@dataclass(frozen=True)
class A2ASecurityContext:
"""Immutable, profile-scoped security settings captured at adapter startup. HTTP request
@@ -69,7 +74,7 @@ class A2ASecurityContext:
return cls(bearer_token=bearer_token, peer_tokens=tuple(_parse_peer_tokens(_startup_env("A2A_PEER_TOKENS")).items()),
trusted_peers=_configured_trusted_peers(),
allow_all_users=_startup_env("A2A_ALLOW_ALL_USERS").lower() in {"1", "true", "yes"},
- requested_host=_startup_env("A2A_HOST") or "127.0.0.1", push_secret=_startup_env("A2A_PUSH_SECRET") or bearer_token)
+ requested_host=_unbracket(_startup_env("A2A_HOST")) or "127.0.0.1", push_secret=_startup_env("A2A_PUSH_SECRET") or bearer_token)
def localhost_only(self) -> bool:
return not (self.bearer_token or self.peer_tokens)
diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.py
index fadcb91fae7..8a964532210 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -974,12 +974,14 @@ def _send_body(text, ctx="", extra_params=None):
return {"jsonrpc": "2.0", "id": "1", "method": "message/send", "params": params}
-def test_ipv6_loopback_bind_serves_and_advertises_a_bracketed_url(monkeypatch):
- """``A2A_HOST=::1`` is an accepted no-token bind: the listener must come up on it and the
- Agent Card must advertise a URL a peer can parse (IPv6 literal in brackets)."""
[email protected]("spelling", ["::1", "[::1]"])
+def test_ipv6_loopback_bind_serves_and_advertises_a_bracketed_url(monkeypatch, spelling):
+ """``A2A_HOST=::1`` (or its URL spelling ``[::1]``) is an accepted no-token bind: the listener
+ must come up on it and every advertised URL, including the Host-less fallback, must be one a
+ peer can parse (IPv6 literal in exactly one pair of brackets)."""
monkeypatch.delenv("A2A_BEARER_TOKEN", raising=False)
monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)
- monkeypatch.setenv("A2A_HOST", "::1")
+ monkeypatch.setenv("A2A_HOST", spelling)
adapter, _ = _make_live_adapter(monkeypatch)
base = f"http://[::1]:{adapter.port}"
@@ -991,6 +993,7 @@ def test_ipv6_loopback_bind_serves_and_advertises_a_bracketed_url(monkeypatch):
await adapter.disconnect()
assert asyncio.run(run())["url"].startswith(base + "/")
+ assert adapter._base_url(None) == base + "/"
@pytest.mark.integration
diff --git a/website/docs/user-guide/messaging/a2a.md b/website/docs/user-guide/messaging/a2a.md
index 92b82caa29b..8a31dc2ef11 100644
--- a/website/docs/user-guide/messaging/a2a.md
+++ b/website/docs/user-guide/messaging/a2a.md
@@ -123,7 +123,7 @@ Secure by default; every widening step is explicit:
|---|---|---|
| `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 when a token is set. IPv6 literals such as `::1` or `::` work too |
+| `A2A_HOST` | `127.0.0.1` | Bind host — only widens when a token is set. IPv6 literals such as `::1` or `::` work too, bare or bracketed (`[::1]`) |
| `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 / k8s) |