fix: root-deletion blocker false positive on absolute subpaths#4
Open
brolag wants to merge 2 commits into
Open
fix: root-deletion blocker false positive on absolute subpaths#4brolag wants to merge 2 commits into
brolag wants to merge 2 commits into
Conversation
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>
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.
Problem
The dangerous-actions blocker used substring matching for
rm -rf /,rm -rf ~, andrm -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
/tmpwas 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-positionrm.Tests
6 new cases in
tests/test-hooks.sh(4 true positives, 2 false-positive regressions). Full suite: 21/21 pass.