hermes - ✅(Solved) Fix Over-broad DANGEROUS_PATTERNS regex flags every absolute path as 'delete in root path' [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#18083Fetched 2026-05-01 05:53:59
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×1

Root Cause

tools/approval.py:202 matches ANY rm command with an absolute path because the regex only requires a single / character after the optional flags:

Fix Action

Fixed

PR fix notes

PR #18089: fix(approval): tighten 'delete in root path' regex to system-root targets only

Description (problem / solution / changelog)

Summary

The delete in root path rule in DANGEROUS_PATTERNS (tools/approval.py:215) matched ANY rm with an absolute path because the regex required only a single / after the optional flags. Tighten it so it fires on real system-root targets only — plain /, root globs, and the system top-level dirs already enumerated by HARDLINE_PATTERNS.

The bug

(r'\brm\s+(-[^\s]*\s+)*/', "delete in root path"),

The / after the flag group matches the leading / of any absolute path, regardless of where in the filesystem the target lives. Every rm /home/<user>/..., rm /tmp/..., rm /mnt/c/... is flagged as delete in root path and forced through an approval prompt — including routine cleanup of the agent's own working files. From the reporter's run:

rm -f /home/scott/hermes-home/fawn_lily_temp.html
↳ Reason: delete in root path

That's deleting one file in the user's home directory; nothing about it is near the system root.

The fix

Constrain what comes after the / to the genuinely-dangerous shapes:

(r'\brm\s+(-[^\s]*\s+)*/(\s|\*|$|\.\*|(bin|boot|dev|etc|lib|lib64|opt|proc|root|run|sbin|srv|sys|usr|var)(/|\s|$))', "delete in root path"),

System top-level dirs match the set already enumerated by the HARDLINE_PATTERNS rules at lines 144-148, so the two layers stay aligned. Recursive rm of any deeper path (including /home/...) is still caught by the separate -r/--recursive rules at lines 216-217 — coverage is unchanged for actually-recursive deletes.

CommandOld ruleNew ruleSource of approval (if any)
rm -rf /matchesmatcheshardline + this rule
rm -rf /*matchesmatcheshardline + this rule
rm -rf /.*matchesmatchesthis rule
rm -rf /etc/passwdmatchesmatchesthis rule
rm -rf /var/logmatchesmatchesthis rule
rm /usr/bin/somethingmatchesmatchesthis rule
rm /home/user/foomatches (false positive)does not matchnone — non-recursive single-file rm
rm -f /home/user/foomatches (false positive)does not matchnone — non-recursive single-file rm
rm /tmp/xmatches (false positive)does not matchnone — non-recursive single-file rm
rm -rf /mnt/c/Users/user/foomatches (false positive)does not matchrecursive-delete rule still flags
rm -rf /home/user/.cachematches (false positive)does not matchrecursive-delete rule still flags

Test plan

  • Focused: tests/tools/test_approval.py — 143 passed (11 new in TestRmRootPathRegexPrecision)
  • Adjacent: tests/tools/test_force_dangerous_override.py, test_approval_plugin_hooks.py, test_approval_heartbeat.py, test_cron_approval_mode.py — 37 passed
  • Regression guard: each false-positive case in the table fails the old regex (old=True) and passes the new one (new=False); each true-positive case matches both. Verified end-to-end with re.compile(...).search(cmd).
  • Confirmed rm -rf /home/user/.cache stays dangerous via the separate recursive delete rule (not via this rule), so coverage of recursive deletes is unchanged.

Pre-existing baseline failures in tests/tools/test_mcp_tool.py, test_mcp_oauth.py, test_mcp_reconnect_signal.py, test_tts_kittentts.py are orthogonal — those modules are untouched.

Related

  • Fixes #18083
  • Aligns the system-dir enumeration in DANGEROUS_PATTERNS with the existing HARDLINE_PATTERNS set at tools/approval.py:144-148
  • Independent from #17962 (different rules; reverse-shell-via-flag and two-stage download-execute)

Changed files

  • tests/tools/test_approval.py (modified, +80/-0)
  • tools/approval.py (modified, +20/-1)

Code Example

(r'\brm\s+(-[^\s]*\s+)*/', "delete in root path"),

---

rm -f /home/scott/hermes-home/fawn_lily_temp.html
Reason: delete in root path

---

(r'\brm\s+(-[^\s]*\s+)*/(\s|\*|$|\.\*|(bin|boot|dev|etc|lib|lib64|opt|proc|root|run|sbin|srv|sys|usr|var)(/|\s|$))', "delete in root path"),
RAW_BUFFERClick to expand / collapse

Bug

tools/approval.py:202 matches ANY rm command with an absolute path because the regex only requires a single / character after the optional flags:

(r'\brm\s+(-[^\s]*\s+)*/', "delete in root path"),

The first / of any absolute path matches, regardless of where in the filesystem the target actually lives.

Impact

Every rm /home/<user>/..., rm /tmp/..., rm /mnt/c/..., etc. is flagged as "delete in root path" and requires human approval. In practice this is enormous friction — it fires on routine cleanup of the agent's own working files. Example from a real run:

rm -f /home/scott/hermes-home/fawn_lily_temp.html
↳ Reason: delete in root path

That command is deleting one file in the user's home directory, not anything near the system root.

Reproduction

Run any rm with an absolute, non-root path through the agent's command-approval pipeline. It will be flagged as "delete in root path."

Proposed fix

Tighten the regex so it only fires on actual system-root targets — plain /, root globs (/*, /.*), and system top-level dirs (/bin, /boot, /dev, /etc, /lib, /lib64, /opt, /proc, /root, /run, /sbin, /srv, /sys, /usr, /var):

(r'\brm\s+(-[^\s]*\s+)*/(\s|\*|$|\.\*|(bin|boot|dev|etc|lib|lib64|opt|proc|root|run|sbin|srv|sys|usr|var)(/|\s|$))', "delete in root path"),

Test cases

Verified locally — all genuinely-dangerous commands still trip, all routine paths are now allowed:

CommandOld ruleNew rule
rm -rf /matchesmatches ✓
rm -rf /*matchesmatches ✓
rm -rf /.*matchesmatches ✓
rm -rf /etc/passwdmatchesmatches ✓
rm -rf /var/logmatchesmatches ✓
rm /usr/bin/somethingmatchesmatches ✓
rm /home/user/foomatches (false positive)does not match ✓
rm -f /home/user/foomatches (false positive)does not match ✓
rm /tmp/xmatches (false positive)does not match ✓
rm -rf /mnt/c/Users/user/foomatches (false positive)does not match ✓
rm -rf /home/user/.cachematches (false positive)does not match ✓

Happy to send this in as a PR if useful.

— Reported from a Hermes Agent v0.11.0 user running on Aurora WSL2 Ubuntu-24.04.

extent analysis

TL;DR

Update the regex pattern in tools/approval.py to accurately identify rm commands that target the system root path.

Guidance

  • Review the proposed fix regex pattern to ensure it covers all necessary system top-level directories and edge cases.
  • Test the updated regex pattern with various rm commands, including those that should and should not be flagged as "delete in root path".
  • Verify that the new pattern does not introduce any new false positives or false negatives.
  • Consider adding more test cases to cover additional scenarios, such as rm commands with multiple flags or options.

Example

The proposed fix regex pattern is:

(r'\brm\s+(-[^\s]*\s+)*/(\s|\*|$|\.\*|(bin|boot|dev|etc|lib|lib64|opt|proc|root|run|sbin|srv|sys|usr|var)(/|\s|$))', "delete in root path"),

This pattern should be used to replace the existing regex pattern in tools/approval.py.

Notes

The updated regex pattern may still have limitations or edge cases that are not accounted for. Additional testing and verification should be performed to ensure the pattern is accurate and effective.

Recommendation

Apply the proposed workaround by updating the regex pattern in tools/approval.py to the new pattern, as it has been verified to reduce false positives and accurately identify rm commands that target the system root path.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Over-broad DANGEROUS_PATTERNS regex flags every absolute path as 'delete in root path' [1 pull requests, 1 participants]