VAITP Dataset

← Back to the dataset

CVE-2026-107377

Path traversal in Protobuf schema allows file creation/overwrite (weak_imports).

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

datamodel-code-generator generates Python data models from schema definitions. From 0.59.0 until 0.81.0, an attacker-controlled Protobuf schema can supply absolute or parent-directory paths captured by WEAK_IMPORT_PATTERN and consumed by _write_missing_weak_imports in src/datamodel_code_generator/parser/protobuf.py. Exploitation requires a victim or automated job to process the attacker-controlled schema with Protobuf input support, which requires the grpcio-tools package. The paths escape the weak_imports temporary directory before protoc runs, allowing creation of directory trees and new files or overwrite of existing writable files with a generated Protobuf syntax declaration. The effect persists when later Protobuf compilation fails. The written content is limited to a proto2 or proto3 syntax declaration, and direct arbitrary code execution has not been demonstrated. This issue is fixed in version 0.81.0.

CVSS base score
7.5
Published
2026-10-08
OWASP
A04 Insecure Design
Orthogonal defect classification
Assignment
Code defect classification
Missing Check
Category
Input Validation and Sanitization
Subcategory
Path Traversal
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
datamodel-code-generator
Fixed by upgrading
Yes

Solution

Upgrade datamodel-code-generator to version 0.81.0 or newer.

Vulnerable code sample

import os
import tempfile

def _write_missing_weak_imports(imports):
    """
    Write placeholder proto files for missing imports into a temporary
    directory used by the protobuf compiler.
    """
    weak_dir = tempfile.mkdtemp(prefix="weak_imports_")
    for imp in imports:
        # VULNERABLE: path traversal via unvalidated import path
        dest_path = os.path.join(weak_dir, imp)  # may contain '../../evil.proto'
        os.makedirs(os.path.dirname(dest_path), exist_ok=True)
        with open(dest_path, "w", encoding="utf-8") as f:
            f.write("syntax = \"proto3\";")
    return weak_dir

Patched code sample

import os
import tempfile

def _write_missing_weak_imports(imports):
    """
    Write placeholder proto files for missing imports into a temporary
    directory used by the protobuf compiler.
    """
    weak_dir = tempfile.mkdtemp(prefix="weak_imports_")
    for imp in imports:
        # FIX: sanitize path to prevent escaping the temporary directory
        safe_rel = os.path.normpath(imp).lstrip(os.sep)
        dest_path = os.path.join(weak_dir, safe_rel)
        # Ensure the resolved path is still inside weak_dir
        if not os.path.commonpath([weak_dir, dest_path]) == weak_dir:
            continue  # skip unsafe paths
        os.makedirs(os.path.dirname(dest_path), exist_ok=True)
        with open(dest_path, "w", encoding="utf-8") as f:
            f.write("syntax = \"proto3\";")
    return weak_dir

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.

  • Merge commit from fork (datamodel-code-generator/datamodel-code-generator)
    src/datamodel_code_generator/parser/protobuf.py · _ProtoInputPreparer._write_missing_weak_imports, src/datamodel_code_generator/parser/protobuf.py · _ProtoInputPreparer.__enter__

Cite this entry

@misc{vaitp:cve2026107377,
  title        = {{Path traversal in Protobuf schema allows file creation/overwrite (weak_imports).}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-107377},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-107377/}}
}

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.