The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(security): gateway lifecycle guard recognises Windows command spellings
hotragnd966b34cc36f
diff --git a/cron/lifecycle_guard.py b/cron/lifecycle_guard.pyindex b5a68288c73..f85c46076ef 100644--- a/cron/lifecycle_guard.py+++ b/cron/lifecycle_guard.py@@ -34,7 +34,9 @@ _GATEWAY_LIFECYCLE_PATTERN = re.compile(# while every real command position (text start, whitespace, `;`/`&`/`|`, `$(`, backtick,# U+FFFD) still matches.# See #77173.- r"(?:(?<![/\w.\-])hermes\s+gateway\s+(?:restart|stop|uninstall)\b)"+ # Windows spells the CLI with a launcher suffix (`hermes.exe`, npm-style `hermes.cmd`/`.ps1`);+ # same command, so the suffix is optional here.+ r"(?:(?<![/\w.\-])hermes(?:\.(?:exe|cmd|bat|com|ps1))?\s+gateway\s+(?:restart|stop|uninstall)\b)"# Branch B: launchctl ops anchored on a hermes-gateway label so unrelated hermes services stay# unblocked. `submit`/`bootstrap` register a NEW keepalive job wrapping an arbitrary helper (a# laundered restart); neutral-label submissions are caught by@@ -56,8 +58,11 @@ _GATEWAY_LIFECYCLE_PATTERN = re.compile(r"|(?:systemctl\s+(?:-\S+\s+)*(?:restart|stop|start)\b[^\n]*\bhermes[.\-]?gateway)"# Branch D: pkill/kill of the gateway process, both token orders. Leading \b keeps "skill" from# matching as "kill".- r"|(?:\bp?kill\b[^\n]*\bhermes\b[^\n]*\bgateway)"- r"|(?:\bp?kill\b[^\n]*\bgateway\b[^\n]*\bhermes)"+ # `taskkill` / `Stop-Process` are the Windows spellings of the same operation; `\bp?kill\b`+ # cannot reach inside `taskkill`, so they are named outright. Service-control forms (`net stop`,+ # `sc stop`) presuppose a service install this guard has no evidence of and stay uncovered.+ r"|(?:\b(?:p?kill|taskkill|stop-process)\b[^\n]*\bhermes\b[^\n]*\bgateway)"+ r"|(?:\b(?:p?kill|taskkill|stop-process)\b[^\n]*\bgateway\b[^\n]*\bhermes)")# Branch E: Windows image-name termination of the interpreter that runs the gateway. A gatewaydiff --git a/tests/hermes_cli/test_gateway_restart_loop.py b/tests/hermes_cli/test_gateway_restart_loop.pyindex 7a727206c83..4a15c8e89de 100644--- a/tests/hermes_cli/test_gateway_restart_loop.py+++ b/tests/hermes_cli/test_gateway_restart_loop.py@@ -54,6 +54,54 @@ class TestGatewayLifecyclePattern:def test_hermes_gateway_commands(self, text):assert _contains_gateway_lifecycle_command(text), f"Should match: {text!r}"+ @pytest.mark.parametrize("text", [+ # Windows spells the CLI with an executable suffix, and npm-style+ # shims install `hermes.cmd` / `hermes.ps1` beside the `.exe`.+ # Anchoring Branch A on the bare name let every one of these walk past+ # a guard that stops `hermes gateway restart`. The guard is gated on+ # PID-file ownership, not on platform, so the bypass was live for any+ # supervised gateway running on Windows.+ "hermes.exe gateway restart",+ "hermes.cmd gateway stop",+ "hermes.bat gateway restart",+ "hermes.ps1 gateway uninstall",+ "HERMES.EXE gateway restart",+ r"C:\tools\hermes.exe gateway stop",+ r".\hermes.exe gateway restart",+ # Quoted and wrapped spellings reach the same place via the+ # tokenizing rescan; pin them so the suffix survives that path too.+ r'"C:\Program Files\hermes.exe" gateway restart',+ "cmd /c hermes.exe gateway restart",+ 'powershell -Command "hermes.exe gateway restart"',+ ])+ def test_windows_executable_suffix_is_caught(self, text):+ assert _contains_gateway_lifecycle_command(text), f"Should match: {text!r}"++ @pytest.mark.parametrize("text", [+ # `taskkill` / `Stop-Process` are the Windows spellings of pkill.+ # `\bp?kill\b` cannot reach inside `taskkill` — there is no word+ # boundary between the two `k`s — so they need naming outright.+ "taskkill /F /IM hermes-gateway.exe",+ "Stop-Process -Name hermes-gateway -Force",+ "stop-process -name hermes-gateway",+ ])+ def test_windows_process_kill_forms_are_caught(self, text):+ assert _contains_gateway_lifecycle_command(text), f"Should match: {text!r}"++ @pytest.mark.parametrize("text", [+ # The suffix must not widen the match. `start` stays deliberately+ # benign, an unrelated process is not the gateway, and the word-tail+ # exclusion still holds once a suffix is attached.+ "hermes.exe gateway start",+ "hermes.exe chat",+ "taskkill /F /IM notepad.exe",+ "Stop-Process -Name chrome",+ "my-hermes.exe gateway restart",+ "hermesexe gateway restart",+ ])+ def test_windows_forms_do_not_overmatch(self, text):+ assert not _contains_gateway_lifecycle_command(text), f"Should NOT match: {text!r}"+@pytest.mark.parametrize("text", [# #62891: a blocked direct restart/kill laundered through a NEW# launchd keepalive job wrapping a helper script, instead of a