The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(terminal): gate the BUZZ_* terminal carve-out on actual Buzz agent context
Teknium26f178e5fa78
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..0b04aeefb32--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+vatevstoildiff --git a/tests/tools/test_env_passthrough.py b/tests/tools/test_env_passthrough.pyindex d1f24de08ed..39734d835f6 100644--- a/tests/tools/test_env_passthrough.py+++ b/tests/tools/test_env_passthrough.py@@ -344,14 +344,16 @@ class TestTerminalIntegration:assert var not in resultassert "PATH" in result- def test_passthrough_cannot_register_buzz_vars(self):+ def test_passthrough_cannot_register_buzz_vars(self, monkeypatch):"""GHSA-rhgp-j443-p4rf seal stays intact for the BUZZ_* first-partyplatform credentials: even though they pass through to terminal- children by default (issue #78026), env_passthrough registration must- still refuse them — the carve-out opens NO registration path, so a- skill cannot expand BUZZ_* exposure to execute_code."""+ children in a Buzz agent context (issue #78026), env_passthrough+ registration must still refuse them — the carve-out opens NO+ registration path, so a skill cannot expand BUZZ_* exposure to+ execute_code."""from tools.environments.local import _sanitize_subprocess_env+ monkeypatch.setenv("BUZZ_MANAGED_AGENT", "1")for var in ("BUZZ_PRIVATE_KEY","BUZZ_AUTH_TAG",diff --git a/tests/tools/test_local_env_blocklist.py b/tests/tools/test_local_env_blocklist.pyindex 7189bde4d3c..5cae08330b5 100644--- a/tests/tools/test_local_env_blocklist.py+++ b/tests/tools/test_local_env_blocklist.py@@ -288,21 +288,27 @@ class TestProviderEnvBlocklist:class TestTerminalFirstPartyPlatformEnv:- """BUZZ_* first-party platform credentials must reach terminal children.+ """BUZZ_* first-party platform credentials must reach terminal children —+ but ONLY in a Buzz agent context.Issue #78026: Buzz platform agents could not use the ``buzz`` CLI from theterminal tool because BUZZ_PRIVATE_KEY / BUZZ_AUTH_TAG / BUZZ_RELAY_URL(and the other BUZZ_* vars) are stripped by _HERMES_PROVIDER_ENV_BLOCKLISTand env_passthrough refuses to re-allow them (GHSA-rhgp-j443-p4rf).- The carve-out is TERMINAL-ONLY: foreground (_make_run_env) and- background/PTY (_sanitize_subprocess_env) children get the BUZZ_* vars;- execute_code, hermes_subprocess_env, docker, and env_passthrough- registration stay sealed. The blocklist itself is NOT modified.+ The carve-out is TERMINAL-ONLY and CONTEXT-GATED: it applies when the+ process is a Buzz-ACP managed agent (BUZZ_MANAGED_AGENT set by the+ buzz-acp harness, #76243) or the live session's platform is ``buzz``.+ Foreground (_make_run_env) and background/PTY (_sanitize_subprocess_env)+ children then get the BUZZ_* vars; execute_code, hermes_subprocess_env,+ docker, and env_passthrough registration stay sealed, and non-Buzz+ sessions/processes keep stripping the vars. The blocklist itself is NOT+ modified."""def test_make_run_env_preserves_buzz_vars(self):- """Foreground terminal children get the BUZZ_* credentials."""+ """Foreground terminal children get the BUZZ_* credentials when the+ process is a Buzz-managed agent (BUZZ_MANAGED_AGENT set)."""from tools.environments.local import _make_run_envbuzz_vars = {@@ -310,7 +316,11 @@ class TestTerminalFirstPartyPlatformEnv:"BUZZ_AUTH_TAG": '["tag","data","kind","sig"]',"BUZZ_RELAY_URL": "https://mycommunity.communities.buzz.xyz",}- with patch.dict(os.environ, {**buzz_vars, "PATH": "/usr/bin:/bin"}, clear=True):+ with patch.dict(+ os.environ,+ {**buzz_vars, "BUZZ_MANAGED_AGENT": "1", "PATH": "/usr/bin:/bin"},+ clear=True,+ ):run_env = _make_run_env({})for var, value in buzz_vars.items():@@ -318,10 +328,12 @@ class TestTerminalFirstPartyPlatformEnv:f"{var} missing from foreground terminal env (issue #78026)")- def test_sanitize_subprocess_env_preserves_buzz_vars(self):- """Background/PTY terminal children get the BUZZ_* credentials."""+ def test_sanitize_subprocess_env_preserves_buzz_vars(self, monkeypatch):+ """Background/PTY terminal children get the BUZZ_* credentials when+ the process is a Buzz-managed agent."""from tools.environments.local import _sanitize_subprocess_env+ monkeypatch.setenv("BUZZ_MANAGED_AGENT", "1")buzz_vars = {"BUZZ_PRIVATE_KEY": "nsec1faketestkey","BUZZ_AUTH_TAG": '["tag","data","kind","sig"]',@@ -334,6 +346,56 @@ class TestTerminalFirstPartyPlatformEnv:f"{var} missing from background/PTY terminal env (issue #78026)")+ def test_buzz_vars_stripped_without_buzz_context(self, monkeypatch):+ """NEGATIVE gate: with no Buzz context signal (no BUZZ_MANAGED_AGENT,+ session platform not buzz), the BUZZ_* credentials stay stripped from+ BOTH terminal scrub paths — a Telegram/CLI/cron session on a host that+ also runs a Buzz gateway must not see BUZZ_PRIVATE_KEY."""+ from gateway.session_context import _SESSION_PLATFORM+ from tools.environments.local import _make_run_env, _sanitize_subprocess_env++ monkeypatch.delenv("BUZZ_MANAGED_AGENT", raising=False)+ monkeypatch.delenv("HERMES_SESSION_PLATFORM", raising=False)+ buzz_vars = {+ "BUZZ_PRIVATE_KEY": "nsec1faketestkey",+ "BUZZ_AUTH_TAG": '["tag","data","kind","sig"]',+ "BUZZ_RELAY_URL": "https://mycommunity.communities.buzz.xyz",+ }+ for var, value in buzz_vars.items():+ monkeypatch.setenv(var, value)+ # Bind a non-buzz session platform (ContextVar-authoritative).+ token = _SESSION_PLATFORM.set("telegram")+ try:+ run_env = _make_run_env({})+ sanitized = _sanitize_subprocess_env({**buzz_vars, "HOME": "/home/user"})+ finally:+ _SESSION_PLATFORM.reset(token)++ for var in buzz_vars:+ assert var not in run_env, f"{var} leaked into non-Buzz foreground env"+ assert var not in sanitized, f"{var} leaked into non-Buzz background env"++ def test_session_platform_buzz_enables_carveout(self, monkeypatch):+ """A live gateway session whose platform is ``buzz`` gets the+ carve-out even without BUZZ_MANAGED_AGENT (native buzz gateway+ plugin path), via the concurrency-safe session ContextVar."""+ from gateway.session_context import _SESSION_PLATFORM+ from tools.environments.local import _make_run_env, _sanitize_subprocess_env++ monkeypatch.delenv("BUZZ_MANAGED_AGENT", raising=False)+ monkeypatch.setenv("BUZZ_PRIVATE_KEY", "nsec1faketestkey")+ token = _SESSION_PLATFORM.set("buzz")+ try:+ run_env = _make_run_env({})+ sanitized = _sanitize_subprocess_env(+ {"BUZZ_PRIVATE_KEY": "nsec1faketestkey", "HOME": "/home/user"}+ )+ finally:+ _SESSION_PLATFORM.reset(token)++ assert run_env.get("BUZZ_PRIVATE_KEY") == "nsec1faketestkey"+ assert sanitized.get("BUZZ_PRIVATE_KEY") == "nsec1faketestkey"+def test_buzz_vars_stay_in_blocklist(self):"""The carve-out is a scrub-path exemption, NOT a blocklist removal —BUZZ_* must remain blocked for every non-terminal surface (execute_code,@@ -350,6 +412,7 @@ class TestTerminalFirstPartyPlatformEnv:from agent import secret_scope as ssfrom tools.environments.local import _make_run_env, _sanitize_subprocess_env+ monkeypatch.setenv("BUZZ_MANAGED_AGENT", "1")monkeypatch.setenv("BUZZ_PRIVATE_KEY", "nsec-plain-value")monkeypatch.setenv("PATH", "/usr/bin:/bin")ss.set_multiplex_active(True)@@ -371,6 +434,7 @@ class TestTerminalFirstPartyPlatformEnv:from agent import secret_scope as ssfrom tools.environments.local import _make_run_env, _sanitize_subprocess_env+ monkeypatch.setenv("BUZZ_MANAGED_AGENT", "1")monkeypatch.setenv("BUZZ_PRIVATE_KEY", "nsec-process-env")monkeypatch.setenv("PATH", "/usr/bin:/bin")ss.set_multiplex_active(True)diff --git a/tools/environments/local.py b/tools/environments/local.pyindex 241d6e9040a..94488bc308e 100644--- a/tools/environments/local.py+++ b/tools/environments/local.py@@ -432,21 +432,15 @@ def _build_provider_env_blocklist() -> frozenset:# It arrives via the registry loop above (anthropic api_key_env_vars),# so remove it explicitly.blocked.discard("CLAUDE_CODE_OAUTH_TOKEN")- # Buzz-ACP managed agents (this process spawned by Buzz Desktop's buzz-acp- # harness) receive BUZZ_PRIVATE_KEY / BUZZ_RELAY_URL / BUZZ_AUTH_TAG in the- # process env ON PURPOSE: the platform's reply-delivery contract is the- # model driving the `buzz` CLI from the terminal (block/buzz#2698 — final- # session text is NOT delivered to the channel). The bundled buzz platform- # plugin registers these names as "messaging" credentials, which would- # strip them here and silently break every reply. Mirror the- # CLAUDE_CODE_OAUTH_TOKEN exception above: when this process is a- # Buzz-managed agent (BUZZ_MANAGED_AGENT is set by the harness), the vars- # are the harness's deliberate hand-off to the agent, not a Hermes-managed- # secret. Gateway/CLI/kanban processes never carry BUZZ_MANAGED_AGENT, so- # the platform-plugin secret (path ③, ~/.hermes/.env) stays stripped there.- if os.environ.get("BUZZ_MANAGED_AGENT"):- for _buzz_var in ("BUZZ_PRIVATE_KEY", "BUZZ_RELAY_URL", "BUZZ_AUTH_TAG"):- blocked.discard(_buzz_var)+ # BUZZ_* is deliberately NOT discarded here, even for Buzz-managed agents+ # (BUZZ_MANAGED_AGENT set by the buzz-acp harness). This blocklist is+ # shared by every scrub surface — the terminal paths, execute_code, and+ # the :func:`hermes_subprocess_env` Tier-2 strip (browser / TUI host /+ # copilot-executor spawns) — so an import-time discard would leak+ # BUZZ_PRIVATE_KEY into non-terminal children too. The Buzz carve-out is+ # instead a TERMINAL-ONLY, context-gated scrub-path exemption: see+ # ``_TERMINAL_FIRST_PARTY_ENV_PREFIXES`` / ``_is_terminal_first_party_env``+ # below (issue #78026 / #76243, PRs #78065 + #78511).return frozenset(blocked)@@ -459,6 +453,17 @@ _HERMES_PROVIDER_ENV_BLOCKLIST = _build_provider_env_blocklist()# agent's OWN credentials — a Buzz community agent is expected to operate the# ``buzz`` CLI — so they are carved out of the terminal scrub.#+# CONTEXT-GATED: the carve-out applies ONLY when this process/session is+# actually operating as a Buzz agent — either the process is a Buzz-ACP+# managed agent (``BUZZ_MANAGED_AGENT`` is set, only by Buzz Desktop's+# buzz-acp harness; see #76243 / #78511) or the current session's platform is+# ``buzz`` (the gateway's ``HERMES_SESSION_PLATFORM`` ContextVar; concurrency+# safe under a multi-session host). A Telegram/CLI/cron session on a host+# that also runs a Buzz gateway does NOT get BUZZ_PRIVATE_KEY in its terminal+# children — blanket passthrough of a signing key to every terminal child on+# the host would be wrong (maintainer triage note on #76243: don't expose the+# key to unrelated shell commands).+## Scope is TERMINAL ONLY: the foreground ``_make_run_env`` and background/PTY# ``_sanitize_subprocess_env`` paths pass them through. ``_sanitize_subprocess_env``# is also consumed by search workers (e.g. the ddgs web-search subprocess),@@ -488,15 +493,52 @@ _HERMES_PROVIDER_ENV_BLOCKLIST = _build_provider_env_blocklist()# Hermes-managed first-party platform credentials, so they stay IN the# blocklist for every non-terminal surface.#-# See issue #78026 (Buzz agents could not use ``buzz`` from the terminal tool).+# See issue #78026 (Buzz agents could not use ``buzz`` from the terminal tool)+# and #76243 (Buzz Desktop managed agent wakes but cannot reply)._TERMINAL_FIRST_PARTY_ENV_PREFIXES = ("BUZZ_",)+def _matches_terminal_first_party_prefix(name: str) -> bool:+ """Pure name check: ``name`` is one of the first-party platform+ credential names (``BUZZ_*``), regardless of session context. Used for+ the snapshot exclusion, which must stay conservative even when the+ carve-out itself is inactive."""+ return name.startswith(_TERMINAL_FIRST_PARTY_ENV_PREFIXES)+++def _buzz_terminal_context_active() -> bool:+ """True when this process/session is operating as a Buzz agent.++ Two independent signals, either suffices:++ * ``BUZZ_MANAGED_AGENT`` in the process env — set exclusively by Buzz+ Desktop's buzz-acp harness when it spawns ``hermes acp`` (#76243).+ Gateway / CLI / cron / kanban processes never carry it.+ * The live session's platform is ``buzz`` — the gateway's+ ``HERMES_SESSION_PLATFORM`` ContextVar via+ :func:`gateway.session_context.get_session_env`, which is+ ContextVar-authoritative under a concurrent multi-session host, so a+ sibling Telegram/Discord session on the same gateway process resolves+ its OWN platform, not buzz.+ """+ if os.environ.get("BUZZ_MANAGED_AGENT"):+ return True+ try:+ from gateway.session_context import get_session_env++ return get_session_env("HERMES_SESSION_PLATFORM", "").strip().lower() == "buzz"+ except Exception:+ return False++def _is_terminal_first_party_env(name: str) -> bool:"""Return True if ``name`` is a first-party platform credential that must- reach terminal children (the ``BUZZ_*`` set; see- ``_TERMINAL_FIRST_PARTY_ENV_PREFIXES``)."""- return name.startswith(_TERMINAL_FIRST_PARTY_ENV_PREFIXES)+ reach terminal children (the ``BUZZ_*`` set) AND the current+ process/session context entitles it (Buzz-managed agent or a buzz-platform+ session — see :func:`_buzz_terminal_context_active`)."""+ if not _matches_terminal_first_party_prefix(name):+ return False+ return _buzz_terminal_context_active()# Active-virtualenv markers that must NOT leak into terminal subprocesses.@@ -1953,7 +1995,11 @@ class LocalEnvironment(BaseEnvironment):sorted(namefor name in merged- if isinstance(name, str) and _is_terminal_first_party_env(name)+ # Prefix-only on purpose: the snapshot exclusion stays+ # conservative even when the context-gated carve-out is+ # inactive (the var then never reaches the child env anyway,+ # but a monotonic exclusion is a cheap extra guard).+ if isinstance(name, str) and _matches_terminal_first_party_prefix(name)))diff --git a/website/docs/user-guide/messaging/buzz.md b/website/docs/user-guide/messaging/buzz.mdindex 0e84514d9c2..1ee240ed80c 100644--- a/website/docs/user-guide/messaging/buzz.md+++ b/website/docs/user-guide/messaging/buzz.md@@ -134,7 +134,7 @@ Check status with `hermes gateway status` — Buzz connection state is reported## Notes and limitations-- **`BUZZ_*` env vars are available in terminal tool children** — the agent can invoke the `buzz` CLI directly (e.g. `buzz messages send ...`) because `BUZZ_PRIVATE_KEY`, `BUZZ_AUTH_TAG`, `BUZZ_RELAY_URL`, and the other `BUZZ_*` variables are passed through to terminal subprocesses. (`execute_code` and other non-terminal spawns remain sealed.)+- **`BUZZ_*` env vars are available in terminal tool children for Buzz sessions** — the agent can invoke the `buzz` CLI directly (e.g. `buzz messages send ...`) because `BUZZ_PRIVATE_KEY`, `BUZZ_AUTH_TAG`, `BUZZ_RELAY_URL`, and the other `BUZZ_*` variables are passed through to terminal subprocesses when the session's platform is `buzz` or the process is a Buzz Desktop managed agent (`BUZZ_MANAGED_AGENT`). Non-Buzz sessions on the same host, `execute_code`, and other non-terminal spawns remain sealed.- **Inbound is polled, not streamed.** The `buzz` CLI is request/response, so the adapter polls `buzz messages get` per watched channel every `poll_interval` seconds (default 4). Expect up to one interval of latency on inbound messages. A future optimization is a websocket transport (the Buzz repo ships `buzz-ws-client` for true streaming).- On (re)connect the adapter seeds its high-water mark from the newest events, so channel history is never replayed into the agent.- New DM conversations are discovered automatically (every few poll sweeps).diff --git a/website/docs/user-guide/security.md b/website/docs/user-guide/security.mdindex 73d87015601..97b1d7cf435 100644--- a/website/docs/user-guide/security.md+++ b/website/docs/user-guide/security.md@@ -520,7 +520,7 @@ If you add names to `terminal.docker_forward_env`, those variables are intentionBoth `execute_code` and `terminal` strip sensitive environment variables from child processes to prevent credential exfiltration by LLM-generated code. However, skills that declare `required_environment_variables` legitimately need access to those vars.-First-party platform credentials — the `BUZZ_*` variables used by the Buzz messaging platform — are passed through to `terminal` children (foreground and background/PTY spawns) by default so a Buzz platform agent can invoke its platform-mandated CLI (e.g. `buzz`) from the terminal tool. Because `_sanitize_subprocess_env` also feeds search workers (e.g. the ddgs web-search subprocess), the computer-use driver binary, and user-script runners (bang `!` commands, quick commands, cron scripts, webhook-filter scripts), those children receive the variables too. This carve-out is **terminal-only**: it does not apply to `execute_code`, browser/TUI-host spawns (`hermes_subprocess_env`), Docker/Modal children, or `env_passthrough` registration, which remain sealed.+First-party platform credentials — the `BUZZ_*` variables used by the Buzz messaging platform — are passed through to `terminal` children (foreground and background/PTY spawns) **only when the session is actually operating as a Buzz agent**: the process is a Buzz-ACP managed agent (`BUZZ_MANAGED_AGENT` set by the Buzz Desktop harness) or the live gateway session's platform is `buzz`. This lets a Buzz platform agent invoke its platform-mandated CLI (e.g. `buzz`) from the terminal tool, while Telegram/CLI/cron sessions on the same host keep the variables stripped. Because `_sanitize_subprocess_env` also feeds search workers (e.g. the ddgs web-search subprocess), the computer-use driver binary, and user-script runners (bang `!` commands, quick commands, cron scripts, webhook-filter scripts), those children receive the variables too when spawned from a Buzz session. The carve-out is **terminal-only**: it does not apply to `execute_code`, browser/TUI-host spawns (`hermes_subprocess_env`), Docker/Modal children, or `env_passthrough` registration, which remain sealed.### How It Works