Skip to content

fix: parse rm flags correctly to avoid pathname false positives#30

Open
lunareed720 wants to merge 1 commit into
disler:mainfrom
lunareed720:fix/rm-flag-parse
Open

fix: parse rm flags correctly to avoid pathname false positives#30
lunareed720 wants to merge 1 commit into
disler:mainfrom
lunareed720:fix/rm-flag-parse

Conversation

@lunareed720

Copy link
Copy Markdown

Fixes #28

Problem

The pre_tool_use.py hook sometimes blocks safe rm commands because it regex-matches -...r... inside pathnames (e.g. soft-hold-enrollment) as if it were an rm -r flag.

Fix

  • Parse the shell command with shlex.split() and interpret -r/-R/--recursive and -f/--force only when they are actual option tokens.
  • Only treat truly dangerous targets as dangerous when -r is present (/, ., .., ~, wildcards).
  • Keep conservative policy: any rm with both recursive+force remains blocked.

Test

Added a small unittest file under tests/ that reproduces the reported false positive and covers a few core cases.

Run locally:

python3 -m unittest discover -s tests -p 'test_*.py'

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.

pre_tool_use.py hook falsely blocks safe rm due to pathname matching -...r...

1 participant