feat: add destructive command guard plugin with pattern detection#316
Merged
mpfaffenberger merged 2 commits intompfaffenberger:mainfrom May 3, 2026
Merged
Conversation
Introduces a pure-regex destructive command detector under code_puppy/plugins/destructive_command_guard/. Covers: - rm -rf /, ~, and glob variants - git push --mirror, clean -fd, reset --hard, checkout/restore . - SQL DROP via psql/mysql/sqlite3 - docker system/volume prune - accidental npm/yarn/twine publish Pre-filtered by cheap substring check, then shell-operator awareness to avoid false positives in string args.
| # Cheap pre-filter substrings — if none appear, bail immediately | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| _PREFILTER_SUBSTRINGS = ( |
Owner
There was a problem hiding this comment.
can you ask your agent to include windoze powershell and command.exe versions too?
…rn detection - Added comprehensive Windows PowerShell destructive command patterns including Remove-Item with Recurse/Force flags, Format-Volume, Clear-Disk, registry operations, and remote code execution via irm|iex - Added Windows CMD destructive command patterns covering rd /s /q recursive deletes, del /s system file deletes, format commands, diskpart, bcdedit, and registry deletions - Reorganized pattern lists by shell type (Unix, PowerShell, CMD) for better maintainability - Added extensive test coverage with 395+ lines of pytest tests covering all three shell environments - Updated module documentation to reflect expanded cross-platform coverage - Enhanced prefilter substrings to include Windows-specific keywords and aliases - Maintained existing Unix/Linux pattern coverage including rm -rf, git operations, SQL DROP, and docker prune commands
This was referenced May 6, 2026
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.
Introduces a pure-regex destructive command detector under
code_puppy/plugins/destructive_command_guard/.Covered patterns
Unix/Linux
rm -rf /,rm -rf /*,rm -rf ~,rm -rf ~/*Cross-platform (git, docker, npm/yarn, twine, SQL clients)
git push --mirror,git clean -fd,git reset --hard,git checkout/restore .DROPviapsql/mysql/sqlite3clientsdocker system prune -af,docker volume prune -fnpm publish,yarn publish,twine uploadWindows PowerShell
Remove-Item -Recurse -Force(includingrialias)Format-Volume,Clear-DiskRemove-ItemPropertyon registry pathsClear-RecycleBin -Forceirm | iexremote code execution (download + execute patterns)Windows CMD
rd /s /q,rmdir /s /qdel /s/erase /son system directoriesformat,format /qdiskpart(any invocation)bcdedit /delete,reg deleteon critical keysDesign
All matching is pure regex — no LLM calls, no caching. Commands are pre-filtered by cheap substring check, then verified as real invocations via shell-operator awareness (
&&,||,;,|) to avoid false positives in string arguments.Patterns are organized into three lists (
_UNIX_DESTRUCTIVE_PATTERNS,_POWERSHELL_DESTRUCTIVE_PATTERNS,_CMD_DESTRUCTIVE_PATTERNS) and combined at load time. First match wins.Files
code_puppy/plugins/destructive_command_guard/detector.pydetect_destructive_command()code_puppy/plugins/destructive_command_guard/__init__.pytests/plugins/test_destructive_command_detector.py