fix(approval): gate perl/ruby -i in-place edits of Hermes config/env - #36894
Closed
AhmetArif0 wants to merge 1 commit into
Closed
fix(approval): gate perl/ruby -i in-place edits of Hermes config/env#36894AhmetArif0 wants to merge 1 commit into
AhmetArif0 wants to merge 1 commit into
Conversation
sed -i coverage for ~/.hermes/config.yaml and .env was added in NousResearch#14639, but perl -i and ruby -i — which perform the same direct file mutation — were not covered. The existing perl/ruby pattern only catches -e/-c (code evaluation), not -i (file mutation), so: perl -i -pe 's/approvals.mode: on/approvals.mode: off/' ~/.hermes/config.yaml bypasses the approval gate entirely, letting the agent flip approvals.mode off mid-session via the mtime-keyed config cache reload. Add a single pattern mirroring the sed -i lines: `\b(?:perl|ruby)\s+-[^\s]*i` against both _HERMES_CONFIG_PATH and _HERMES_ENV_PATH. Three regression tests pin the new coverage.
13 tasks
Contributor
|
Merged via PR #38998. Your commit was cherry-picked onto current main with your authorship preserved in git log (commit a6a4e6f). Added a follow-up commit that widens the regex to also catch the separate-token form (perl -p -i -e config.yaml), which the first-flag-token pattern missed. Thanks for closing this bypass class. |
Closed
13 tasks
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sed -icoverage for~/.hermes/config.yamland.envwas added in #14639, butperl -iandruby -i— which perform the same direct file mutation — were not covered. The existingperl/rubypattern only catches-e/-c(code evaluation), not-i(file mutation), leaving this bypass open:config.yamlis the security policy (approvals.mode,yolo, and the permanent-approval allowlist live there). The mtime-keyed config cache reloads it mid-session, so a successful write immediately disables the gate — identical threat model to thesed -igap that #14639 closed.Changes
tools/approval.py: adds one pattern —\b(?:perl|ruby)\s+-[^\s]*iagainst both_HERMES_CONFIG_PATHand_HERMES_ENV_PATH, directly mirroring thesed -ilinestests/tools/test_approval.py: three new tests inTestHermesConfigWriteProtection—perl -ion config.yaml,ruby -ion config.yaml,perl -ion.envTest plan
uv run --frozen python -m pytest tests/tools/test_approval.py -x -q— 200 passed (197 existing + 3 new)perl -iandruby -iagainst~/.hermes/config.yamlare now flagged as dangerousperl -e/perl -c(code execution) andcat ~/.hermes/config.yaml(read) still behave correctly — no false positives introduced