Skip to content

feat: add destructive command guard plugin with pattern detection#316

Merged
mpfaffenberger merged 2 commits intompfaffenberger:mainfrom
thomwebb:feature/destructive-command-detector
May 3, 2026
Merged

feat: add destructive command guard plugin with pattern detection#316
mpfaffenberger merged 2 commits intompfaffenberger:mainfrom
thomwebb:feature/destructive-command-detector

Conversation

@thomwebb
Copy link
Copy Markdown
Contributor

@thomwebb thomwebb commented May 3, 2026

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 .
  • DROP via psql/mysql/sqlite3 clients
  • docker system prune -af, docker volume prune -f
  • npm publish, yarn publish, twine upload

Windows PowerShell

  • Remove-Item -Recurse -Force (including ri alias)
  • Format-Volume, Clear-Disk
  • Remove-ItemProperty on registry paths
  • Clear-RecycleBin -Force
  • irm | iex remote code execution (download + execute patterns)

Windows CMD

  • rd /s /q, rmdir /s /q
  • del /s / erase /s on system directories
  • format, format /q
  • diskpart (any invocation)
  • bcdedit /delete, reg delete on critical keys

Design

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

File Description
code_puppy/plugins/destructive_command_guard/detector.py Pattern definitions + detect_destructive_command()
code_puppy/plugins/destructive_command_guard/__init__.py Plugin module docstring
tests/plugins/test_destructive_command_detector.py 72 parametrized test cases

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 = (
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you ask your agent to include windoze powershell and command.exe versions too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

…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
@mpfaffenberger mpfaffenberger merged commit fc5bd8d into mpfaffenberger:main May 3, 2026
2 checks passed
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.

2 participants