feat(security): add shell evasion guard#3400
feat(security): add shell evasion guard#3400gnipping wants to merge 3 commits intoagentscope-ai:mainfrom
Conversation
|
Hi @gnipping, this is your 18th Pull Request. 🙌 Join Developer CommunityThanks so much for your contribution! We'd love to invite you to join the official QwenPaw developer group! You can find the Discord and DingTalk group links under the "Developer Community" section on our docs page: We truly appreciate your enthusiasm—and look forward to your future contributions! 😊 We'll review your PR soon. |
There was a problem hiding this comment.
Pull request overview
Adds a new Tool Guard guardian that performs quote-aware scanning of execute_shell_command parameters to detect shell obfuscation/evasion patterns before execution.
Changes:
- Introduces
ShellEvasionGuardianwith multiple heuristics (command substitution, obfuscated flags, escaped whitespace/operators, newline/comment desync patterns). - Registers the new guardian in
ToolGuardEngine’s default guardian set.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/qwenpaw/security/tool_guard/guardians/shell_evasion_guardian.py |
New guardian implementation and helper functions for detecting shell evasion patterns. |
src/qwenpaw/security/tool_guard/engine.py |
Adds ShellEvasionGuardian to the default guardian initialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Description
Adds
ShellEvasionGuardian, a quote-aware pre-execution check forexecute_shell_commandthat flags common shell obfuscation / evasion patterns (for example command substitution, ANSI-C / locale quoting and empty-quote flag tricks, backslash-escaped whitespace and shell operators, suspicious newlines /\r,#-comment quote desync, and quoted-newline +#-line patterns). Findings are produced through the existing Tool Guard pipeline (ToolGuardEngineruns this guardian alongside the default rule- and file-path guardians).Related Issue: N/A (replace with
Fixes #…/Relates to #…if you have one)Security Considerations: Defense-in-depth only: scanning happens before the shell tool runs; severity and approval behavior follow existing Tool Guard / approval UX. This does not replace OS-level sandboxing or channel auth; misclassification remains possible for unusual but legitimate commands, so users may still need to review or approve per existing flows.
Type of Change
Component(s) Affected
Checklist
pre-commit run --all-fileslocally and it passespytestor as relevant) and they pass (please run and tick if you did)Testing
QWENPAW_TOOL_GUARD_ENABLED/ config as usual).ToolGuardEngine.guard) with toolexecute_shell_commandand acommandstring that should match one of the guardian checks, for example:echo $(whoami)→ command substitution findingecho $'-n'→ obfuscated-flag style findingecho\ hello→ backslash-escaped whitespacetrue \; false→ backslash before operatorshell_evasion_guardianand that the existing approval / blocked-tool UX still behaves as before for other guardians.Local Verification Evidence
pre-commit run --all-files # Passed (mypy, black, flake8, pylint, prettier, etc.) pytest