The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(dashboard): reject legacy credential masks by shape, not equality
kshitijk4pooraf4c9286d5ae
diff --git a/hermes_cli/web_routers/_common.py b/hermes_cli/web_routers/_common.pyindex 67b44b2556e..e5a28a5352e 100644--- a/hermes_cli/web_routers/_common.py+++ b/hermes_cli/web_routers/_common.py@@ -7,6 +7,7 @@ from __future__ import annotationsimport asyncioimport contextlibimport logging+import reimport sqlite3import timefrom typing import Any, Callable, Dict, Optional@@ -131,16 +132,18 @@ def redacted_credential_preview(value: Any) -> Optional[str]:return f"«redacted:{redact_key(str(value))}»"-def is_redacted_credential_preview(submitted: Any, current: Any = None) -> bool:- """Recognize current and stale dashboard previews without guessing from key shape."""+# Legacy bare masks (pre-sentinel pages, older Desktop builds) are recognised by the+# producer shape of ``agent.redact.mask_secret`` — never by equality to the current+# secret, which would authorise a stale preview after a rotation (#121002).+_LEGACY_MASK_RE = re.compile(r".{4}\.\.\..{4}")+++def is_redacted_credential_preview(submitted: Any) -> bool:+ """Recognize current, stale and legacy dashboard previews by shape alone."""value = str(submitted or "")if value == "«redacted-secret»" or (value.startswith("«redacted:") and value.endswith("»")):return True- if current:- # Compatibility with a page opened before the non-reusable sentinel contract.- from hermes_cli.config import redact_key- return value == redact_key(str(current))- return False+ return value == "***" or _LEGACY_MASK_RE.fullmatch(value) is not None# Corrupt-store reporting for polled read endpoints. The dashboard polls analytics every fewdiff --git a/hermes_cli/web_routers/config_env.py b/hermes_cli/web_routers/config_env.pyindex 0487c81147e..296c0d4c9ac 100644--- a/hermes_cli/web_routers/config_env.py+++ b/hermes_cli/web_routers/config_env.py@@ -299,8 +299,7 @@ async def set_env_var(body: EnvVarUpdate, profile: Optional[str] = None):from hermes_cli.credential_lifecycle import save_provider_env_credentialdef _save():- current = load_env().get(body.key)- if is_redacted_credential_preview(body.value, current):+ if is_redacted_credential_preview(body.value):raise ValueError(REDACTED_CREDENTIAL_WRITE_DETAIL)return save_provider_env_credential(body.key, body.value)@@ -627,14 +626,9 @@ def _write_custom_endpoint(cfg: Dict[str, Any], body: CustomEndpointUpdate) -> Tenv_var = custom_endpoint_key_env(endpoint_id)submitted_key = body.api_key.strip() if body.api_key is not None else Noneif submitted_key:- display_preview = _api_key_display(existing)[1]- existing_key_env = str(existing.get("key_env") or "").strip()- stored_secret = load_env().get(existing_key_env) if existing_key_env else None- if (- submitted_key == display_preview- or re.fullmatch(r"\$\{[^}]+\}", submitted_key)- or is_redacted_credential_preview(submitted_key, stored_secret)- ):+ # ``${KEY_ENV}`` is the GET display for key_env entries; the helper covers the+ # sentinel and legacy masks. Either one is display-only, current or stale.+ if re.fullmatch(r"\$\{[^}]+\}", submitted_key) or is_redacted_credential_preview(submitted_key):raise HTTPException(status_code=400, detail=REDACTED_CREDENTIAL_WRITE_DETAIL)save_env_value(env_var, submitted_key)entry["key_env"] = env_vardiff --git a/hermes_cli/web_routers/messaging.py b/hermes_cli/web_routers/messaging.pyindex 41f146d9927..3f93b66e88b 100644--- a/hermes_cli/web_routers/messaging.py+++ b/hermes_cli/web_routers/messaging.py@@ -199,11 +199,6 @@ def _platform_enablement(return enabled, configured, home_channel-def _messaging_env_value(key: str, env_on_disk: dict[str, str], *, scoped: bool) -> str:- """Resolve the credential source shared by Messaging GET and write preflight."""- return env_on_disk.get(key) or ("" if scoped else os.getenv(key, ""))--def _messaging_platform_payload(entry: dict[str, Any], env_on_disk: dict[str, str], runtime: dict | None,scoped: bool = False, profile_home: Optional[Path] = None,@@ -233,7 +228,9 @@ def _messaging_platform_payload(runtime_platform = {}def env_value(key: str) -> str:- return _messaging_env_value(key, env_on_disk, scoped=scoped)+ # Profile-scoped: judge only the profile's own .env — the dashboard process's+ # os.environ carries the ROOT install's .env and would report root credentials as the profile's.+ return env_on_disk.get(key) or ("" if scoped else os.getenv(key, ""))env_vars = [{@@ -877,12 +874,10 @@ async def update_messaging_platform(platform_id: str, body: MessagingPlatformUpdraise HTTPException(status_code=400, detail=f"{key} is not configurable for {entry['name']}")def _apply():- with _profile_scope(target_profile) as scoped_dir:- env_on_disk = load_env()+ with _profile_scope(target_profile):updates: dict[str, str] = {}- # Validate the whole request against the same credential snapshot the GET- # response uses before clearing or replacing anything.+ # Validate the whole request before clearing or replacing anything.for key in body.clear_env:_check_allowed(key)for key, value in body.env.items():@@ -890,8 +885,7 @@ async def update_messaging_platform(platform_id: str, body: MessagingPlatformUpdtrimmed = value.strip()if not trimmed:continue- current = _messaging_env_value(key, env_on_disk, scoped=scoped_dir is not None)- if is_redacted_credential_preview(trimmed, current):+ if is_redacted_credential_preview(trimmed):raise HTTPException(status_code=400, detail=REDACTED_CREDENTIAL_WRITE_DETAIL)_validate_messaging_env_value(platform_id, key, trimmed)updates[key] = trimmed