Skip to content

The agent that grows with you

fix(terminal-env): adapter secrets are the declared ones, not any platform-named variable

kshitijk4pooree942a7bbff7
diff --git a/gateway/platform_registry.py b/gateway/platform_registry.py
index ea1ecc10b6b..c2b82f2c3df 100644
--- a/gateway/platform_registry.py
+++ b/gateway/platform_registry.py
@@ -348,6 +348,13 @@ class PlatformRegistry:
entries, deferred = self._scope_maps(self.current_scope_key())
return entries.keys() | deferred.keys() | self._entries.keys() | self._deferred.keys()
+ def required_env_names(self) -> set[str]:
+ """``required_env`` of every loaded entry (current profile scope AND process-global) without
+ loading deferred adapters; the child-env scrub reads this on every spawn."""
+ with self._lock:
+ entries, _deferred = self._scope_maps(self.current_scope_key())
+ return {n for e in (*self._entries.values(), *entries.values()) for n in e.required_env}
+
def is_registered(self, name: str) -> bool:
# A deferred (not-yet-imported) platform still counts as registered so cheap membership
# checks (toolset resolution, webhook deliver-target checks) never trigger a heavy import.
diff --git a/plugins/platforms/a2a/plugin.yaml b/plugins/platforms/a2a/plugin.yaml
index 110267dea59..a45b0042721 100644
--- a/plugins/platforms/a2a/plugin.yaml
+++ b/plugins/platforms/a2a/plugin.yaml
@@ -48,6 +48,10 @@ optional_env:
description: "Shared bearer token for inbound A2A calls (identity falls back to caller IP). With no token of any kind => bind to 127.0.0.1 only (no remote access)."
prompt: "A2A shared bearer token (or empty for localhost-only)"
password: true
+ - name: A2A_PUSH_SECRET
+ description: "HMAC secret for signing push notifications (default: the shared bearer token)."
+ prompt: "A2A push signing secret (or empty)"
+ password: true
- name: A2A_HOST
description: "Inbound bind host. Defaults to 127.0.0.1; only widens to 0.0.0.0 when a bearer token is set AND you opt in here."
prompt: "A2A bind host (default 127.0.0.1)"
diff --git a/plugins/platforms/photon/plugin.yaml b/plugins/platforms/photon/plugin.yaml
index bfd028361b6..1d6468582fa 100644
--- a/plugins/platforms/photon/plugin.yaml
+++ b/plugins/platforms/photon/plugin.yaml
@@ -34,6 +34,10 @@ optional_env:
description: "Loopback port for the Node sidecar control + inbound channel (default 8789)"
prompt: "Sidecar control port"
password: false
+ - name: PHOTON_SIDECAR_TOKEN
+ description: "Shared secret for the loopback sidecar channel (default: random per start)"
+ prompt: "Sidecar token"
+ password: true
- name: PHOTON_SIDECAR_AUTOSTART
description: "Spawn the Node sidecar on connect (true/false, default true)"
prompt: "Auto-start the sidecar?"
diff --git a/plugins/platforms/teams/plugin.yaml b/plugins/platforms/teams/plugin.yaml
index b0d6394791f..4296905d0f4 100644
--- a/plugins/platforms/teams/plugin.yaml
+++ b/plugins/platforms/teams/plugin.yaml
@@ -54,3 +54,11 @@ optional_env:
description: "Display name for the Teams home channel"
prompt: "Home channel display name"
password: false
+ - name: TEAMS_INCOMING_WEBHOOK_URL
+ description: "Incoming-webhook URL for meeting-summary delivery in webhook mode (the URL is the credential)"
+ prompt: "Incoming webhook URL (or empty)"
+ password: true
+ - name: TEAMS_GRAPH_ACCESS_TOKEN
+ description: "Microsoft Graph access token for meeting-summary delivery in graph mode"
+ prompt: "Graph access token (or empty)"
+ password: true
diff --git a/plugins/platforms/telegram/plugin.yaml b/plugins/platforms/telegram/plugin.yaml
index 468081d2d38..76ea417f29d 100644
--- a/plugins/platforms/telegram/plugin.yaml
+++ b/plugins/platforms/telegram/plugin.yaml
@@ -33,3 +33,7 @@ optional_env:
description: "Display name for the Telegram home channel"
prompt: "Home channel display name"
password: false
+ - name: TELEGRAM_WEBHOOK_SECRET
+ description: "Secret token Telegram sends with each webhook update (required with TELEGRAM_WEBHOOK_URL)"
+ prompt: "Webhook secret"
+ password: true
diff --git a/tests/tools/test_local_env_blocklist.py b/tests/tools/test_local_env_blocklist.py
index 11e099f694a..6bc72d21d88 100644
--- a/tests/tools/test_local_env_blocklist.py
+++ b/tests/tools/test_local_env_blocklist.py
@@ -92,12 +92,18 @@ def test_terminal_child_observes_declared_policy(child_env, monkeypatch):
# Secrets adapters read straight from the environment (webhook signing secrets, access tokens,
-# app secrets), built-in and plugin adapters alike, none of them listed in OPTIONAL_ENV_VARS.
+# app secrets), declared in the gateway env-override table, a plugin manifest, or the policy's
+# own short list, none of them among the hand-written OPTIONAL_ENV_VARS entries.
ADAPTER_SECRETS = """
-WHATSAPP_CLOUD_ACCESS_TOKEN WHATSAPP_CLOUD_APP_SECRET WHATSAPP_CLOUD_VERIFY_TOKEN WEIXIN_TOKEN
+TEAMS_INCOMING_WEBHOOK_URL WHATSAPP_CLOUD_ACCESS_TOKEN WHATSAPP_CLOUD_APP_SECRET WHATSAPP_CLOUD_VERIFY_TOKEN WEIXIN_TOKEN
YUANBAO_APP_SECRET FEISHU_ENCRYPT_KEY FEISHU_VERIFICATION_TOKEN TELEGRAM_WEBHOOK_SECRET
-PHOTON_SIDECAR_TOKEN RAFT_CHANNEL_TOKEN MSGRAPH_WEBHOOK_CLIENT_STATE MSGRAPH_CLIENT_SECRET
+PHOTON_SIDECAR_TOKEN A2A_PUSH_SECRET TEAMS_GRAPH_ACCESS_TOKEN QQ_STT_API_KEY
+MSGRAPH_WEBHOOK_CLIENT_STATE MSGRAPH_CLIENT_SECRET
""".split()
+# The user's own credentials that merely start with a platform name. Hermes never reads them, so
+# they reach the terminal like any other variable, and passthrough can forward them.
+OPERATOR_SECRETS = ["MY_APP_KEY", "DEPLOY_WEBHOOK_SECRET", "SLACK_USER_TOKEN", "LOCAL_LLM_API_KEY",
+ "GATEWAY_API_KEY"]
@pytest.mark.parametrize("builder", ["foreground", "background", "nonterminal"])
@@ -107,24 +113,24 @@ def test_adapter_and_provider_profile_secrets_never_reach_children(child_env, mo
secrets = set(ADAPTER_SECRETS)
secrets.update(name for profile in bundled_provider_profiles() for name in (profile.env_vars or ()))
secrets.discard("CLAUDE_CODE_OAUTH_TOKEN") # operator's subscription, not Hermes inference
- operator = ["MY_APP_KEY", "DEPLOY_WEBHOOK_SECRET"] # secret-shaped, but no adapter owns them
- for name in [*secrets, *operator]:
+ for name in [*secrets, *OPERATOR_SECRETS]:
monkeypatch.setenv(name, "fake-" + name)
factories = {
"foreground": lambda: local._make_run_env({}),
"background": lambda: local._sanitize_subprocess_env(dict(os.environ)),
"nonterminal": local.hermes_subprocess_env,
}
- observed = observe_child(factories[builder](), sorted(secrets | set(operator)))
- assert observed == {**dict.fromkeys(secrets), **{k: "fake-" + k for k in operator}}
+ observed = observe_child(factories[builder](), sorted(secrets | set(OPERATOR_SECRETS)))
+ assert observed == {**dict.fromkeys(secrets), **{k: "fake-" + k for k in OPERATOR_SECRETS}}
# Skill passthrough is what forwards a name into docker/ssh/modal and execute_code children.
- register_env_passthrough(sorted(secrets))
+ register_env_passthrough(sorted(secrets | set(OPERATOR_SECRETS)))
assert not any(is_env_passthrough(name) for name in secrets)
+ assert all(is_env_passthrough(name) for name in OPERATOR_SECRETS)
def test_inheriting_child_gets_provider_keys_but_never_adapter_secrets(child_env, monkeypatch):
# inherit_credentials is the narrow grant for model-driving CLIs: provider keys only.
- granted = ["OPENAI_API_KEY", "NOUS_API_KEY", "MY_APP_KEY", "DEPLOY_WEBHOOK_SECRET"]
+ granted = ["OPENAI_API_KEY", "NOUS_API_KEY", *OPERATOR_SECRETS]
for name in [*ADAPTER_SECRETS, *granted]:
monkeypatch.setenv(name, "fake-" + name)
observed = observe_child(local.hermes_subprocess_env(inherit_credentials=True),
@@ -138,13 +144,13 @@ def test_runtime_adapter_secret_follows_the_bound_profiles_registry(child_env, m
home_a, home_b = child_env / "hermes", child_env / "profile-b"
home_a.mkdir(exist_ok=True)
home_b.mkdir()
- name = "ACME_CHAT_SIGNING_SECRET" # read by a user adapter; no OPTIONAL_ENV_VARS entry
+ name = "ACME_CHAT_SIGNING_SECRET" # declared by a user adapter; no OPTIONAL_ENV_VARS entry
monkeypatch.setenv(name, "fake-secret")
monkeypatch.setenv("MY_APP_KEY", "operator")
scope_a = platform_registry.current_scope_key()
# Registered after the policy module was imported, in profile A only.
platform_registry.register(PlatformEntry(name="acme-chat", label="Acme", adapter_factory=lambda c: None,
- check_fn=lambda: True), scope=scope_a)
+ check_fn=lambda: True, required_env=[name]), scope=scope_a)
def child_sees():
return observe_child(local.hermes_subprocess_env(), [name, "MY_APP_KEY"])
@@ -185,7 +191,7 @@ def test_passthrough_accepted_before_an_adapter_owns_the_name_stops_forwarding_i
scope = platform_registry.current_scope_key()
platform_registry.register(PlatformEntry(name="acme-chat", label="Acme", adapter_factory=lambda c: None,
- check_fn=lambda: True), scope=scope)
+ check_fn=lambda: True, required_env=[name]), scope=scope)
try:
assert [observe_child(b(), names) for b in builders] == [{name: None, "MY_APP_KEY": "operator"}] * 3
# A routed profile's value lives only in its scope; the stale declaration must not add it back.
diff --git a/tools/environments/local.py b/tools/environments/local.py
index e2edb04324e..d9e54df4078 100644
--- a/tools/environments/local.py
+++ b/tools/environments/local.py
@@ -22,8 +22,9 @@ from tools.environments.base_output import _pipe_stdin
from hermes_cli._subprocess_compat import windows_hide_flags
from tools.environments.local_env_policy import ( # noqa: F401 — _HERMES_PROVIDER_ENV_BLOCKLIST stays importable from here
_ALWAYS_STRIP_KEYS, _HERMES_PROVIDER_ENV_BLOCKLIST, _HERMES_PROVIDER_ENV_FORCE_PREFIX,
- _is_hermes_internal_secret, _is_platform_secret_env, _is_provider_env_blocklisted,
- _is_terminal_first_party_env, _matches_terminal_first_party_prefix, _plugin_terminal_env_strip_keys, strip_profile_gate_env)
+ _is_hermes_internal_secret, _is_provider_env_blocklisted, _is_terminal_first_party_env,
+ _matches_terminal_first_party_prefix, _plugin_terminal_env_strip_keys, _registered_adapter_secret_env,
+ strip_profile_gate_env)
from tools.environments.local_pythonpath import (
_build_hermes_repo_root_aliases, _strip_hermes_owned_pythonpath_and_runtime_markers)
@@ -250,6 +251,7 @@ def _filter_secret_env(
except Exception:
is_env_passthrough, resolve_passthrough_value = (lambda _: False), (lambda _n, fb: fb)
plugin_strip_folded = frozenset(k.upper() for k in plugin_strip)
+ registered = _registered_adapter_secret_env()
for key, value in items.items():
if key.startswith(_HERMES_PROVIDER_ENV_FORCE_PREFIX):
if not unwrap_force:
@@ -262,7 +264,7 @@ def _filter_secret_env(
continue
first_party = _is_terminal_first_party_env(key)
passthrough = is_env_passthrough(key)
- if _is_provider_env_blocklisted(key) and not (passthrough or first_party):
+ if _is_provider_env_blocklisted(key, registered) and not (passthrough or first_party):
continue
if passthrough and not first_party:
value = resolve_passthrough_value(key, value)
@@ -333,10 +335,10 @@ def _scrub_credentials(env: dict, *, inherit_credentials: bool) -> dict:
# Credential names fold to uppercase for membership: on Windows the env block
# itself is case-insensitive, so a lowercase-stored ``gh_token`` IS GH_TOKEN.
strip_folded = frozenset(k.upper() for k in (_ALWAYS_STRIP_KEYS | _plugin_terminal_env_strip_keys()))
+ registered = _registered_adapter_secret_env()
for key in list(env):
- # Adapter secrets are Tier 1 like the bot tokens above: no provider-key child needs them.
- if (key.upper() in strip_folded or _is_platform_secret_env(key.upper())
- or (not inherit_credentials and _is_provider_env_blocklisted(key))
+ if (key.upper() in strip_folded
+ or (not inherit_credentials and _is_provider_env_blocklisted(key, registered))
or key.startswith(_HERMES_PROVIDER_ENV_FORCE_PREFIX)
or _is_hermes_internal_secret(key)):
del env[key]
diff --git a/tools/environments/local_env_policy.py b/tools/environments/local_env_policy.py
index 5fd4e41131b..ae7f753a9a5 100644
--- a/tools/environments/local_env_policy.py
+++ b/tools/environments/local_env_policy.py
@@ -40,9 +40,6 @@ _STATIC_PROVIDER_ENV_BLOCKLIST = frozenset({
"DAYTONA_API_KEY", "GATEWAY_RELAY_ID", "GATEWAY_RELAY_SECRET",
"GATEWAY_RELAY_DELIVERY_KEY", "VERCEL_OIDC_TOKEN", "VERCEL_TOKEN",
"VERCEL_PROJECT_ID", "VERCEL_TEAM_ID",
- # Microsoft Graph app secret and webhook clientState: read in code only, and no
- # adapter prefix owns them for the shape rule (``_is_platform_secret_env``).
- "MSGRAPH_CLIENT_SECRET", "MSGRAPH_WEBHOOK_CLIENT_STATE",
})
@@ -94,31 +91,64 @@ def _build_provider_env_blocklist() -> frozenset:
return frozenset(blocked)
-_HERMES_PROVIDER_ENV_BLOCKLIST = _build_provider_env_blocklist()
+_SECRET_ENV_SUFFIXES = ("_TOKEN", "_SECRET", "_PASSWORD", "_KEY")
-def _is_provider_env_blocklisted(name: str) -> bool:
- """``name`` is a blocklisted provider/tool credential, matched the way the
- platform's environment resolves names: exact plus case-folded. On Windows
- the environment block is case-insensitive, so ``openai_api_key`` IS
- ``OPENAI_API_KEY``; consistent with ``_is_hermes_internal_secret``, which
- already folds (``key.upper()``)."""
- upper = name.upper()
- return (name in _HERMES_PROVIDER_ENV_BLOCKLIST or upper in _HERMES_PROVIDER_ENV_BLOCKLIST
- or _is_platform_secret_env(upper))
+def _build_adapter_secret_env() -> frozenset:
+ """Secrets the messaging adapters declare: ``password`` messaging entries of OPTIONAL_ENV_VARS
+ (built-ins plus every platform plugin manifest's ``requires_env`` / ``optional_env``) and the
+ secret-named keys the gateway env-override table reads (WEIXIN_TOKEN, FEISHU_ENCRYPT_KEY, ...).
+ Declared names only: a user's own ``SLACK_USER_TOKEN`` or ``LOCAL_LLM_API_KEY`` is not Hermes's."""
+ # Read in code only, declared nowhere else: the Microsoft Graph app secret and webhook
+ # clientState, and the QQ bot's speech-to-text key.
+ names: set[str] = {"MSGRAPH_CLIENT_SECRET", "MSGRAPH_WEBHOOK_CLIENT_STATE", "QQ_STT_API_KEY"}
+ try:
+ from hermes_cli.config import OPTIONAL_ENV_VARS
+ names.update(name.upper() for name, meta in OPTIONAL_ENV_VARS.items()
+ if meta.get("category") == "messaging" and meta.get("password"))
+ except ImportError:
+ pass
+ try:
+ from gateway import config_env
+ from hermes_cli.profile_channels import _cred_row_envs
+ declared = {n for ns in config_env._ENV_ENABLE_CREDENTIALS.values() for n in ns}
+ for step in config_env._ENV_STEPS:
+ if isinstance(step, config_env._Cred):
+ declared |= _cred_row_envs(step)
+ names.update(n.upper() for n in declared if n.upper().endswith(_SECRET_ENV_SUFFIXES))
+ except ImportError:
+ pass
+ return frozenset(names)
-# Adapters read many secrets straight from the environment without listing them in
-# OPTIONAL_ENV_VARS (TELEGRAM_WEBHOOK_SECRET, WHATSAPP_CLOUD_APP_SECRET, WEIXIN_TOKEN, ...), so
-# the list above never sees them. Match them by shape, like the authorization gates below: an
-# adapter prefix plus a secret suffix, so a new adapter secret needs no second edit. The owners
-# are read per call because plugin adapters register late and per profile.
-_PLATFORM_SECRET_ENV_SUFFIXES = ("_TOKEN", "_SECRET", "_PASSWORD", "_KEY")
+_ADAPTER_SECRET_ENV = _build_adapter_secret_env()
+_HERMES_PROVIDER_ENV_BLOCKLIST = _build_provider_env_blocklist() | _ADAPTER_SECRET_ENV
-def _is_platform_secret_env(upper: str) -> bool:
- return upper.endswith(_PLATFORM_SECRET_ENV_SUFFIXES) and any(
- upper.startswith(prefix + "_") for prefix in _platform_gate_env_prefixes())
+def _registered_adapter_secret_env() -> frozenset:
+ """Secret-named ``required_env`` of the adapters registered in the current profile scope. Read
+ per call: plugin adapters register late and per profile, and a profile's own user plugins are
+ not in the import-time OPTIONAL_ENV_VARS. Tier 2 only: ``required_env`` is an unchecked setup
+ list, so a plugin naming OPENAI_API_KEY must not strip it from credentialed children."""
+ try:
+ from gateway.platform_registry import platform_registry
+ return frozenset(n.upper() for n in platform_registry.required_env_names()
+ if n.upper().endswith(_SECRET_ENV_SUFFIXES))
+ except Exception:
+ return frozenset()
+
+
+def _is_provider_env_blocklisted(name: str, _registered: "frozenset | None" = None) -> bool:
+ """``name`` is a blocklisted provider/tool credential or adapter secret, matched the way the
+ platform's environment resolves names: exact plus case-folded. On Windows the environment
+ block is case-insensitive, so ``openai_api_key`` IS ``OPENAI_API_KEY``; consistent with
+ ``_is_hermes_internal_secret``, which already folds (``key.upper()``). Loops pass
+ ``_registered`` so the registry is read once per env, not once per key."""
+ upper = name.upper()
+ if name in _HERMES_PROVIDER_ENV_BLOCKLIST or upper in _HERMES_PROVIDER_ENV_BLOCKLIST:
+ return True
+ return upper in (_registered_adapter_secret_env() if _registered is None else _registered)
+
# First-party platform credentials (``BUZZ_*``, driving the platform-mandated ``buzz``
# CLI) carved out of the TERMINAL scrub only (``_make_run_env``,
@@ -321,7 +351,6 @@ _ALWAYS_STRIP_KEYS: frozenset[str] = frozenset({
# enumerated here to stay stripped on the inherit_credentials=True path.
"GATEWAY_RELAY_ID", "GATEWAY_RELAY_SECRET", "GATEWAY_RELAY_DELIVERY_KEY",
"HASS_TOKEN", "EMAIL_PASSWORD", "HERMES_DASHBOARD_SESSION_TOKEN",
- "MSGRAPH_CLIENT_SECRET", "MSGRAPH_WEBHOOK_CLIENT_STATE",
# Remote-compute / infrastructure secrets
"MODAL_TOKEN_ID", "MODAL_TOKEN_SECRET", "DAYTONA_API_KEY",
-})
+}) | _ADAPTER_SECRET_ENV # every declared adapter secret is Tier 1, like the bot tokens above