fix(security): shell-quote workdir in SSH/Docker/Singularity to prevent command injection - #1799
Closed
0xbyt4 wants to merge 1 commit into
Closed
fix(security): shell-quote workdir in SSH/Docker/Singularity to prevent command injection#17990xbyt4 wants to merge 1 commit into
0xbyt4 wants to merge 1 commit into
Conversation
…nt command injection
The workdir parameter from terminal_tool was interpolated unescaped into
shell commands: f'cd {work_dir} && {exec_command}'. A crafted workdir
like '/tmp/$(rm -rf /)' would execute the subshell as command substitution.
Fixed by wrapping work_dir with shlex.quote() in all three backends.
SSH was the most critical (always triggered), Docker and Singularity
only triggered for ~-prefixed paths but fixed for defense in depth.
Contributor
|
This is now fixed via PR #5629 (merged), which sanitizes workdir with tilde-aware shlex.quote + an allowlist validator. Thanks for flagging the vulnerability! |
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
The
workdirparameter fromterminal_toolwas interpolated unescaped into shell commands:A crafted workdir like
/tmp/$(rm -rf /)would execute the subshell as command substitution on the target host.Attack path: LLM tool call →
terminal_tool(command="ls", workdir="/tmp/$(malicious)")→SSHEnvironment._execute_oneshot→ shell injection on remote host. Theworkdirparameter bypasses dangerous command checks since those only inspect thecommandargument.Fixed with
shlex.quote(work_dir)in all three backends:tools/environments/ssh.py— always triggered (highest risk)tools/environments/docker.py— only for~-prefixed pathstools/environments/singularity.py— only for~-prefixed pathsTest plan
TestWorkdirShellEscaping::test_workdir_with_shell_metacharacters_is_escaped— proves$(rm -rf /)in workdir is quoted