fix(hooks): block rm long flags (--recursive --force) in denylist - #324
Merged
Conversation
The recursive-delete rule captured only single-dash combined short flags
via /((-[a-zA-Z]+\s*)+)/, so GNU long flags never matched and
`rm --recursive --force src/` (in any order) slipped past the denylist.
The -R uppercase short form was also missed (test was /r/, lowercase-only).
Detect recursive via short -r/-R or long --recursive, and force via short
-f or long --force, both required and in any order, still gated by
SAFE_RM_TARGETS so build/temp deletes stay allowed. The `(?:^|\s)-` anchor
keeps double-dash long flags and mid-word dashes out of the short-flag
bucket. Short-flag behavior, the {blocked,rule,msg} shape, and the
fail-open guard are unchanged. #311 full-string rules untouched.
Closes #312
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SATRHKa6mDHDuirhP6QuwL
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.
What & why
The denylist
recursive-deleterule captured only single-dash combined short flags via/((-[a-zA-Z]+\s*)+)/, so GNU long flags never matched —rm --recursive --force src/(in any order) slipped past the block outside the safe-target dirs. The uppercase-Rshort form was also missed (the check was/r/, lowercase-only).Now recursive is detected via short
-r/-Ror long--recursive, and force via short-for long--force; both are required, in any order, still gated bySAFE_RM_TARGETS. The(?:^|\s)-anchor keeps double-dash long flags and mid-word dashes (file-r.txt) out of the short-flag bucket, so no false short-flag match. Short-flag behavior, the{blocked, rule, msg}shape, and the fail-open guard are unchanged. #311's full-string pipe-to-shell/eval rules are untouched.Acceptance criteria
--recursiveAND--force, in any order) outside theSAFE_RM_TARGETSallowlist. Verified byAC-312.1test (rm --recursive --force src/,rm --force --recursive src/,-R --force, chained segment) all →rule: 'recursive-delete'.--recursivealone (no force) still passes, by design.rm --recursive --force src/(blocked) and a safe-target delete likerm -rf node_modules(allowed). Verified byAC-312.1andAC-312.2tests (rm -rf node_modules,rm --recursive --force node_modules,rm --force --recursive dist build coverageall allowed).Verification
pnpm verifygreen: 558/558 tests pass (50 files), including the agy denylist-parity test (AC-289.2) that exercises recursive-delete. No ReDoS: the new regex/(?:^|\s)-([a-zA-Z]+)/gis linear. No false positive on common safe deletes (safe-target gate preserved;--recursive-only still allowed).Closes #312
🤖 Generated with Claude Code