Skip to content

Security: Command injection via shell=True in git command execution (CWE-78) #1918

Description

@hypery11

Summary

commitizen uses subprocess.Popen(cmd, shell=True) in commitizen/cmd.py to execute all git commands. Multiple functions in commitizen/git.py construct shell commands by interpolating values via f-strings without escaping.

Affected Code

commitizen/cmd.py lines 41-43:

process = subprocess.Popen(cmd, shell=True, ...)

commitizen/git.py line 173:

return cmd.run(f'git tag {option} {tag} -m "{msg or tag}"')

commitizen/git.py line 167:

return cmd.run(f"git tag {tag}")

commitizen/git.py line 177:

return cmd.run(f"git add {' '.join(args)}")

Attack Vector

An attacker poisons pyproject.toml (e.g., via PR) with:

[tool.commitizen]
annotated_tag = true
annotated_tag_message = 'Release" && malicious_command && echo "'

When CI/CD runs cz bump, the shell interprets the injected command.

Impact

  • Arbitrary command execution in CI/CD pipelines
  • CVSS 3.1: 7.8 (High)
  • Similar to CVE-2026-33718 (OpenHands command injection via git operations)

Suggested Fix

Replace shell=True with list-based subprocess, or use shlex.quote():

subprocess.run(["git", "tag", option, tag, "-m", msg or tag])

Reported by: Tom Chen (hypery11@gmail.com)

Activity

  1. PhilipNelson5 commented on Apr 15, 2026

    @PhilipNelson5
    Contributor

    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() with shell=False.

    https://docs.python.org/3/library/shlex.html#shlex.quote

  2. self-assigned this
    on May 3, 2026
  3. added 16 commits that reference this issue on May 3, 2026
    a0efa57
    11d6890
    b58f63a
    b480ecf
    e76f086
    03f1543
    f772cc0
    19d1861
    080cf83
    e96caf1
    28f982f
    713e7ed
    53dc759
    153d8f6
    e7aa5f8
    90b055b
  4. added a commit that references this issue on May 6, 2026
    0cc88a5
  5. bearomorphism commented on May 6, 2026

    @bearomorphism
    Collaborator

    Thank you all for reporting this issue! The fix was just checked in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions