diff --git a/hermes_cli/providers.py b/hermes_cli/providers.py index 57483e9982..241b51d700 100644 --- a/hermes_cli/providers.py +++ b/hermes_cli/providers.py @@ -592,9 +592,11 @@ def is_official_openai_host(base_url: str) -> bool: (``proxy.test/api.openai.com/v1``) are rejected. A genuine ``*.api.openai.com`` subdomain requires control of openai.com DNS, so the dot-suffix match does not reopen the #32243 spoofing hole. + Delegates to ``utils.base_url_host_matches``, which owns the + exact-or-dot-suffix hostname contract (userinfo/port stripped, + lowercased, trailing dot removed) — one implementation, not two. """ - hostname = base_url_hostname(base_url) - return hostname == "api.openai.com" or hostname.endswith(".api.openai.com") + return base_url_host_matches(base_url, "api.openai.com") def host_mandated_api_mode(base_url: str = "") -> Optional[str]: diff --git a/tests/hermes_cli/test_official_openai_host.py b/tests/hermes_cli/test_official_openai_host.py index da0c92b556..8d91adfe5f 100644 --- a/tests/hermes_cli/test_official_openai_host.py +++ b/tests/hermes_cli/test_official_openai_host.py @@ -26,6 +26,9 @@ class TestOfficialHosts: "https://eu.api.openai.com/v1", "https://US.api.OpenAI.com/v1", # case-insensitive hostname "https://in.api.openai.com/v1", # future regional variants + "https://api.openai.com:443/v1", # port stripped by hostname parse + "https://api.openai.com./v1", # trailing dot normalized + "https://attacker.test@us.api.openai.com/v1", # userinfo stripped; real host wins ], ) def test_official_hosts_match(self, url): @@ -50,6 +53,8 @@ class TestSpoofRejection: # Unrelated hosts. "https://openrouter.ai/api/v1", "https://api.anthropic.com/v1", + # IPv6 literal and empty input. + "https://[::1]:8080/v1", "", ], )