fix(cli): mitigate shell injection in quick_commands exec via shlex.split() - #48571
fix(cli): mitigate shell injection in quick_commands exec via shlex.split()#48571baolingao wants to merge 1 commit into
Conversation
|
This PR is filed against an unclean base: it shows 5,140 changed files and ~1.84M deletions (CONFLICTING), effectively a whole-fork/whole-repo push rather than the focused Marking Note: the underlying |
de42564 to
3900d92
Compare
…plit() Prefer shlex.split() + shell=False for user-defined quick commands, falling back to shell=True only when the command contains shell operators (pipes, redirects, chaining) that cannot be expressed as an argv list. This reduces the attack surface if config.yaml is compromised (CWE-78) while preserving backward compatibility for existing configurations that rely on shell features. Tested: - echo hello → shell=False, runs - echo hello | wc -c → shell=True fallback, runs - echo "unclosed → shlex.split() ValueError → shell=True fallback
3900d92 to
61dcbb6
Compare
|
Thank you for narrowing this to the quick-command handler. The current-main implementation still uses a shell, but this change needs a clarified execution contract before it can be salvaged. Problems
Suggested changes
Automated hermes-sweeper review. |
Summary
The
quick_commandsexec handler incli.pyruns user-defined commands withshell=Trueunconditionally (CWE-78). While these commands are configured inconfig.yamlby the user and are not agent-controlled, a compromised configfile could inject arbitrary shell commands through metacharacters.
Change
Prefer
shlex.split()+shell=Falsefor simple commands, falling back toshell=Trueonly when the command contains shell operators (|,;,&&,||,>,<,>>,&,$()) that cannot be expressed as an argv list, orwhen
shlex.split()raisesValueError.This preserves backward compatibility — existing configurations that use shell
features continue to work unchanged. Simple commands like
git statusorpython script.pynow run without a shell.Tested
echo hello→shell=False, worksecho hello | wc -c→shell=Truefallback, worksecho "unclosed→shlex.split()ValueError →shell=TruefallbackRelated