Skip to content

The agent that grows with you

fix(a2a): fail closed on non-loopback bind with empty trusted-peers allowlist (#126756)

JerryLiu369a0cad39f5d55
diff --git a/plugins/platforms/a2a/security.py b/plugins/platforms/a2a/security.py
index cd096ee463f..9b57e9363cc 100644
--- a/plugins/platforms/a2a/security.py
+++ b/plugins/platforms/a2a/security.py
@@ -99,10 +99,32 @@ class A2ASecurityContext:
return f"ip:{client_ip or 'unknown'}"
return None
+ 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
+
def is_trusted_peer(self, identity: str) -> bool:
- """Open when allow-all or localhost-only; else the allow-list (if any) must contain identity."""
- if self.allow_all_users or self.localhost_only() or not self.trusted_peers:
+ """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:
return True
+ if self.is_loopback_bind():
+ if not self.trusted_peers:
+ return True
+ return identity in self.trusted_peers
+ if not self.trusted_peers:
+ 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 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 7e715908798..8d6648e055a 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -189,6 +189,54 @@ 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):
+ """#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_non_loopback_bind_matching_peer_trusted(self, monkeypatch):
+ monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
+ monkeypatch.setenv("A2A_HOST", "0.0.0.0")
+ monkeypatch.setenv("A2A_TRUSTED_PEERS", "alice,bob")
+ monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
+ ctx = security.A2ASecurityContext.capture()
+ assert ctx.is_trusted_peer("alice") is True
+
+ def test_non_loopback_bind_non_matching_peer_rejected(self, monkeypatch):
+ monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
+ monkeypatch.setenv("A2A_HOST", "0.0.0.0")
+ monkeypatch.setenv("A2A_TRUSTED_PEERS", "alice,bob")
+ monkeypatch.delenv("A2A_ALLOW_ALL_USERS", raising=False)
+ ctx = security.A2ASecurityContext.capture()
+ assert ctx.is_trusted_peer("mallory") is False
+
+ def test_non_loopback_bind_allow_all_users_trusts_all(self, monkeypatch):
+ monkeypatch.setenv("A2A_BEARER_TOKEN", "secret")
+ monkeypatch.setenv("A2A_HOST", "0.0.0.0")
+ monkeypatch.setenv("A2A_ALLOW_ALL_USERS", "true")
+ monkeypatch.delenv("A2A_TRUSTED_PEERS", raising=False)
+ ctx = security.A2ASecurityContext.capture()
+ assert ctx.is_trusted_peer("mallory") is True
+
+ 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
+
class TestInjectionFilter:
def test_chatml_defanged(self):