Skip to content

The agent that grows with you

fix(auxiliary): inherit the main API key only on the identical origin

John Paul Soliva4678fa512107
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 98c4e4eac81..41e5a9b3376 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -2509,12 +2509,13 @@ def _read_main_model_for_aux() -> str:
def _read_main_api_key_if_same_host(aux_base_url: str) -> str:
- """Main api_key only when *aux_base_url* shares the main base_url's host.
+ """Main api_key only when *aux_base_url* has the main base_url's exact origin.
Unconditional inheritance would leak the credential to any misconfigured host; mismatch keeps ``no-key-required`` → 401.
+ Origin, not hostname: another scheme (``http://``) or port on the same host is a different endpoint.
"""
- aux_host = base_url_hostname(aux_base_url)
- if not aux_host or aux_host != base_url_hostname(_read_main_base_url()):
+ aux_origin = base_url_origin(aux_base_url)
+ if not aux_origin[1] or aux_origin != base_url_origin(_read_main_base_url()):
return ""
return _read_main_api_key()
diff --git a/tests/agent/test_auxiliary_client.py b/tests/agent/test_auxiliary_client.py
index 1c0781e8443..0e339ed502f 100644
--- a/tests/agent/test_auxiliary_client.py
+++ b/tests/agent/test_auxiliary_client.py
@@ -4789,6 +4789,28 @@ class TestCustomEndpointApiKeyInheritance:
assert captured.get("api_key") == "no-key-required"
+ @pytest.mark.parametrize("aux_base_url,inherits", [
+ ("https://gw.example.com:443/v2", True),
+ ("http://gw.example.com/v1", False),
+ ("https://gw.example.com:8443/v1", False),
+ ])
+ def test_main_key_follows_only_the_identical_origin(self, monkeypatch, aux_base_url, inherits):
+ """Same hostname is not the same endpoint: a different scheme or port must not
+ receive the main key; the identical origin (default port spelled out) still does."""
+ import agent.auxiliary_client as ac
+
+ monkeypatch.delenv("OPENAI_API_KEY", raising=False)
+ fake_config = {"model": {"api_key": "sk-main-config-key", "base_url": "https://gw.example.com/v1"}}
+ captured: dict = {}
+
+ with patch("hermes_cli.config.load_config", return_value=fake_config), \
+ patch("hermes_cli.config.load_config_readonly", return_value=fake_config), \
+ patch.object(ac, "_create_openai_client", side_effect=lambda **kw: captured.update(kw) or MagicMock()):
+ resolve_provider_client("custom", model="test-model",
+ explicit_base_url=aux_base_url, explicit_api_key=None)
+
+ assert (captured.get("api_key") == "sk-main-config-key") is inherits
+
class TestNoProgressTimeoutTaskConfigGating:
"""#108104: ``auxiliary.<task>.no_progress_timeout`` must only reach the request kwargs