VAITP Dataset

← Back to the dataset

CVE-2024-27318

Directory Traversal vulnerability in onnx versions ≤ 1.15.0 allows file access.

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

Versions of the package onnx before and including 1.15.0 are vulnerable to Directory Traversal as the external_data field of the tensor proto can have a path to the file which is outside the model current directory or user-provided directory. The vulnerability occurs as a bypass for the patch added for CVE-2022-25882.

CVSS base score
7.5
Published
2024-02-23
OWASP
A05 Security Misconfiguration
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Functionality
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Local
Impact
Information Disclosure
Affected component
onnx
Fixed by upgrading
Yes

Solution

Upgrade to onnx version 1.15.1 or later.

Vulnerable code sample

import os
import onnx
from onnx import TensorProto

def load_external_tensor(model_path: str, tensor: TensorProto) -> bytes:
    """Load raw data for a tensor that uses external storage."""
    # VULNERABLE: uses external_data path without validation, enabling path traversal
    external_path = tensor.external_data[0].value
    full_path = os.path.join(os.path.dirname(model_path), external_path)
    with open(full_path, "rb") as f:
        return f.read()

Patched code sample

import os
import onnx
from onnx import TensorProto

def load_external_tensor(model_path: str, tensor: TensorProto) -> bytes:
    """Load raw data for a tensor that uses external storage."""
    # FIX: sanitize external_data path to prevent directory traversal
    external_path = tensor.external_data[0].value
    base_dir = os.path.abspath(os.path.dirname(model_path))
    candidate = os.path.abspath(os.path.join(base_dir, external_path))
    if not os.path.commonpath([base_dir, candidate]) == base_dir:
        raise ValueError("External tensor path escapes model directory")
    with open(candidate, "rb") as f:
        return f.read()

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.

Payload

external_data: "../sensitive_data.txt"

Cite this entry

@misc{vaitp:cve202427318,
  title        = {{Directory Traversal vulnerability in onnx versions ≤ 1.15.0 allows file access.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-27318},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-27318/}}
}

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.