VAITP Dataset

← Back to the dataset

CVE-2022-21187

Command injection in libvcs < 0.11.1 via Mercurial (hg)

  • CVSS 9.8
  • CWE-88
  • Input Validation and Sanitization
  • Remote

The package libvcs before 0.11.1 are vulnerable to Command Injection via argument injection. When calling the update_repo function (when using hg), the url parameter is passed to the hg clone command. By injecting some hg options it was possible to get arbitrary command execution.

CVSS base score
9.8
Published
2022-03-14
OWASP
A03 Injection
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
libvcs
Fixed by upgrading
Yes

Solution

Update libvcs to version 0.11.1 or higher.

Vulnerable code sample

import subprocess

def update_repo(url):
    # Vulnerable to command injection
    command = f'hg clone {url}'
    subprocess.run(command, shell=True, check=True)

Patched code sample

import subprocess
import shlex

def update_repo(url):
    # Validate the URL to prevent command injection
    if not is_valid_url(url):
        raise ValueError("Invalid repository URL")

    # Safely construct the command
    command = ['hg', 'clone', url]
    
    # Use subprocess.run to execute the command securely
    subprocess.run(command, check=True)

def is_valid_url(url):
    # Implement URL validation logic here
    # For example, only allow certain protocols or patterns
    return url.startswith(('http://', 'https://', 'ssh://'))

Cite this entry

@misc{vaitp:cve202221187,
  title        = {{Command injection in libvcs < 0.11.1 via Mercurial (hg)}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-21187},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-21187/}}
}

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.