Skip to content

fix(security): prevent shell injection in sudo password piping#65

Merged
teknium1 merged 1 commit intoNousResearch:mainfrom
leonsgithub:fix/sudo-password-shell-injection
Feb 27, 2026
Merged

fix(security): prevent shell injection in sudo password piping#65
teknium1 merged 1 commit intoNousResearch:mainfrom
leonsgithub:fix/sudo-password-shell-injection

Conversation

@leonsgithub
Copy link
Copy Markdown

Problem

The sudo password in _transform_sudo_command() was embedded in a shell command using single-quote interpolation:

return f"echo '{sudo_password}' | sudo -S -p ''"

If the password contained shell metacharacters (single quotes, $(), backticks), they would escape the quoting and be interpreted by the shell — enabling arbitrary command execution.

Example — a password like test'; rm -rf / # produces:

echo 'test'; rm -rf / #' | sudo -S -p ''
       ^^^^^^^^^^^ executed as a separate command

Fix

Use shlex.quote() which properly handles all shell-special characters:

import shlex
return f"echo {shlex.quote(sudo_password)} | sudo -S -p ''"

The same attack payload now produces:

echo 'test'"'"'; rm -rf / #' | sudo -S -p ''
      ^^^^^^^^^^^^^^^^^^^^^^^^ entire string treated as echo argument

Scope

Single file, 3-line change in tools/terminal_tool.py. No behavior change for normal passwords — shlex.quote() is a no-op for simple alphanumeric strings.

The sudo password was embedded in shell commands via single-quote
interpolation: echo '{password}' | sudo -S

If the password contained shell metacharacters (single quotes,
$(), backticks), they would be interpreted by the shell, enabling
arbitrary command execution.

Fix: use shlex.quote() which properly escapes all shell-special
characters, ensuring the password is always treated as a literal
string argument to echo.
@teknium1 teknium1 merged commit 547ba73 into NousResearch:main Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants