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

CVE-2026-55415: datamodel-code-generator RCE Vulnerability

CVE-2026-55415 is a remote code execution flaw in datamodel-code-generator allowing attackers to inject Python code through schema extensions. This post covers technical details, affected versions, impact, and mitigation.

Published:

CVE-2026-55415 Overview

CVE-2026-55415 is a code injection vulnerability [CWE-94] in datamodel-code-generator, a Python tool that generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from schema formats including OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, JSON, YAML, and CSV. Versions from 0.11.6 up to but not including 0.64.0 accept attacker-controlled x-python-import or customTypePath schema extensions. These values flow into generated import statements without validation, enabling newline injection that executes arbitrary Python code when the generated model is imported. The maintainer released a fix in version 0.64.0.

Critical Impact

Attacker-controlled schema input can inject arbitrary Python code into generated modules, resulting in code execution on any host that imports the generated models.

Affected Products

  • datamodel-code-generator versions 0.11.6 through 0.63.x
  • Python projects that generate models from untrusted OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, JSON, YAML, or CSV input
  • CI/CD pipelines and build systems that invoke datamodel-code-generator on externally supplied schemas

Discovery Timeline

  • 2026-07-28 - CVE-2026-55415 published to NVD
  • 2026-07-29 - Last updated in NVD database

Technical Details for CVE-2026-55415

Vulnerability Analysis

The vulnerability arises because datamodel-code-generator treats specific schema extension keys as trusted import specifiers. When a schema contains x-python-import or customTypePath, the parser at src/datamodel_code_generator/parser/jsonschema.py forwards the value into the import generation logic at src/datamodel_code_generator/imports.py. Both Import.from_full_path and Imports.create_line write the value directly into generated Python source without validating that it is a well-formed dotted identifier path. Attackers exploit this by embedding a newline character in the extension value. The newline terminates the synthetic import line and allows arbitrary Python statements to follow. Because the payload lands in the generated module body, it executes the first time any consumer imports the produced code, which typically occurs in a development, build, or runtime environment with broad privileges.

Root Cause

The root cause is missing input validation on schema extension values used for symbol resolution. The generator concatenates untrusted strings into Python source and does not confirm that the value matches a dotted-identifier grammar before emission. The 0.64.0 patch introduces _validate_dotted_python_identifier_path in datamodel_code_generator.validators and calls it before import lines are written.

Attack Vector

Exploitation requires an attacker to supply or influence a schema that is processed by datamodel-code-generator. Common vectors include public API definitions consumed by client-generation pipelines, third-party schema registries, pull requests that modify schema files, and services that accept user-supplied OpenAPI or JSON Schema documents. Successful exploitation yields Python code execution in the context of whichever process imports the generated model, often a build agent, test runner, or application server.

python
# Source: https://github.com/koxudaxi/datamodel-code-generator/commit/577d49569c2254c371a97e495020ae2238a73b84
     is_python_type_annotation,
 )
 from datamodel_code_generator.util import BaseModel
+from datamodel_code_generator.validators import _validate_dotted_python_identifier_path
 
 if TYPE_CHECKING:
     from collections.abc import Callable, Generator, Iterable, Iterator, Sequence

The patch wires the new _validate_dotted_python_identifier_path validator into jsonschema.py, rejecting extension values that are not strict dotted Python identifier paths.

Detection Methods for CVE-2026-55415

Indicators of Compromise

  • Schema files containing x-python-import or customTypePath values that include newline characters, semicolons, or Python keywords such as import, exec, os.system, or __import__.
  • Generated Python modules where an import line is followed by unexpected top-level statements or shell-invoking calls.
  • Build agents that spawn python, sh, or network client processes immediately after importing generated model modules.

Detection Strategies

  • Scan repository schemas for the strings x-python-import and customTypePath and flag any value that fails a strict dotted-identifier regex such as ^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$.
  • Run static analysis (for example, bandit or semgrep) over generated output directories to identify unexpected top-level executable statements in files that should only contain model definitions.
  • Diff generated modules across builds and alert when import blocks change shape or gain trailing code.

Monitoring Recommendations

  • Log all invocations of datamodel-codegen in CI/CD, capturing the source schema hash and installed package version.
  • Alert on outbound network connections from build agents originating from Python processes that import generated model packages.
  • Track installed versions of datamodel-code-generator across developer workstations and pipelines to identify hosts still running 0.11.6 through 0.63.x.

How to Mitigate CVE-2026-55415

Immediate Actions Required

  • Upgrade datamodel-code-generator to version 0.64.0 or later in every environment that runs the tool.
  • Regenerate all previously produced models from trusted schemas and diff the output to detect prior injection.
  • Treat any schema fetched from an external or untrusted source as tainted until it has been reviewed for x-python-import and customTypePath misuse.

Patch Information

The fix is included in datamodel-code-generator 0.64.0. The remediation adds _validate_dotted_python_identifier_path and enforces it on extension-derived import paths in both parser/jsonschema.py and imports.py. Details are available in the GitHub Security Advisory GHSA-5578-w22f-pfx9, the fix commit, and the 0.64.0 release notes.

Workarounds

  • Preprocess input schemas to strip x-python-import and customTypePath fields before invoking the generator.
  • Run datamodel-codegen inside an isolated container or sandbox with no network access and no credentials to limit blast radius.
  • Require code review on all generated model files and block merges that introduce non-import statements at module top level.
bash
# Pin a fixed version in requirements.txt or pyproject.toml
pip install --upgrade 'datamodel-code-generator>=0.64.0'

# Optional: strip risky extensions from schemas before generation
python -c "import json,sys,re;\
s=json.load(open(sys.argv[1]));\
def clean(o):\
  if isinstance(o,dict):\
    o.pop('x-python-import',None); o.pop('customTypePath',None);\
    [clean(v) for v in o.values()]\
  elif isinstance(o,list):\
    [clean(v) for v in o]\
clean(s); json.dump(s,open(sys.argv[1],'w'))" schema.json

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

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

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.