VAITP Dataset

← Back to the dataset

CVE-2024-45388

Path traversal vulnerability allows file reading on Hoverfly server.

  • CVSS 7.5
  • CWE-22
  • Input Validation and Sanitization
  • Remote

Hoverfly is a lightweight service virtualization/ API simulation / API mocking tool for developers and testers. The `/api/v2/simulation` POST handler allows users to create new simulation views from the contents of a user-specified file. This feature can be abused by an attacker to read arbitrary files from the Hoverfly server. Note that, although the code prevents absolute paths from being specified, an attacker can escape out of the `hf.Cfg.ResponsesBodyFilesPath` base path by using `../` segments and reach any arbitrary files. This issue was found using the Uncontrolled data used in path expression CodeQL query for python. Users are advised to make sure the final path (`filepath.Join(hf.Cfg.ResponsesBodyFilesPath, filePath)`) is contained within the expected base path (`filepath.Join(hf.Cfg.ResponsesBodyFilesPath, "/")`). This issue is also tracked as GHSL-2023-274.

CVSS base score
7.5
Published
2024-09-02
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Checking
Code defect classification
Incorrect Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Hoverfly

Solution

Implement strict path validation to ensure that user-specified file paths do not allow directory traversal. Upgrade to the latest version of Hoverfly where this issue is patched.

Vulnerable code sample

import os
from pathlib import Path

def load_simulation_body(file_path: str) -> bytes:
    # VULNERABLE: joins user-supplied path without proper containment check
    full_path = Path(os.getenv("HF_RESPONSES_PATH", "/var/lib/hoverfly/responses")).joinpath(file_path)
    with open(full_path, "rb") as f:
        return f.read()

Patched code sample

import os
from pathlib import Path

def load_simulation_body(file_path: str) -> bytes:
    # FIX: ensure the resolved path stays within the configured base directory
    base_dir = Path(os.getenv("HF_RESPONSES_PATH", "/var/lib/hoverfly/responses")).resolve()
    full_path = base_dir.joinpath(file_path).resolve()
    if not str(full_path).startswith(str(base_dir) + os.sep):
        raise ValueError("Path traversal detected")
    with open(full_path, "rb") as f:
        return f.read()

Payload

../../../../etc/passwd

Cite this entry

@misc{vaitp:cve202445388,
  title        = {{Path traversal vulnerability allows file reading on Hoverfly server.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-45388},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-45388/}}
}

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.