Skip to content

The agent that grows with you

fix(aux): local-server aliases never borrow OPENAI_API_KEY for the lane's base_url

teknium15b80838ea252
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index 604fce113ec..d8763472ea6 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -4895,12 +4895,18 @@ def _resolve_custom_branch(req: _ResolveRequest) -> _ResolveResult:
custom_base = custom_base.rstrip("/") + "/v1"
if req.api_mode == "anthropic_messages":
wrap_base = (req.explicit_base_url or "").strip().rstrip("/")
- custom_key = (
- (req.explicit_api_key or "").strip()
- or _scoped_key_env("OPENAI_API_KEY")
- or _read_main_api_key_if_same_host(custom_base)
- or "no-key-required" # local servers don't need auth
- )
+ if req.original_provider in _LOCAL_SERVER_ALIASES:
+ # SECURITY: a local-server alias never borrows OPENAI_API_KEY or the main key —
+ # the alias means "this is my own server"; sending an OpenAI secret to whatever
+ # host base_url names is never intended. Explicit api_key or the placeholder only.
+ custom_key = (req.explicit_api_key or "").strip() or "no-key-required"
+ else:
+ custom_key = (
+ (req.explicit_api_key or "").strip()
+ or _scoped_key_env("OPENAI_API_KEY")
+ or _read_main_api_key_if_same_host(custom_base)
+ or "no-key-required" # local servers don't need auth
+ )
if not custom_base:
logger.warning("resolve_provider_client: explicit custom endpoint requested but base_url is empty")
return None, None
diff --git a/tests/agent/test_auxiliary_ollama_local_provider.py b/tests/agent/test_auxiliary_ollama_local_provider.py
index e34a4cde845..6d25253a8cb 100644
--- a/tests/agent/test_auxiliary_ollama_local_provider.py
+++ b/tests/agent/test_auxiliary_ollama_local_provider.py
@@ -38,12 +38,26 @@ def _client_attr(client, attr: str) -> str:
return ""
[email protected]("api_key, expected_key", [("", "no-key-required"), ("test-key-123", "test-key-123")])
-def test_ollama_lane_with_bare_local_host_resolves_custom_client_under_v1(monkeypatch, api_key, expected_key):
+ "api_key, env_openai_key, expected_key",
+ [
+ ("", "", "no-key-required"),
+ ("test-key-123", "", "test-key-123"),
+ # SECURITY: a keyless local-server lane must not borrow OPENAI_API_KEY (or the main
+ # key on a host match) — that would send an OpenAI secret to the lane's base_url.
+ ("", "sk-USER-OPENAI-SECRET", "no-key-required"),
+ ],
+)
+def test_ollama_lane_with_bare_local_host_resolves_custom_client_under_v1(
+ monkeypatch, api_key, env_openai_key, expected_key,
+):
"""The reporter's lane, through the real task-config path: keyless gets the placeholder,
an explicit key is sent verbatim, and both post to /v1."""
from agent import auxiliary_client as ac
+ if env_openai_key:
+ monkeypatch.setenv("OPENAI_API_KEY", env_openai_key)
+ monkeypatch.setattr(ac, "_read_main_api_key_if_same_host", lambda _base: "sk-MAIN-SECRET")
lane = {"provider": "ollama", "model": "qwen3.8:27b", "base_url": "http://127.0.0.1:11434", "api_key": api_key}
monkeypatch.setattr(ac, "_get_auxiliary_task_config", lambda task: dict(lane) if task == "title_generation" else {})
provider, model, base_url, key, _mode = ac._resolve_task_provider_model("title_generation")