Skip to content

The agent that grows with you

fix(a2a): keep no-token localhost peers trusted when an allow-list is set

kshitijk4poor66ed823b5c10
diff --git a/plugins/platforms/a2a/adapter.py b/plugins/platforms/a2a/adapter.py
index d692045b89a..bd3dbda516c 100644
--- a/plugins/platforms/a2a/adapter.py
+++ b/plugins/platforms/a2a/adapter.py
@@ -330,6 +330,10 @@ class A2AAdapter(BasePlatformAdapter):
self._mark_connected()
logger.info("A2A: serving Agent Card + JSON-RPC on http://%s:%s (%s) as %r; %d routed agent(s)", self.host, self.port,
"localhost-only" if self._security_context.localhost_only() else "REMOTE (bearer auth)", self.agent_name, len(self._agents))
+ sec = self._security_context
+ if not (sec.allow_all_users or sec.localhost_only() or sec.trusted_peers or sec.is_loopback_bind()):
+ logger.error("A2A: exposed on non-loopback bind %s with no A2A_TRUSTED_PEERS; every dispatch will be refused (403). "
+ "Set A2A_TRUSTED_PEERS, or A2A_ALLOW_ALL_USERS=true for a trusted network.", self.host)
self._wire_plugin_handlers(None) # plugin-registered native handlers
return True
diff --git a/plugins/platforms/a2a/security.py b/plugins/platforms/a2a/security.py
index 129670ce81d..b6f0d9d0a21 100644
--- a/plugins/platforms/a2a/security.py
+++ b/plugins/platforms/a2a/security.py
@@ -101,28 +101,16 @@ class A2ASecurityContext:
def is_loopback_bind(self) -> bool:
"""True when the resolved bind host is loopback."""
- host = (self.resolve_bind_host() or "").strip()
- if host.lower() in {"127.0.0.1", "localhost", "::1"}:
- return True
- try:
- return ipaddress.ip_address(host).is_loopback
- except ValueError:
- return False
+ from agent.proxy_bypass import is_loopback_host
+ return is_loopback_host(self.resolve_bind_host())
def is_trusted_peer(self, identity: str) -> bool:
"""Fail closed on network-exposed binds with no allow-list; loopback
binds without an allow-list stay open for backward compatibility."""
- if self.allow_all_users:
+ if self.allow_all_users or self.localhost_only():
return True
if not self.trusted_peers:
- if self.is_loopback_bind():
- return True
- logger.error(
- "A2A: adapter exposed on a non-loopback bind (%s) with no A2A_TRUSTED_PEERS; "
- "refusing dispatch. Set A2A_TRUSTED_PEERS, or A2A_ALLOW_ALL_USERS=true for a trusted network.",
- self.resolve_bind_host(),
- )
- return False
+ return self.is_loopback_bind() # the misconfiguration is logged once in A2AAdapter.connect()
return identity in self.trusted_peers
def sign_push_payload(self, payload: dict) -> str:
diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.py
index 89009a3677b..0ae1e411db2 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -168,9 +168,14 @@ class TestTrustedPeers:
monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)
monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
assert security.A2ASecurityContext.capture().is_trusted_peer("ip:127.0.0.1") is True
+ # No token => identity is always ip:<addr>, so a configured allow-list must not 403 local callers.
+ monkeypatch.setenv("A2A_TRUSTED_PEERS", "alice")
+ assert security.A2ASecurityContext.capture().is_trusted_peer("ip:127.0.0.1") is True
- def test_no_allowlist_trusts_authenticated(self, monkeypatch):
+ def test_loopback_bind_no_allowlist_trusts_authenticated(self, monkeypatch):
+ """Loopback + bearer token + no allow-list preserves backward compat."""
monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
+ monkeypatch.setenv("A2A_HOST", "127.0.0.1")
monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
monkeypatch.delenv("A2A_TRUSTED_PEERS", raising=False)
assert security.A2ASecurityContext.capture().is_trusted_peer("alice") is True
@@ -189,29 +194,14 @@ class TestTrustedPeers:
monkeypatch.setenv("A2A_TRUSTED_PEERS", "alice")
assert security.A2ASecurityContext.capture().is_trusted_peer("mallory") is True
- def test_non_loopback_bind_empty_allowlist_fails_closed(self, monkeypatch, caplog):
+ def test_non_loopback_bind_empty_allowlist_fails_closed(self, monkeypatch):
"""#126756: network-exposed bind + bearer token + no allow-list must fail closed."""
monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
monkeypatch.setenv("A2A_HOST", "0.0.0.0")
monkeypatch.delenv("A2A_TRUSTED_PEERS", raising=False)
monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)
- ctx = security.A2ASecurityContext.capture()
- assert ctx.is_loopback_bind() is False
- with caplog.at_level("ERROR", logger="plugins.platforms.a2a.security"):
- assert ctx.is_trusted_peer("ip:1.2.3.4") is False
- assert "no A2A_TRUSTED_PEERS" in caplog.text
-
- def test_loopback_bind_empty_allowlist_trusts_all(self, monkeypatch):
- """Loopback + bearer token + no allow-list preserves backward compat."""
- monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
- monkeypatch.setenv("A2A_HOST", "127.0.0.1")
- monkeypatch.delenv("A2A_TRUSTED_PEERS", raising=False)
- monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
- monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)
- ctx = security.A2ASecurityContext.capture()
- assert ctx.is_loopback_bind() is True
- assert ctx.is_trusted_peer("ip:127.0.0.1") is True
+ assert security.A2ASecurityContext.capture().is_trusted_peer("ip:1.2.3.4") is False
class TestInjectionFilter: