The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(gateway): resolve the update/restart argv from the running install, not PATH
liuhao1024fea812824d3e
diff --git a/gateway/run.py b/gateway/run.pyindex bf1d09f82ca..339079fb836 100644--- a/gateway/run.py+++ b/gateway/run.py@@ -2878,17 +2878,20 @@ def _get_channel_override(def _resolve_hermes_bin() -> Optional[list[str]]:- """Hermes update command argv: ``hermes`` on PATH, else ``python -m hermes_cli.main``, else None."""- import shutil- hermes_bin = shutil.which("hermes")- if hermes_bin:- return [hermes_bin]+ """Hermes update/restart argv: the running interpreter's ``python -m hermes_cli.main``+ (exactly this install), else ``hermes`` on PATH, else None. The module argv must win: a+ PATH-first lookup lets an attacker-planted ``hermes`` shadow the running install when+ /update or /restart re-execs it (#111569)."""try:import importlib.utilif importlib.util.find_spec("hermes_cli") is not None:return [sys.executable, "-m", "hermes_cli.main"]except Exception:pass+ import shutil+ hermes_bin = shutil.which("hermes")+ if hermes_bin:+ return [hermes_bin]return Nonediff --git a/tests/gateway/test_update_command.py b/tests/gateway/test_update_command.pyindex 61fac28546a..4d1faa57eb3 100644--- a/tests/gateway/test_update_command.py+++ b/tests/gateway/test_update_command.py@@ -91,18 +91,34 @@ class TestHandleUpdateCommand:@pytest.mark.asyncio- async def test_resolve_hermes_bin_fallback(self):- """_resolve_hermes_bin falls back to sys.executable argv when which fails."""+ async def test_resolve_hermes_bin_module_argv(self):+ """_resolve_hermes_bin uses the running interpreter's module argv when hermes_cli is+ importable, even when PATH also offers a ``hermes`` binary (#111569: a PATH-first+ lookup would re-exec an attacker-planted executable on /update and /restart)."""import sysfrom gateway.run import _resolve_hermes_binfake_spec = MagicMock()- with patch("shutil.which", return_value=None), \+ with patch("shutil.which", return_value="/tmp/attacker/hermes"), \patch("importlib.util.find_spec", return_value=fake_spec):result = _resolve_hermes_bin()assert result == [sys.executable, "-m", "hermes_cli.main"]+ @pytest.mark.asyncio+ async def test_resolve_hermes_bin_falls_back_to_path_then_none(self):+ """Without an importable hermes_cli the argv degrades to PATH, then to None — never a+ bare ``hermes`` string that a hostile PATH entry could shadow."""+ from gateway.run import _resolve_hermes_bin++ with patch("shutil.which", return_value="/usr/local/bin/hermes"), \+ patch("importlib.util.find_spec", return_value=None):+ assert _resolve_hermes_bin() == ["/usr/local/bin/hermes"]++ with patch("shutil.which", return_value=None), \+ patch("importlib.util.find_spec", side_effect=ImportError):+ assert _resolve_hermes_bin() is None+@pytest.mark.asyncioasync def test_writes_pending_marker(self, tmp_path):