The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): reject the placeholder secrets this repo ships as examples
treatux3335319fe40f
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex 2620c6fdf92..26a6422baf4 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -284,12 +284,34 @@ _PLACEHOLDER_SECRET_VALUES = {"placeholder", "example", "dummy", "null", "none"}+# The two placeholder shapes this repo ships itself, in ``.env.example`` (four providers) and in+# the quickstart / MCP / skill references (``ghp_xxx``, ``hf_xxx``, ``sk-xxxxxxxx``). Both are+# copied verbatim by users, so both must read as "not configured" rather than as a credential.+_PLACEHOLDER_KEY_PREFIXES = ("sk-", "ghp_", "hf_")+++def _is_placeholder_shape(value: str) -> bool:+ """True for the placeholder shapes shipped in .env.example and the docs."""+ lowered = value.lower()+ if lowered.startswith("your_") and lowered.endswith("_here"):+ return True+ for prefix in _PLACEHOLDER_KEY_PREFIXES:+ if lowered.startswith(prefix):+ tail = lowered[len(prefix):]+ if tail and all(c == "x" for c in tail):+ return True+ stripped = lowered.replace(" ", "").replace("-", "").replace("_", "")+ return bool(stripped) and all(c == "x" for c in stripped)++def has_usable_secret(value: Any, *, min_length: int = 4) -> bool:"""Return True when a configured secret looks usable, not empty/placeholder."""if not isinstance(value, str):return Falsecleaned = value.strip()- return len(cleaned) >= min_length and cleaned.lower() not in _PLACEHOLDER_SECRET_VALUES+ return (len(cleaned) >= min_length+ and cleaned.lower() not in _PLACEHOLDER_SECRET_VALUES+ and not _is_placeholder_shape(cleaned))# Known API-key prefixes per provider. Only listed providers get prefix validation; everyone elsediff --git a/hermes_cli/runtime_provider.py b/hermes_cli/runtime_provider.pyindex 1320a5c36d9..3e1ef690b46 100644--- a/hermes_cli/runtime_provider.py+++ b/hermes_cli/runtime_provider.py@@ -607,6 +607,8 @@ def _resolve_from_pool(provider: str, requested_provider: str, model_cfg: Dict[spool_api_key = _pool_entry_api_key(entry)if provider == "nous":entry, pool_api_key = _refresh_nous_pool_entry(pool, entry, pool_api_key)+ if not has_usable_secret(pool_api_key):+ return Noneif pool_api_key and credential_pool_matches_provider(pool, provider, base_url=_pool_entry_base_url(entry)):return _resolve_runtime_from_pool_entry(provider=provider, entry=entry, requested_provider=requested_provider,model_cfg=model_cfg, pool=pool, target_model=target_model)diff --git a/tests/hermes_cli/test_auth_placeholder_rejection.py b/tests/hermes_cli/test_auth_placeholder_rejection.pynew file mode 100644index 00000000000..ace002183f2--- /dev/null+++ b/tests/hermes_cli/test_auth_placeholder_rejection.py@@ -0,0 +1,87 @@+"""Placeholder credentials must read as "not configured", never as a usable secret.++``.env.example`` ships ``your_key_here`` for four providers (Xiaomi, Upstage, Ramp Router,+Nebius) and ``your_google_ai_studio_key_here`` / ``your_gemini_key_here`` /+``your_ollama_key_here`` for three more; the quickstart and MCP/skill references use+``sk-xxx`` / ``ghp_xxx`` / ``hf_xxx``. ``has_usable_secret`` only knew the exact string+``your_api_key_here``, so every other shipped placeholder was treated as a real credential and+sent upstream — an opaque 401 instead of failing loud at the read point.++Regression for the placeholder shapes; the pooled-key case covers the sibling resolution path.+"""++import pytest++from hermes_cli.auth import has_usable_secret, AuthError+++class TestHasUsableSecretPlaceholderRejection:+ """has_usable_secret must reject common placeholder patterns."""++ @pytest.mark.parametrize("placeholder", [+ # every placeholder shape shipped by this repo's own .env.example+ "your_key_here",+ "your_google_ai_studio_key_here",+ "your_gemini_key_here",+ "your_ollama_key_here",+ "your_api_key_here",+ # the x-run convention used in quickstart / MCP / skill references+ "sk-xxx",+ "sk-XXXX",+ "ghp_xxxxxxxxxxxxxxxxxxxx",+ "xxxx xxxx xxxx xxxx",+ "hf_xxxx",+ "XXXXXXXX",+ ])+ def test_rejects_placeholder_patterns(self, placeholder):+ assert not has_usable_secret(placeholder)++ @pytest.mark.parametrize("real_key", [+ "sk-or-v1-abc123",+ "ghp_real_token_here",+ "hf_real_token",+ "xai-real-key-123",+ "sk-test-1234567890abcdef",+ ])+ def test_accepts_real_looking_keys(self, real_key):+ assert has_usable_secret(real_key)+++class TestRuntimeRejectsPlaceholderApiKey:+ """Placeholder env vars must raise AuthError with guidance at resolution time."""++ def test_xai_placeholder_raises(self, monkeypatch):+ monkeypatch.setenv("XAI_API_KEY", "your_key_here")+ from hermes_cli.runtime_provider import resolve_runtime_provider+ with pytest.raises(AuthError, match="No usable credentials found for provider 'xai'"):+ resolve_runtime_provider(requested="xai")++ def test_openrouter_placeholder_fallback_to_empty_key(self, monkeypatch):+ """OpenRouter silently falls back to free-tier when the env key is a placeholder."""+ monkeypatch.setenv("OPENROUTER_API_KEY", "sk-xxx")+ from hermes_cli.runtime_provider import resolve_runtime_provider+ runtime = resolve_runtime_provider(requested="openrouter")+ assert runtime.get("api_key") == ""+ assert runtime.get("provider") == "openrouter"++ def test_pooled_placeholder_is_not_used_as_a_credential(self, tmp_path, monkeypatch):+ """The credential pool is the sibling path: a pooled placeholder must behave exactly like+ no credential at all, never like a configured key."""+ import uuid++ monkeypatch.setenv("HERMES_HOME", str(tmp_path / "hermes"))+ (tmp_path / "hermes").mkdir(parents=True, exist_ok=True)+ monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)++ from agent.credential_pool import AUTH_TYPE_API_KEY, SOURCE_MANUAL, PooledCredential, load_pool++ pool = load_pool("openrouter")+ pool.add_entry(PooledCredential(+ provider="openrouter", id=uuid.uuid4().hex[:6], label="pasted-example",+ auth_type=AUTH_TYPE_API_KEY, priority=0, source=SOURCE_MANUAL,+ access_token="your_key_here", base_url="https://openrouter.ai/api/v1",+ ))++ from hermes_cli.runtime_provider import resolve_runtime_provider+ runtime = resolve_runtime_provider(requested="openrouter")+ assert runtime.get("api_key") == "", "a pooled .env.example placeholder was used as a key"