VAITP Dataset

← Back to the dataset

CVE-2022-36069

Git command execution in Poetry Python < 1.1.9 due to input handling issue

  • CVSS 7.3
  • CWE-88 Improper Neutralization of Argument Delimiters in a Command ('Argument Injection')
  • Input Validation and Sanitization
  • Remote

Poetry is a dependency manager for Python. When handling dependencies that come from a Git repository instead of a registry, Poetry uses various commands, such as `git clone`. These commands are constructed using user input (e.g. the repository URL). When building the commands, Poetry correctly avoids Command Injection vulnerabilities by passing an array of arguments instead of a command string. However, there is the possibility that a user input starts with a dash (`-`) and is therefore treated as an optional argument instead of a positional one. This can lead to Code Execution because some of the commands have options that can be leveraged to run arbitrary executables. If a developer is exploited, the attacker could steal credentials or persist their access. If the exploit happens on a server, the attackers could use their access to attack other internal systems. Since this vulnerability requires a fair amount of user interaction, it is not as dangerous as a remotely exploitable one. However, it still puts developers at risk when dealing with untrusted files in a way they think is safe, because the exploit still works when the victim tries to make sure nothing can happen, e.g. by vetting any Git or Poetry config files that might be present in the directory. Versions 1.1.9 and 1.2.0b1 contain patches for this issue.

CVSS base score
7.3
Published
2022-09-07
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Poetry
Fixed by upgrading
Yes

Solution

Update Poetry to version 1.2.0b1 or higher.

Vulnerable code sample

import subprocess

def vulnerable_git_clone(repo_url):
    # Directly using user input in a command string
    subprocess.run(f'git clone {repo_url}', shell=True, check=True)

# Example usage
vulnerable_git_clone('-e /path/to/malicious/script')  # This could lead to code execution

Patched code sample

import subprocess

def safe_git_clone(repo_url):
    # Ensure the repository URL does not start with a dash
    if repo_url.startswith('-'):
        raise ValueError("Invalid repository URL: cannot start with a dash.")

    # Use subprocess with a list to avoid command injection
    subprocess.run(['git', 'clone', repo_url], check=True)

# Example usage
try:
    safe_git_clone('https://github.com/example/repo.git')
except ValueError as e:
    print(e)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • Ensure Git parameters are safe (python-poetry/poetry-core)
    poetry/core/vcs/git.py, poetry/core/vcs/git.py · Git.checkout, poetry/core/vcs/git.py · Git.clone, poetry/core/vcs/git.py · Git.rev_parse

Cite this entry

@misc{vaitp:cve202236069,
  title        = {{Git command execution in Poetry Python < 1.1.9 due to input handling issue}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-36069},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-36069/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.