Skip to content

fix(approval): gate perl/ruby -i in-place edits of Hermes config/env - #36894

Closed
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/approval-perl-ruby-inplace
Closed

fix(approval): gate perl/ruby -i in-place edits of Hermes config/env#36894
AhmetArif0 wants to merge 1 commit into
NousResearch:mainfrom
AhmetArif0:fix/approval-perl-ruby-inplace

Conversation

@AhmetArif0

Copy link
Copy Markdown
Contributor

Summary

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), leaving this bypass open:

perl -i -pe 's/approvals.mode: on/approvals.mode: off/' ~/.hermes/config.yaml

config.yaml is 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 the sed -i gap that #14639 closed.

Changes

  • tools/approval.py: adds one pattern — \b(?:perl|ruby)\s+-[^\s]*i against both _HERMES_CONFIG_PATH and _HERMES_ENV_PATH, directly mirroring the sed -i lines
  • tests/tools/test_approval.py: three new tests in TestHermesConfigWriteProtectionperl -i on config.yaml, ruby -i on config.yaml, perl -i on .env

Test plan

  • uv run --frozen python -m pytest tests/tools/test_approval.py -x -q — 200 passed (197 existing + 3 new)
  • perl -i and ruby -i against ~/.hermes/config.yaml are now flagged as dangerous
  • perl -e / perl -c (code execution) and cat ~/.hermes/config.yaml (read) still behave correctly — no false positives introduced

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.
@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management area/config Config system, migrations, profiles labels Jun 1, 2026
@teknium1

teknium1 commented Jun 4, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/config Config system, migrations, profiles P2 Medium — degraded but workaround exists tool/terminal Terminal execution and process management type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants