VAITP Dataset

← Back to the dataset

CVE-2022-23531

GuardDog CLI tool (<0.1.5) Vulnerable to Local PyPI Package Relative Path Traversal for Arbitrary File Writes

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

GuardDog is a CLI tool to identify malicious PyPI packages. Versions prior to 0.1.5 are vulnerable to Relative Path Traversal when scanning a specially-crafted local PyPI package. Running GuardDog against a specially-crafted package can allow an attacker to write an arbitrary file on the machine where GuardDog is executed due to a path traversal vulnerability when extracting the .tar.gz file of the package being scanned, which exists by design in the tarfile.TarFile.extractall function. This issue is patched in version 0.1.5.

CVSS base score
7.8
Published
2022-12-17
OWASP
A06 Vulnerable and Outdated Components
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
GuardDog
Fixed by upgrading
Yes

Solution

Update GuardDog to version 0.1.5 or higher.

Vulnerable code sample

import tarfile

def extract_package(file_path):
    with tarfile.open(file_path, "r:gz") as tar:
        tar.extractall()  # Vulnerable to path traversal

Patched code sample

import tarfile
import os

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
    # Prevent path traversal by ensuring the target path is within the allowed directory
    if members is None:
        members = tar.getmembers()
    for member in members:
        member_path = os.path.join(path, member.name)
        # Check if the member path is safe
        if not os.path.commonprefix([path, member_path]) == path:
            raise Exception("Attempted Path Traversal detected: {}".format(member_path))
    tar.extractall(path, members, numeric_owner=numeric_owner)

# Usage example
def scan_package(file_path):
    with tarfile.open(file_path, "r:gz") as tar:
        safe_extract(tar, path="safe_directory")

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:cve202223531,
  title        = {{GuardDog CLI tool (<0.1.5) Vulnerable to Local PyPI Package Relative Path Traversal for Arbitrary File Writes}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2022},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2022-23531},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-23531/}}
}

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.