Skip to content

fix: root-deletion blocker false positive on absolute subpaths#4

Open
brolag wants to merge 2 commits into
mainfrom
fix/root-deletion-false-positive
Open

fix: root-deletion blocker false positive on absolute subpaths#4
brolag wants to merge 2 commits into
mainfrom
fix/root-deletion-false-positive

Conversation

@brolag

@brolag brolag commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Problem

The dangerous-actions blocker used substring matching for rm -rf /, rm -rf ~, and rm -rf $HOME. Any recursive deletion of an absolute path matched the first pattern:

  • rm -rf /tmp/build-cache → blocked (false positive)
  • rm -rf ~/projects/old-clone → blocked (false positive)
  • echo "rm -rf /" → blocked (false positive)

Hit in a real session: cleaning a temp clone under /tmp was blocked as CRITICAL.

Fix

Replace the three substring patterns with a target-aware regex that blocks only when the deletion target is root or home itself: /, /*, //, ~, ~/, ~/*, $HOME. Flag variants (-fr, -r -f, sudo rm -rf /) are still caught. Quoted mentions no longer match because the pattern requires a command-position rm.

Tests

6 new cases in tests/test-hooks.sh (4 true positives, 2 false-positive regressions). Full suite: 21/21 pass.

brolag and others added 2 commits June 10, 2026 22:02
The substring patterns 'rm -rf /', 'rm -rf ~', and 'rm -rf $HOME'
blocked any recursive deletion of an absolute path (rm -rf /tmp/build)
or home subdirectory (rm -rf ~/projects/old). Replace them with a
target-aware regex that only blocks when the target is / or home
itself (/, /*, ~, ~/, $HOME), including flag variants like -fr and
-r -f. Quoted mentions (echo "rm -rf /") no longer match either.

Adds 6 test cases covering true and false positives.
The earlier target-aware regex fixed the /tmp/subpath false positive but
regressed protection: rm -rf /etc, /usr, /var, /home (caught by the old
substring 'rm -rf /') were silently allowed.

Extend the protected-root denylist to /, ~, $HOME plus the catastrophic
system dirs (/etc /usr /var /bin /sbin /lib /boot /dev /proc /sys /opt
/root /home /System /Library /Applications) and their trailing-slash / *
glob forms. Subpaths (/tmp/build, ~/proj, /etc/myapp) stay allowed.

5 new test cases. Suite: 26/26 pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant