The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: managed worker env is scrubbed by owning profile; outbox ids stay inside worker-outboxes
Teknium2e9e172926c4
diff --git a/agent/managed_worker.py b/agent/managed_worker.pyindex bc1d690c798..dc4b5eb886c 100644--- a/agent/managed_worker.py+++ b/agent/managed_worker.py@@ -14,6 +14,7 @@ except ModuleNotFoundError as exc:import jsonimport os+import refrom pathlib import Pathimport sysimport threading@@ -161,10 +162,18 @@ class WorkerControls:self.channel.send('prompt_settled', prompt_id=prompt_id)+_OUTBOX_NAME = re.compile(r'[A-Za-z0-9_-]{1,200}')++def outbox_dir(home, execution_id):"""execution_id is a ledger key ('admission-worker:<hex>'); ':' is not a legal Windows pathcharacter, so the private outbox directory is a portable spelling of the same identity."""- return Path(home) / 'worker-outboxes' / execution_id.replace(':', '-')+ # A legacy-imported admission id is arbitrary text; never let it name a path outside+ # worker-outboxes (``../`` on POSIX, ``..\\`` or drive spellings on Windows).+ name = execution_id.replace(':', '-') if isinstance(execution_id, str) else ''+ if not _OUTBOX_NAME.fullmatch(name):+ raise ValueError('invalid_execution_id')+ return Path(home) / 'worker-outboxes' / namedef discover_profile_mcp(policy):diff --git a/gateway/session_managed_worker.py b/gateway/session_managed_worker.pyindex 529d0fc9b52..2dc8367ce1f 100644--- a/gateway/session_managed_worker.py+++ b/gateway/session_managed_worker.py@@ -210,14 +210,24 @@ def _worker_env(authority):process env byte-for-byte, exactly as before."""from pathlib import Pathfrom agent.secret_scope import is_multiplex_active+ from tools.environments.local import _is_routed_homehome = Path(str(authority.profile_id))- if not is_multiplex_active() or not home.is_absolute():+ if not home.is_absolute():+ return None+ # Keyed on the worker's OWNING profile, not only the process-wide multiplex flag: a worker for+ # another profile must never inherit the launch environ even when that flag reads False.+ routed = _is_routed_home(home)+ if not routed and not is_multiplex_active():return Nonefrom agent.secret_scope import build_profile_secret_scope- from tools.environments.local import build_subprocess_env, strip_launch_profile_env+ from tools.environments.local import _scrub_credentials, build_subprocess_env, strip_launch_profile_env# The scrub removes credentials, not settings: the launch profile's TERMINAL_* policy and# its ``.env`` settings would otherwise reach the secondary's worker (cron/kanban rule).env = strip_launch_profile_env(build_subprocess_env(scrub_secrets=True), home)+ if routed:+ # Same rule as served_profile_child_env: env_passthrough / first-party carve-outs must not+ # forward launch-process provider credentials that no .env or source snapshot recorded.+ _scrub_credentials(env, inherit_credentials=False)env.update({k: v for k, v in build_profile_secret_scope(home).items() if v is not None})env['HERMES_HOME'] = str(home)from hermes_constants import apply_subprocess_home_envdiff --git a/tests/gateway/test_managed_worker_env_boundary.py b/tests/gateway/test_managed_worker_env_boundary.pynew file mode 100644index 00000000000..7c92a50d66f--- /dev/null+++ b/tests/gateway/test_managed_worker_env_boundary.py@@ -0,0 +1,42 @@+"""Managed worker boundary: a worker FOR another profile never inherits the launch profile's+credentials, and a ledger id never names a path outside worker-outboxes (PR #106742 security lane)."""+from types import SimpleNamespace++import pytest++[email protected]("multiplex", [True, False])+def test_secondary_profile_worker_gets_no_launch_credentials(tmp_path, monkeypatch, multiplex):+ launch = tmp_path / ".hermes"+ sec = launch / "profiles" / "l106742sec"+ sec.mkdir(parents=True)+ (launch / ".env").write_text("OPENROUTER_API_KEY=LAUNCH-or\nMY_SERVICE_TOKEN=LAUNCH-mysvc\n")+ (sec / ".env").write_text("OPENROUTER_API_KEY=SEC-or\n")+ monkeypatch.setenv("HOME", str(tmp_path))+ monkeypatch.setenv("HERMES_HOME", str(launch))+ for key, value in {"OPENROUTER_API_KEY": "LAUNCH-or", "MY_SERVICE_TOKEN": "LAUNCH-mysvc",+ "NOUS_API_KEY": "LAUNCH-nous", "VAULT_ONLY_TOKEN": "LAUNCH-vault"}.items():+ monkeypatch.setenv(key, value)+ import hermes_cli.env_loader as env_loader+ monkeypatch.setitem(env_loader._SECRET_SOURCES, "VAULT_ONLY_TOKEN", "bitwarden")+ from agent import secret_scope+ from gateway.session_managed_worker import _worker_env+ secret_scope.set_multiplex_active(multiplex)+ try:+ env = _worker_env(SimpleNamespace(profile_id=str(sec)))+ own = _worker_env(SimpleNamespace(profile_id=str(launch)))+ finally:+ secret_scope.set_multiplex_active(False)+ # The scrub follows the worker's OWNING profile, not the process-wide multiplex flag.+ assert env is not None and env["OPENROUTER_API_KEY"] == "SEC-or"+ assert sorted(k for k, v in env.items() if "LAUNCH" in str(v)) == []+ if not multiplex:+ assert own is None # single-profile: the launch profile's own worker inherits byte-for-byte++[email protected]("bad", ["../../../../escape", "x/../../y", "..\\..\\win", "C:\\evil", ""])+def test_outbox_dir_only_names_paths_inside_worker_outboxes(tmp_path, bad):+ from agent.managed_worker import outbox_dir+ assert outbox_dir(tmp_path, "admission-worker:" + "ab" * 16).parent == tmp_path / "worker-outboxes"+ with pytest.raises(ValueError):+ outbox_dir(tmp_path, "admission-worker:" + bad if bad else bad)