Skip to content

The agent that grows with you

fix(a2a): accept the absolute form localhost. in the no-token Host check

John Paul Soliva53d28d9b8523
diff --git a/plugins/platforms/a2a/security.py b/plugins/platforms/a2a/security.py
index 03257d39697..4fd3f5dcdce 100644
--- a/plugins/platforms/a2a/security.py
+++ b/plugins/platforms/a2a/security.py
@@ -217,7 +217,8 @@ def is_loopback_host_header(host_header: Optional[str]) -> bool:
parts.port # noqa: B018 -- raises ValueError on a malformed port
except ValueError:
return False
- return (parts.hostname or "").lower() in _LOOPBACK_HOST_NAMES
+ # ``localhost.`` is the absolute form of ``localhost``; a rebound name stays foreign either way.
+ return (parts.hostname or "").lower().rstrip(".") in _LOOPBACK_HOST_NAMES
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.py
index 16a98259bb2..08e4ca328f0 100644
--- a/tests/plugins/test_a2a_plugin.py
+++ b/tests/plugins/test_a2a_plugin.py
@@ -1332,7 +1332,9 @@ class TestInboundRoundTrip:
(None, True), # urllib's own Host: 127.0.0.1:<port>
("localhost", True),
("[::1]", True),
- ("rebound.example", False), # a page's hostname re-resolved to 127.0.0.1
+ ("localhost.", True), # absolute form of localhost
+ ("rebound.example", False),
+ ("rebound.example.", False), # a page's hostname re-resolved to 127.0.0.1
])
def test_no_token_listener_serves_only_loopback_host_names(monkeypatch, host, served):
"""Without a token the listener trusts the loopback socket; a page on a hostname re-resolved to