Description
datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. From 0.11.6 until 0.64.0, datamodel-code-generator allows attacker-controlled x-python-import or customTypePath schema extensions to reach src/datamodel_code_generator/parser/jsonschema.py and generated import handling through Import.from_full_path and Imports.create_line in src/datamodel_code_generator/imports.py, allowing a newline to break out of an import statement and execute Python code when the generated model is imported. This issue is fixed in version 0.64.0.
Published: 2026-07-28
Score: 7.5 High
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

datamodel-code-generator, used to generate Pydantic v2 models and related structures from various schema formats, contains a code injection flaw. Attackers can embed malicious import parameters via the schema extensions x-python-import or customTypePath. Those extensions are passed to Import.from_full_path and Imports.create_line, where a newline in the value can break out of the generated import statement and execute arbitrary Python code when the resulting module is imported. The flaw permits remote code execution.

Affected Systems

The koxudaxi datamodel-code-generator is vulnerable in all releases starting from 0.11.6 up to, but not including, 0.64.0. Any environment that runs the generator with any of these versions on input containing untrusted x‑python‑import or customTypePath schema extensions and then imports the generated modules is affected. The issue was fixed in release 0.64.0.

Risk and Exploitability

The CVSS score of 7.5 marks the flaw as high severity, while an EPSS score below 1% indicates a low but non‑zero likelihood of exploitation. It is not listed in CISA KEV. Exploitation requires an attacker to supply a malicious schema to the generator, which writes the generated file; execution is only achieved when the file is imported or run by the downstream application. Based on the description, the attack vector is inferred to be local to the code generation process, but the impact of the executed payload can be arbitrary code run with the privileges of the importing process.

Generated by OpenCVE AI on August 4, 2026 at 23:26 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade datamodel-code-generator to version 0.64.0 or later.
  • Before running the generator, sanitize or remove any x‑python‑import or customTypePath extensions from the input schema, or ensure they come from a trusted source.
  • Review and audit the generated Python code before importing or executing it in production environments, keeping the import paths under strict control.

Generated by OpenCVE AI on August 4, 2026 at 23:26 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-5578-w22f-pfx9 datamodel-code-generator vulnerable to code injection via `x-python-import` / `customTypePath` in generated import statements
History

Wed, 29 Jul 2026 14:30:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'poc', 'Technical Impact': 'total'}, 'version': '2.0.3'}


Tue, 28 Jul 2026 23:45:00 +0000

Type Values Removed Values Added
First Time appeared Koxudaxi
Koxudaxi datamodel-code-generator
Vendors & Products Koxudaxi
Koxudaxi datamodel-code-generator

Tue, 28 Jul 2026 22:00:00 +0000

Type Values Removed Values Added
Description datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. From 0.11.6 until 0.64.0, datamodel-code-generator allows attacker-controlled x-python-import or customTypePath schema extensions to reach src/datamodel_code_generator/parser/jsonschema.py and generated import handling through Import.from_full_path and Imports.create_line in src/datamodel_code_generator/imports.py, allowing a newline to break out of an import statement and execute Python code when the generated model is imported. This issue is fixed in version 0.64.0.
Title datamodel-code-generator vulnerable to code injection via `x-python-import` / `customTypePath` in generated import statements
Weaknesses CWE-94
CWE-95
References
Metrics cvssV3_1

{'score': 7.5, 'vector': 'CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H'}


Subscriptions

Koxudaxi Datamodel-code-generator
cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-07-29T14:06:25.028Z

Reserved: 2026-06-16T21:48:43.125Z

Link: CVE-2026-55415

cve-icon Vulnrichment

Updated: 2026-07-29T14:05:34.491Z

cve-icon NVD

Status : Analyzed

Published: 2026-07-28T22:17:48.983

Modified: 2026-08-06T19:42:57.190

Link: CVE-2026-55415

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-08-04T23:30:15Z

Weaknesses
  • CWE-94

    Improper Control of Generation of Code ('Code Injection')

  • CWE-95

    Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')