Skip to content

fix(security): shell-quote workdir in SSH/Docker/Singularity to prevent command injection - #1799

Closed
0xbyt4 wants to merge 1 commit into
NousResearch:mainfrom
0xbyt4:fix/ssh-workdir-injection
Closed

fix(security): shell-quote workdir in SSH/Docker/Singularity to prevent command injection#1799
0xbyt4 wants to merge 1 commit into
NousResearch:mainfrom
0xbyt4:fix/ssh-workdir-injection

Conversation

@0xbyt4

@0xbyt4 0xbyt4 commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Summary

The workdir parameter from terminal_tool was interpolated unescaped into shell commands:

wrapped = f'cd {work_dir} && {exec_command}'

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. The workdir parameter bypasses dangerous command checks since those only inspect the command argument.

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 paths
  • tools/environments/singularity.py — only for ~-prefixed paths

Test plan

  • TestWorkdirShellEscaping::test_workdir_with_shell_metacharacters_is_escaped — proves $(rm -rf /) in workdir is quoted
  • 29 existing environment tests pass, 0 regressions

…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.
@teknium1

teknium1 commented Apr 6, 2026

Copy link
Copy Markdown
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!

@teknium1 teknium1 closed this Apr 6, 2026
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