Skip to content

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

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-18970df9
Jun 4, 2026
Merged

teknium1 merged 2 commits into
mainfrom
hermes/hermes-18970df9

Conversation

@teknium1

@teknium1 teknium1 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

perl -i / ruby -i in-place edits of ~/.hermes/config.yaml and .env now trip the approval gate, closing the same bypass class that #14639 closed for sed -i.

config.yaml is 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 existing perl|ruby pattern 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]*i matched -i only inside the first flag token, so perl -p -i -e '...' config.yaml (the -i split out after -p) still slipped through. The pattern now matches a -...i flag 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 the sed -i lines.
  • tests/tools/test_approval.py: 6 tests — perl -i / ruby -i / perl -i on .env (contributor), plus separate-token (perl -p -i -e), backup-suffix (perl -i.bak), and read-safe (perl -wne 'print' config.yaml) cases.

Validation

Form Before After
perl -i -pe ... config.yaml not gated gated
perl -pi -e ... config.yaml not gated gated
perl -p -i -e ... config.yaml not gated gated
perl -i.bak -pe ... config.yaml not gated gated
ruby -i / ruby -p -i -e ... .env not gated gated
perl -wne 'print' config.yaml (read) safe safe

scripts/run_tests.sh tests/tools/test_approval.py → 203 passed. E2E verified all 7 in-place forms gate and reads stay safe via real detect_dangerous_command with isolated HERMES_HOME.

Closes #36894.

Infographic

gate-perl-ruby-inplace-approval

AhmetArif0 and others added 2 commits June 4, 2026 05:21
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.
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-18970df9 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9792 on HEAD, 9792 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5085 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@teknium1
teknium1 merged commit b04c6e9 into main Jun 4, 2026
23 checks passed
@teknium1
teknium1 deleted the hermes/hermes-18970df9 branch June 4, 2026 12:36
@alt-glitch alt-glitch added type/security Security vulnerability or hardening tool/terminal Terminal execution and process management P2 Medium — degraded but workaround exists labels Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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