The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(env): a parent-injected dashboard session token survives the .env reload
teknium1d5c2e0fb169f
diff --git a/hermes_cli/env_loader.py b/hermes_cli/env_loader.pyindex 1addf557580..741aa573c0a 100644--- a/hermes_cli/env_loader.py+++ b/hermes_cli/env_loader.py@@ -54,6 +54,13 @@ _DOTENV_PUBLISHED: dict[str, tuple[str | None, str, int]] = {}_DOTENV_PASSES = itertools.count()_DOTENV_LOCK = threading.RLock()+# Per-process credentials a parent mints and injects into the child's environment (the Desktop shell /+# a link-style launcher spawns `hermes dashboard` with a fresh HERMES_DASHBOARD_SESSION_TOKEN and keeps+# the same token for its own /api probes). They are never .env configuration, so a persisted value in+# ~/.hermes/.env must not replace an injected one — the parent would then 401 against its own child+# (#115955). A value an earlier dotenv pass published is still reloaded normally.+_SPAWN_CREDENTIAL_KEYS: frozenset[str] = frozenset({"HERMES_DASHBOARD_SESSION_TOKEN"})+# Behavioral routing keys a parent Hermes process injects into child env that silently redirect a profile# onto the wrong provider path; these — and ONLY these — are scrubbed at startup when absent from the# profile's .env. Credentials are excluded: shell exports are a documented way to supply them, and@@ -300,8 +307,11 @@ def _load_dotenv_with_fallback(path: Path, *, override: bool, load_pass: int | Ncontinuecurrent = os.environ.get(name)record = _DOTENV_PUBLISHED.get(name)+ ours = record is not None and current == record[1]+ if name in _SPAWN_CREDENTIAL_KEYS and current and not ours:+ continue # parent-minted per-process credential: .env must not split it from the parent# Ours and untouched since → keep the original baseline; anything else is a newer outside value.- baseline = record[0] if record is not None and current == record[1] else current+ baseline = record[0] if ours else currentos.environ[name] = value_DOTENV_PUBLISHED[name] = (baseline, value, load_pass)_sanitize_loaded_credentials() # httpx encodes headers as ASCIIdiff --git a/tests/hermes_cli/test_env_loader.py b/tests/hermes_cli/test_env_loader.pyindex 4ab389ffe43..05f22348f75 100644--- a/tests/hermes_cli/test_env_loader.py+++ b/tests/hermes_cli/test_env_loader.py@@ -650,3 +650,40 @@ def test_other_profile_home_does_not_bridge_process_config(tmp_path, monkeypatch# The other profile's .env value stands; the process config was not applied.assert os.getenv("TERMINAL_ENV") == "docker"+++def test_parent_injected_dashboard_session_token_survives_dotenv(tmp_path, monkeypatch):+ """A parent that spawns `hermes dashboard` mints HERMES_DASHBOARD_SESSION_TOKEN and keeps it for+ its own /api probes; a persisted token in ~/.hermes/.env must not replace it, or the parent gets+ HTTP 401 from its own child (#115955). Ordinary keys keep the documented .env-wins precedence."""+ home = tmp_path / "hermes"+ home.mkdir()+ (home / ".env").write_text(+ "HERMES_DASHBOARD_SESSION_TOKEN=persisted-token\nHERMES_DASHBOARD_PUBLIC_URL=http://127.0.0.1:1\n",+ encoding="utf-8",+ )+ monkeypatch.setenv("HERMES_DASHBOARD_SESSION_TOKEN", "link-token")+ monkeypatch.setenv("HERMES_DASHBOARD_PUBLIC_URL", "http://127.0.0.1:43123")++ load_hermes_dotenv(hermes_home=home)+ assert os.environ["HERMES_DASHBOARD_SESSION_TOKEN"] == "link-token"+ assert os.environ["HERMES_DASHBOARD_PUBLIC_URL"] == "http://127.0.0.1:1" # control: .env still wins++ # Reload with the same injection: the injected value still holds.+ load_hermes_dotenv(hermes_home=home)+ assert os.environ["HERMES_DASHBOARD_SESSION_TOKEN"] == "link-token"+++def test_dotenv_published_dashboard_session_token_still_reloads(tmp_path, monkeypatch):+ """No injection: the .env token is published, and a later edit + reload replaces the value the+ earlier pass published (the guard only protects values dotenv did not put there)."""+ home = tmp_path / "hermes"+ home.mkdir()+ monkeypatch.delenv("HERMES_DASHBOARD_SESSION_TOKEN", raising=False)+ (home / ".env").write_text("HERMES_DASHBOARD_SESSION_TOKEN=first\n", encoding="utf-8")+ load_hermes_dotenv(hermes_home=home)+ assert os.environ["HERMES_DASHBOARD_SESSION_TOKEN"] == "first"++ (home / ".env").write_text("HERMES_DASHBOARD_SESSION_TOKEN=second\n", encoding="utf-8")+ load_hermes_dotenv(hermes_home=home)+ assert os.environ["HERMES_DASHBOARD_SESSION_TOKEN"] == "second"diff --git a/website/docs/reference/environment-variables.md b/website/docs/reference/environment-variables.mdindex 074433d96a2..a91adb2bc75 100644--- a/website/docs/reference/environment-variables.md+++ b/website/docs/reference/environment-variables.md@@ -573,6 +573,7 @@ Three dashboard-auth providers ship in the box. For a remote Hermes Desktop conn| `HERMES_DASHBOARD_BASIC_AUTH_SECRET` | HMAC key (32+ bytes, base64/hex/raw) signing the basic provider's stateless session tokens. Set explicitly so sessions survive restarts / span multiple workers; blank → random per-process (you'll be logged out on every restart). Overrides `dashboard.basic_auth.secret`. || `HERMES_DASHBOARD_BASIC_AUTH_TTL_SECONDS` | Access-token lifetime for the basic provider (default 12h). Overrides `dashboard.basic_auth.session_ttl_seconds`. || `HERMES_DASHBOARD_OAUTH_CLIENT_ID` | OAuth client id (`agent:{instance_id}`) for the gated/public dashboard, activating the Nous (`plugins/dashboard_auth/nous`) provider. Overrides `dashboard.oauth.client_id`. Provision it with `hermes dashboard register`. |+| `HERMES_DASHBOARD_SESSION_TOKEN` | Per-process session token for the dashboard's sensitive `/api` routes, minted by the launcher that spawns `hermes dashboard` (Desktop shell, link-style integrations). A value injected by the parent process is kept as-is: a `HERMES_DASHBOARD_SESSION_TOKEN` line in `~/.hermes/.env` does not replace it. Unset, the server mints a fresh token per start. || `HERMES_DASHBOARD_PUBLIC_URL` | Complete public URL the dashboard is reached at behind a reverse proxy. It controls OAuth callback construction, adds its exact hostname to the HTTP Host/WebSocket Origin guard, and requires the auth gate for non-loopback public hosts even when the backend binds to loopback. Overrides `dashboard.public_url`. || `HERMES_DASHBOARD_OIDC_ISSUER` | OIDC issuer URL for the bundled self-hosted OIDC provider (`plugins/dashboard_auth/self_hosted`). Required to activate it. Overrides `dashboard.oauth.self_hosted.issuer`. || `HERMES_DASHBOARD_OIDC_CLIENT_ID` | Public OIDC client id (authorization-code + PKCE) for the self-hosted OIDC provider. Required to activate it. Overrides `dashboard.oauth.self_hosted.client_id`. |