Repository navigation
Security: Command injection via shell=True in git command execution (CWE-78) #1918
Copy link
Copy link
Closed
Description
Activity
shlex.quote()is probably not a viable solution because it's only designed for POSIX shells.Warning: The shlex module is only designed for Unix shells.
The
quote()function is not guaranteed to be correct on non-POSIX compliant shells or shells from other operating systems such as Windows. Executing commands quoted by this module on such shells can open up the possibility of a command injection vulnerability.Consider using functions that pass command arguments with lists such as
subprocess.run()withshell=False.- added 16 commits that reference this issue
on May 3, 2026 - added a commit that references this issue
on May 6, 2026 Thank you all for reporting this issue! The fix was just checked in
Summary
commitizen uses
subprocess.Popen(cmd, shell=True)incommitizen/cmd.pyto execute all git commands. Multiple functions incommitizen/git.pyconstruct shell commands by interpolating values via f-strings without escaping.Affected Code
commitizen/cmd.pylines 41-43:commitizen/git.pyline 173:commitizen/git.pyline 167:commitizen/git.pyline 177:Attack Vector
An attacker poisons
pyproject.toml(e.g., via PR) with:When CI/CD runs
cz bump, the shell interprets the injected command.Impact
Suggested Fix
Replace
shell=Truewith list-based subprocess, or useshlex.quote():Reported by: Tom Chen (hypery11@gmail.com)