Skip to main content
Vulnerability Database/CVE-2026-107377

CVE-2026-107377: datamodel-code-generator Path Traversal

CVE-2026-107377 is a path traversal flaw in datamodel-code-generator that allows attackers to write files outside intended directories. This post explains its impact, affected versions, and mitigation steps.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-107377 Overview

CVE-2026-107377 is a path traversal vulnerability [CWE-22] in datamodel-code-generator, a Python library that generates data models from schema definitions. Versions 0.59.0 through 0.80.x contain a flaw in the Protobuf parser where attacker-controlled schemas can supply absolute or parent-directory paths. These paths are captured by WEAK_IMPORT_PATTERN and consumed by _write_missing_weak_imports in src/datamodel_code_generator/parser/protobuf.py. The paths escape the weak_imports temporary directory before protoc runs, allowing creation of directory trees and new files, or overwriting of existing writable files. The issue is fixed in version 0.81.0.

Critical Impact

An attacker-controlled Protobuf schema can write arbitrary files containing a proto2 or proto3 syntax declaration to any location writable by the victim process, persisting even when later Protobuf compilation fails.

Affected Products

  • datamodel-code-generator versions 0.59.0 through 0.80.x
  • Deployments using Protobuf input support (requires grpcio-tools package)
  • Automated pipelines or jobs processing third-party Protobuf schemas

Discovery Timeline

  • 2026-10-08 - CVE CVE-2026-107377 published to NVD
  • 2026-10-14 - Last updated in NVD database

Technical Details for CVE-2026-107377

Vulnerability Analysis

The vulnerability resides in the Protobuf parser context manager used to stage schema files before invoking protoc. During setup, the parser scans input .proto files for weak imports using a regular expression (WEAK_IMPORT_PATTERN). Matched import strings are then passed to _write_missing_weak_imports, which joins them with the __weak_imports__ temporary directory and writes a placeholder file containing only a syntax declaration.

Because the extracted path is not validated against the temporary directory boundary, an attacker can supply values such as /etc/cron.d/payload or ../../../home/user/.bashrc inside a crafted Protobuf schema. The write operation creates missing parent directories and overwrites any file that the running process can write. The side effect persists across the pipeline even if protoc later rejects the schema, because files are written before compilation.

Root Cause

The root cause is missing path containment validation on attacker-controlled import names consumed by _write_missing_weak_imports. The function treats the import string as a trusted relative path when joining it with the weak-imports staging directory.

Attack Vector

Exploitation requires a victim or automated job to process an attacker-supplied .proto schema with Protobuf input support enabled. The schema embeds a weak import statement containing an absolute or parent-directory path. When the parser stages weak imports, the file is written outside the sandbox. The written content is constrained to a syntax declaration, so direct arbitrary code execution has not been demonstrated, but file overwrite can tamper with build artifacts, scripts, or configuration files.

python
# Patch excerpt from src/datamodel_code_generator/parser/protobuf.py
def __enter__(self) -> tuple[list[Path], list[Path], frozenset[str]]:
    self.temp_dir = tempfile.TemporaryDirectory()
    try:
        temp_path = Path(self.temp_dir.name)
        include_paths = [temp_path, self.parser.base_path]
        input_files = self._input_files(temp_path)
        input_file_names = frozenset(
            path.relative_to(temp_path).as_posix() for path in input_files
        )
        include_paths.extend(self._additional_include_paths(input_files))
        self.weak_import_dir = temp_path / "__weak_imports__"
        self._write_missing_weak_imports(input_files, include_paths)
        if self.weak_import_dir.exists():
            include_paths.append(self.weak_import_dir)
    except Exception:
        self.temp_dir.cleanup()
        raise
    else:
        return input_files, include_paths, input_file_names

Source: GitHub Commit 5e94b8f. The patch ensures the temporary directory is cleaned up on failure. Additional containment logic in release 0.81.0 constrains weak-import paths to the staging directory.

Detection Methods for CVE-2026-107377

Indicators of Compromise

  • Unexpected files containing only a bare syntax = "proto2"; or syntax = "proto3"; line appearing outside build directories.
  • New directory trees created by the user account running code-generation jobs in paths such as /etc/, ~/.ssh/, or CI workspace roots.
  • datamodel-codegen invocations against third-party or untrusted .proto input in build logs.

Detection Strategies

  • Inventory Python environments for datamodel-code-generator versions >=0.59.0,<0.81.0 with grpcio-tools installed.
  • Scan .proto schemas processed by CI/CD pipelines for import weak statements containing .. sequences or absolute paths.
  • Enable filesystem auditing on build agents to flag write operations outside expected workspace paths by the code generator process.

Monitoring Recommendations

  • Log all invocations of datamodel-codegen with their --input arguments and source origin.
  • Alert on file creation events in sensitive directories initiated by Python interpreters running inside CI runners.
  • Review package manifests (requirements.txt, pyproject.toml, poetry.lock) in version control for vulnerable version pins.

How to Mitigate CVE-2026-107377

Immediate Actions Required

  • Upgrade datamodel-code-generator to version 0.81.0 or later across all environments.
  • Audit CI/CD pipelines that consume externally sourced Protobuf schemas and quarantine untrusted inputs.
  • Review build hosts for unexpected files or directories matching the IoC patterns above.

Patch Information

The fix is included in datamodel-code-generator 0.81.0. Details are published in GitHub Security Advisory GHSA-77xj-x4rm-935c. The code change is tracked in commit 5e94b8f.

Workarounds

  • Only process Protobuf schemas from trusted sources until the upgrade is applied.
  • Run datamodel-codegen under a least-privilege user account with a restricted writable filesystem scope.
  • Execute code-generation jobs inside ephemeral containers with read-only mounts for host-sensitive paths.
bash
# Upgrade to the patched release
pip install --upgrade 'datamodel-code-generator>=0.81.0'

# Verify the installed version
python -c "import datamodel_code_generator; print(datamodel_code_generator.__version__)"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.