fix(security): close shell-escape denylist bypass + fail-closed on missing approval module (#36846, #36847)#40591
Merged
Merged
Conversation
…d on missing approval module DANGEROUS_PATTERNS and HARDLINE_PATTERNS are matched on the raw command string, so backslash-escape (r\m) and empty-quote split (r''m) bypass both lists. _normalize_command_for_detection now strips these before pattern matching. tui_gateway shell.exec had a bare 'except ImportError: pass' that silently disabled the entire safety gate if tools.approval wasn't importable. Changed to fail-closed (return 5001 error). Added detect_hardline_command check. Fixes #36846, #36847.
6 tasks
Contributor
🔎 Lint report:
|
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.
Summary
Closes two ways to bypass dangerous-command detection. Closes #36846 and #36847.
tools/approval.py): the denylist normalizer didn't account for shell tokenization, sor\\m -rf /andr''m -rf /slipped past detection (returneddangerous=False) while the shell still executed them asrm -rf /. The normalizer now strips backslash-escapes and empty-string literals before matching.tui_gateway/server.py):shell.execdidexcept ImportError: pass, running the command with no safety check iftools.approvalfailed to import. Now fails closed (returns an error) and also blocks hardline commands viadetect_hardline_command.Validation
Live-verified the bypass on main (
r\\m -rf /→dangerous=False) and after the fix (→True);rm -rf /still caught,ls -lastill benign. Regression tests added (4 passed).Cherry-picked from #40370 (@ashishpatel26), authorship preserved; added regression tests.