The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: gate dynamic shell words in approval checks
Teknium06a3a98751e1
diff --git a/tests/tools/test_approval.py b/tests/tools/test_approval.pyindex 29bc6e3fec1..7189ffedb01 100644--- a/tests/tools/test_approval.py+++ b/tests/tools/test_approval.py@@ -158,6 +158,36 @@ class TestDetectDangerousRm:assert "delete" in desc.lower(), command+class TestDynamicShellWordSpellings:+ """Unquoted brace/glob words that the shell can expand into `find -delete`/`-exec` or into a+ program-bearing read-tool option require approval. Additive detection of these spellings only:+ approval is decided from source text, so `$var`-built words are out of scope here."""++ @pytest.mark.parametrize("command", [+ "find ./missing-approval-target -{delete,print}",+ "find ./missing-approval-target -del*",+ "find ./missing-approval-target -delet?",+ "find ./missing-approval-target -delet[e]",+ "rg --pre{=,=sh} pattern missing-approval-payload.sh",+ "rg --hostname-bin{=,=sh} pattern file",+ "sort --compress-program{=,=sh} file",+ "ag --pager{=,=sh} pattern",+ ])+ def test_dynamic_spellings_require_approval(self, command):+ dangerous, key, desc = detect_dangerous_command(command)+ assert dangerous is True and key is not None, command+ assert "dynamic shell word" in desc, command++ @pytest.mark.parametrize("command", [+ "echo '-{delete,print}' '-del*'",+ 'echo -g"*.py" \'-{delete,print}\' "--pre{=,=sh}"',+ "find . -name '*.pyc' -print",+ "rg --pretty pattern file",+ ])+ def test_inert_spellings_remain_safe(self, command):+ assert detect_dangerous_command(command) == (False, None, None), command++class TestWindowsShellDestructiveCommands:def test_windows_destructive_requires_approval(self):cases = [diff --git a/tools/approval_detection.py b/tools/approval_detection.pyindex 0d7732f24ac..ec7f96b8217 100644--- a/tools/approval_detection.py+++ b/tools/approval_detection.py@@ -318,7 +318,16 @@ DANGEROUS_PATTERNS = [(r'\bxargs\s+.*\brm\b', "xargs with rm"),# -execdir has the same semantics as -exec (runs in each match's directory).(r'\bfind\b.*-exec(?:dir)?\s+(/\S*/)?rm\b', "find -exec/-execdir rm"),+ # Unquoted brace/glob spellings the shell can expand into the flags above at run time+ # (`find . -{delete,print}`, `find . -del*`). Additive: catches these spellings only; approval is+ # still decided from source text, so `$var`/`$(...)`-built words are not covered here.+ (r'\bfind\b[^;|&\n]*-(?:\{[^}\s]*(?:delete|exec(?:dir)?)[^}\s]*\}|(?:del(?:ete?)?|exec(?:dir)?)[*?\[])',+ "find dynamic shell word may expand to destructive flag"),(r'\bfind\b.*-delete\b', "find -delete"),+ # Same for program-bearing read-tool options, which _execution_flag_findings() parses structurally+ # only when the option is spelled literally.+ (r'\b(?:rg|sort|ag|man)\b[^;|&\n]*--(?:pre|hostname-bin|compress-program|pager|html)(?:\{|[*?\[])',+ "dynamic shell word may expand to arbitrary program execution flag"),# Gateway lifecycle: stopping/restarting the gateway kills all running agents. Global flags# between `hermes` and `gateway` (`hermes -p ade gateway restart`) are allowed so a profile flag can't slip past.(r'\bhermes\s+(?:-{1,2}\S+(?:\s+\S+)?\s+)*gateway\s+(stop|restart)\b', "stop/restart hermes gateway (kills running agents)"),