fix(approval): gate perl/ruby -i in-place edits of Hermes config/env - #38998
Merged
Merged
Conversation
sed -i coverage for ~/.hermes/config.yaml and .env was added in #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.
The salvaged pattern matched -i only inside the first flag token, so `perl -p -i -e '...' config.yaml` (the -i split out after -p) slipped through. Widen to match a -...i flag token anywhere in the args; still no false positive on `perl -e` code eval or config reads. Adds tests for the separate-token, backup-suffix, and read-safe forms.
Contributor
🔎 Lint report:
|
3 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
perl -i/ruby -iin-place edits of~/.hermes/config.yamland.envnow trip the approval gate, closing the same bypass class that #14639 closed forsed -i.config.yamlis the security policy (approvals.mode,yolo, the permanent-approval allowlist), and the mtime-keyed config cache reloads it mid-session — so a successful in-place write flips the gate off immediately. The existingperl|rubypattern only matched-e/-c(code eval) as the first flag, leaving-i(file mutation) uncovered.Salvaged from #36894 by @AhmetArif0. Follow-up commit widens the regex: the contributor's
-[^\s]*imatched-ionly inside the first flag token, soperl -p -i -e '...' config.yaml(the-isplit out after-p) still slipped through. The pattern now matches a-...iflag token anywhere in the args.Changes
tools/approval.py: one pattern —\b(?:perl|ruby)\b.*(?:^|\s)-[^\s]*i\b.*(?:CONFIG|ENV)against the Hermes config/env paths, mirroring thesed -ilines.tests/tools/test_approval.py: 6 tests —perl -i/ruby -i/perl -ion.env(contributor), plus separate-token (perl -p -i -e), backup-suffix (perl -i.bak), and read-safe (perl -wne 'print' config.yaml) cases.Validation
perl -i -pe ... config.yamlperl -pi -e ... config.yamlperl -p -i -e ... config.yamlperl -i.bak -pe ... config.yamlruby -i / ruby -p -i -e ... .envperl -wne 'print' config.yaml(read)scripts/run_tests.sh tests/tools/test_approval.py→ 203 passed. E2E verified all 7 in-place forms gate and reads stay safe via realdetect_dangerous_commandwith isolated HERMES_HOME.Closes #36894.
Infographic