VAITP Dataset

← Back to the dataset

CVE-2022-23530

GuardDog v0.1.8: Arbitrary file overwrite in PyPI packages

  • CVSS 6.5
  • CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
  • Input Validation and Sanitization
  • Remote

GuardDog is a CLI tool to identify malicious PyPI packages. Versions prior to v0.1.8 are vulnerable to arbitrary file write when scanning a specially-crafted remote PyPI package. Extracting files using shutil.unpack_archive() from a potentially malicious tarball without validating that the destination file path is within the intended destination directory can cause files outside the destination directory to be overwritten. This issue is patched in version 0.1.8. Potential workarounds include using a safer module, like zipfile, and validating the location of the extracted files and discarding those with malicious paths.

CVSS base score
6.5
Published
2022-12-16
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
GuardDog
Fixed by upgrading
Yes

Solution

Update GuardDog to version 0.1.8 or higher.

Vulnerable code sample

import shutil

def unpack_archive(source, destination):
    # Vulnerable code that extracts files without validating the destination path
    shutil.unpack_archive(source, destination)

# Example usage
# unpack_archive('malicious_package.tar.gz', '/path/to/destination')

Patched code sample

import os
import shutil
import zipfile

def safe_unpack_archive(source, destination):
    # Ensure the destination directory is absolute
    destination = os.path.abspath(destination)
    
    # Extract files using zipfile for safety
    with zipfile.ZipFile(source, 'r') as zip_ref:
        for file in zip_ref.namelist():
            # Ensure the extracted file path is within the intended destination directory
            extracted_path = os.path.abspath(os.path.join(destination, file))
            if os.path.commonpath([destination, extracted_path]) != destination:
                print(f"Malicious path detected: {extracted_path}. Skipping extraction.")
                continue
            zip_ref.extract(file, destination)

# Example usage
# safe_unpack_archive('malicious_package.zip', '/path/to/destination')

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.

Cite this entry

@misc{vaitp:cve202223530,
  title        = {{GuardDog v0.1.8: Arbitrary file overwrite in PyPI packages}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-23530},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-23530/}}
}

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.