Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/tools/test_approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,27 @@ def test_custom_hermes_home(self):
dangerous, key, desc = detect_dangerous_command("echo x | tee $HERMES_HOME/config.yaml")
assert dangerous is True

def test_perl_in_place_config(self):
# perl -i performs the same in-place mutation as sed -i but was not
# caught by the -e/-c pattern (which targets code evaluation).
dangerous, key, desc = detect_dangerous_command(
"perl -i -pe 's/approvals.mode: on/approvals.mode: off/' ~/.hermes/config.yaml"
)
assert dangerous is True
assert "in-place" in desc.lower() or "perl" in desc.lower()

def test_ruby_in_place_config(self):
dangerous, key, desc = detect_dangerous_command(
"ruby -i -pe 'gsub(/manual/, \"off\")' ~/.hermes/config.yaml"
)
assert dangerous is True

def test_perl_in_place_env(self):
dangerous, key, desc = detect_dangerous_command(
"perl -i -pe 's/SECRET=old/SECRET=new/' ~/.hermes/.env"
)
assert dangerous is True

def test_read_is_safe(self):
# Reading config is not a write — must not trip.
dangerous, key, desc = detect_dangerous_command("cat ~/.hermes/config.yaml")
Expand Down
4 changes: 4 additions & 0 deletions tools/approval.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ def _sudo_stdin_block_result(description: str) -> dict:
# the terminal side is not an open door. See #14639.
(rf'\bsed\s+-[^\s]*i.*(?:{_HERMES_CONFIG_PATH}|{_HERMES_ENV_PATH})', "in-place edit of Hermes config/env"),
(rf'\bsed\s+--in-place\b.*(?:{_HERMES_CONFIG_PATH}|{_HERMES_ENV_PATH})', "in-place edit of Hermes config/env (long flag)"),
# perl -i and ruby -i perform the same in-place mutation as sed -i but are
# not caught by the -e/-c script-execution pattern above (which targets code
# evaluation, not file mutation). Pairs the sed -i coverage from #14639.
(rf'\b(?:perl|ruby)\s+-[^\s]*i.*(?:{_HERMES_CONFIG_PATH}|{_HERMES_ENV_PATH})', "in-place edit of Hermes config/env (perl/ruby)"),
# Script execution via heredoc — bypasses the -e/-c flag patterns above.
# `python3 << 'EOF'` feeds arbitrary code via stdin without -c/-e flags.
(r'\b(python[23]?|perl|ruby|node)\s+<<', "script execution via heredoc"),
Expand Down
Loading