fix(tools): execute bash commands as argv with shell=False - #1930
Open
tripathiji1312 wants to merge 1 commit into
Open
fix(tools): execute bash commands as argv with shell=False#1930tripathiji1312 wants to merge 1 commit into
tripathiji1312 wants to merge 1 commit into
Conversation
run_bash_tool previously ran subprocess.run(command, shell=True), which handed the command string to /bin/sh: shell metacharacters were live, so a prompt like 'echo hi > /dev/sda' or '|sh' could execute arbitrary commands. The command is now parsed with shlex.split and executed as argv with shell=False, making metacharacters inert. The dangerous-command blocklist is checked both on the raw string and on the parsed token list, closing the r""m -rf / (quoted-concat) and rm -r -f / (split-flag) bypasses of the old substring check. New entries: rm -r -f, rm --recursive --force, rm -rf /, chmod 777. Rejected commands are logged and recorded in agent short memory.
|
Hello there, thank you for opening an PR ! 🙏🏻 The team was notified and they will get back to you asap. |
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
run_bash_toolpreviously ransubprocess.run(command, shell=True), handing the command string to/bin/sh. Shell metacharacters were live, so a prompt likeecho hi > /dev/sdaor|shcould execute arbitrary commands — the tool was effectively a remote shell for any agent with tool access.Changes
shlex.splitand executed as argv withshell=False: metacharacters become inert literal tokens (a redirection attempt fails to exec instead of writing to disk).r""m -rf /(quoted-concat hides thermsubstring)rm -r -f /(split flags evade therm -rfsubstring)rm -r -f,rm --recursive --force,rm -rf /,chmod 777.Blocked (security): ...; unparseable input (unbalanced quotes, NUL bytes) is rejected without execution.Tests
tests/structs/test_autonomous_loop_utils.py(20 tests): raw-string and argv-level blocklist coverage, quoted-concat and split-flag bypasses, NUL/empty argv rejection, shell-metacharacter inertness (>/dev/sda,|shfail to exec), benign command execution, and short-memory recording of blocked commands.