Description
datamodel-code-generator generates Python data models from schema definitions. From 0.51.0 until 0.60.2, x-python-type values parsed by src/datamodel_code_generator/parser/jsonschema.py in _get_python_type_override are inserted into generated field annotations without sufficient validation, allowing attacker-controlled JSON Schema content to execute Python code when the generated module is imported. This issue is fixed in version 0.60.2.
Published: 2026-07-28
Score: 7.8 High
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

The vulnerability allows an attacker to inject Python code through the x‑python‑type JSON‑Schema extension. When datamodel‑code‑generator parses the schema, the unchecked value is inserted into generated field annotations, causing arbitrary code to run when the resulting module is imported. This flaw maps to CWE‑94: Improper Control of Generation of Code via Dynamic Code Generation. The effect is the execution of attacker‑controlled code in the context of the process that imports the generated file, potentially leading to full system compromise if the generator is used in production services.

Affected Systems

The affected product is datamodel‑code‑generator from koxudaxi. Vulnerability is present in versions 0.51.0 through 0.60.1. Version 0.60.2 and later include the fix.

Risk and Exploitability

The CVSS score of 7.8 indicates high severity, while the EPSS score of less than 1% suggests a low probability of exploitation at this time. The vulnerability is not listed in the CISA KEV catalog. Exploitation requires the attacker to supply a malicious JSON Schema that includes a controlled x‑python‑type value, meaning the attack vector is local or occurs within a trusted environment where the generator is used. The flaw exists in versions from 0.51.0 through 0.60.1; it is fixed in 0.60.2. If the generator is used in an automated or production pipeline, an attacker who can modify the schema—such as through a repository commit, continuous integration pipeline, or an API that accepts user‑supplied schemas—can trigger code execution when the generated module is imported. Given the high impact and moderate likelihood when the generator is part of a deployment pipeline, systems using datamodel‑code‑generator in automated or production contexts should treat this as a critical risk.

Generated by OpenCVE AI on August 3, 2026 at 14:12 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade datamodel‑code‑generator to 0.60.2 or later, which validates and rejects malicious x‑python‑type values.
  • If an upgrade is not immediately possible, avoid using the x‑python‑type extension in all JSON Schema documents fed to the generator or implement a pre‑flight validation step that strips or sanitizes untrusted extension values.
  • Review any previously generated modules for hard‑coded imports or suspicious type annotations and refactor them to use safe, static types.

Generated by OpenCVE AI on August 3, 2026 at 14:12 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-m34r-v34r-rf9q `datamodel-code-generator` vulnerable to code execution on import via `x-python-type` JSON-Schema extension in datamodel-code-generator
History

Wed, 29 Jul 2026 13: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 Python data models from schema definitions. From 0.51.0 until 0.60.2, x-python-type values parsed by src/datamodel_code_generator/parser/jsonschema.py in _get_python_type_override are inserted into generated field annotations without sufficient validation, allowing attacker-controlled JSON Schema content to execute Python code when the generated module is imported. This issue is fixed in version 0.60.2.
Title `datamodel-code-generator` vulnerable to code execution on import via `x-python-type` JSON-Schema extension in datamodel-code-generator
Weaknesses CWE-94
References
Metrics cvssV3_1

{'score': 7.8, 'vector': 'CVSS:3.1/AV:L/AC:L/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-29T12:47:08.130Z

Reserved: 2026-06-15T20:16:46.199Z

Link: CVE-2026-54655

cve-icon Vulnrichment

Updated: 2026-07-29T12:47:04.681Z

cve-icon NVD

Status : Deferred

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

Modified: 2026-07-30T20:02:12.943

Link: CVE-2026-54655

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-08-03T14:15:05Z

Weaknesses
  • CWE-94

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