{"id":1176,"cve":"CVE-2024-45388","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2024-45388\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":7.5,"published":"2024-09-02","owasp":"A05 Security Misconfiguration","odc":"Checking","cdc":"Incorrect Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Information Disclosure","summary":"Path traversal vulnerability allows file reading on Hoverfly server.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2024-45388\/","description":"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.","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.","affected_component":"Hoverfly","fixed_by_upgrading":false,"vulnerable_code":"import os\nfrom pathlib import Path\n\ndef load_simulation_body(file_path: str) -> bytes:\n    # VULNERABLE: joins user-supplied path without proper containment check\n    full_path = Path(os.getenv(\"HF_RESPONSES_PATH\", \"\/var\/lib\/hoverfly\/responses\")).joinpath(file_path)\n    with open(full_path, \"rb\") as f:\n        return f.read()\n","patched_code":"import os\nfrom pathlib import Path\n\ndef load_simulation_body(file_path: str) -> bytes:\n    # FIX: ensure the resolved path stays within the configured base directory\n    base_dir = Path(os.getenv(\"HF_RESPONSES_PATH\", \"\/var\/lib\/hoverfly\/responses\")).resolve()\n    full_path = base_dir.joinpath(file_path).resolve()\n    if not str(full_path).startswith(str(base_dir) + os.sep):\n        raise ValueError(\"Path traversal detected\")\n    with open(full_path, \"rb\") as f:\n        return f.read()\n","payload_needed":true,"payload":"```plaintext\n..\/..\/..\/..\/etc\/passwd\n```","payload_status":"available","published_fix":[],"references":null}