The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(web): a routed profile without an Exa/Parallel key is refused, not served on the launch key
teknium16b6c7f4a99f1
diff --git a/agent/web_search_provider.py b/agent/web_search_provider.pyindex 4c5e393241d..947b95cc044 100644--- a/agent/web_search_provider.py+++ b/agent/web_search_provider.py@@ -27,7 +27,9 @@ def get_provider_env(name: str) -> str:delegate children / subprocess runs. Stripped value, or ``""`` when unset.Falls back to a bare ``os.getenv`` when the config module is unavailable (stripped installs, early- import contexts). See #40190.+ import contexts). See #40190. Never when a profile secret scope is bound: a scoped miss means the+ served profile has no key, and ``os.environ`` holds the LAUNCH profile's — a routed profile without+ an Exa/Parallel key must be refused, not search on another profile's key."""try:from hermes_cli.config import get_env_value@@ -35,11 +37,19 @@ def get_provider_env(name: str) -> str:val = get_env_value(name)except Exception: # noqa: BLE001 — config layer optional hereval = None- if val is None:+ if val is None and not _secret_scope_bound():val = os.getenv(name, "")return (val or "").strip()+def _secret_scope_bound() -> bool:+ try:+ from agent.secret_scope import current_secret_scope+ except Exception: # noqa: BLE001 — stripped install without the scope module+ return False+ return current_secret_scope() is not None++class WebSearchProvider(ProviderBase):"""Abstract base class for a web search/extract backend: implement :meth:`is_available`and at least one of :meth:`search` / :meth:`extract`; the ``supports_*`` flags route each capability."""diff --git a/tests/plugins/video_gen/test_openrouter.py b/tests/plugins/video_gen/test_openrouter.pyindex 2d9f6b2fa02..3fbb723d4d0 100644--- a/tests/plugins/video_gen/test_openrouter.py+++ b/tests/plugins/video_gen/test_openrouter.py@@ -194,6 +194,34 @@ def test_multiplexed_profile_spends_its_own_key_not_the_launch_profiles(monkeypaassert session.posts[0][0] == "https://profile-b.example/api/v1/videos"+def test_multiplexed_profile_without_a_key_is_refused_not_served_on_the_launch_key(monkeypatch, tmp_path):+ """Absence on the routed side: a profile with no OpenRouter credential of its own must fail closed, never+ spend the launch profile's ``os.environ`` key."""+ from agent.secret_scope import build_profile_secret_scope, reset_secret_scope, set_multiplex_active, set_secret_scope+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-launch-profile")+ profile_home = tmp_path / "profile-nokey"+ profile_home.mkdir()+ (profile_home / ".env").write_text("")+ provider = _provider(monkeypatch, [_VEO])++ set_multiplex_active(True)+ home_token = set_hermes_home_override(str(profile_home))+ secret_token = set_secret_scope(build_profile_secret_scope(profile_home))+ try:+ available = provider.is_available()+ result, session, bearers = _generate_capturing(monkeypatch, tmp_path, provider)+ finally:+ reset_secret_scope(secret_token)+ reset_hermes_home_override(home_token)+ set_multiplex_active(False)++ assert available is False+ assert result["success"] is False and result["error_type"] == "missing_credentials", result+ assert session.posts == [] and bearers == []++def test_generate_rejects_local_image_paths_before_spending(monkeypatch):monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-test")provider = _provider(monkeypatch, [_VEO])diff --git a/tests/tools/test_web_tools_config.py b/tests/tools/test_web_tools_config.pyindex 77f2b67991d..b504d98e419 100644--- a/tests/tools/test_web_tools_config.py+++ b/tests/tools/test_web_tools_config.py@@ -490,14 +490,17 @@ class TestExaClientConfig:self._lazy_gate_patch.stop()def test_multiplexed_profiles_search_with_their_own_key(self, tmp_path, monkeypatch):- """One process serving two profiles: each turn's search goes out with its own profile's key."""+ """One process serving two profiles: each turn's search goes out with its own profile's key, and a+ profile WITHOUT a key is refused — never served on the launch profile's ``os.environ`` key."""from agent import secret_scopefrom plugins.web.exa.provider import ExaWebSearchProviderhomes = {}- for name in ("a", "b"):+ for name, line in (("a", "EXA_API_KEY=key-a\n"), ("b", "EXA_API_KEY=key-b\n"), ("nokey", "")):homes[name] = tmp_path / namehomes[name].mkdir()- (homes[name] / ".env").write_text(f"EXA_API_KEY=key-{name}\n")+ (homes[name] / ".env").write_text(line)+ monkeypatch.setenv("EXA_API_KEY", "key-launch")+ monkeypatch.setattr("plugins.web.keyless_mcp.keyless_enabled", lambda: False)monkeypatch.setattr(secret_scope, "_MULTIPLEX_ACTIVE", True)def sent_with(name):@@ -506,10 +509,22 @@ class TestExaClientConfig:result = ExaWebSearchProvider().search("q")finally:secret_scope.reset_secret_scope(token)- assert result["success"], result+ if not result["success"]:+ return result["error"]return result["data"]["web"][0]["description"]assert [sent_with("a"), sent_with("b"), sent_with("a")] == ["key-a", "key-b", "key-a"]+ assert "EXA_API_KEY" in sent_with("nokey") and "key-launch" not in sent_with("nokey")+ assert sent_with("a") == "key-a"++ def test_single_profile_process_env_still_serves_the_key(self, monkeypatch):+ """Control: no profile scope bound (plain CLI / systemd-injected env) keeps reading os.environ."""+ from plugins.web.exa.provider import ExaWebSearchProvider+ monkeypatch.setenv("EXA_API_KEY", "key-env")+ monkeypatch.setattr("plugins.web.keyless_mcp.keyless_enabled", lambda: False)+ result = ExaWebSearchProvider().search("q")+ assert result["success"], result+ assert result["data"]["web"][0]["description"] == "key-env"class TestWebSearchSchema: