Description
datamodel-code-generator generates Python data models from schema definitions. Prior to 0.60.1, GraphQL Union description values in src/datamodel_code_generator/model/template/UnionTypeStatement.jinja2 and src/datamodel_code_generator/model/template/UnionTypeStatement.py312.jinja2 are rendered into Python comments without neutralizing carriage returns in Python # comments, allowing attacker-controlled GraphQL schema content to inject Python code into generated models that runs when imported. This issue is fixed in version 0.60.1.
Published: 2026-07-28
Score: 7.8 High
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

The flaw allows an attacker to inject Python code into generated data‑model files by inserting a carriage return in a GraphQL Union type description. The generator places the description directly into Python comments without neutralizing control characters, so a crafted schema can cause the generated model to execute malicious code when it is imported.

Affected Systems

The vulnerability exists in koxudaxi's datamodel‑code‑generator in all releases prior to version 0.60.1; any instance of the tool that processes untrusted GraphQL schemas and then imports the generated models is susceptible.

Risk and Exploitability

With a CVSS score of 7.8 the risk is moderate to high. The EPSS < 1% indicates that active exploitation is currently rare, and the issue is not listed in the CISA KEV catalog. Exploitation requires the attacker to supply a malicious schema to the generator and subsequently execute the resulting Python module, typically within a build or deployment pipeline. If achieved, an attacker can run arbitrary code with the permissions of the executing process.

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

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade datamodel-code-generator to version 0.60.1 or later, which neutralizes carriage returns in GraphQL Union descriptions.
  • Change the workflow so that only schemas from trusted, internal sources are fed to the generator, preventing external manipulation of the description field.
  • Implement a code review or automated static‑analysis step to detect injected code in the generated Python modules before deployment or import.

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

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-j884-q54q-mmx3 `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in GraphQL Union description
History

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

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', '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. Prior to 0.60.1, GraphQL Union description values in src/datamodel_code_generator/model/template/UnionTypeStatement.jinja2 and src/datamodel_code_generator/model/template/UnionTypeStatement.py312.jinja2 are rendered into Python comments without neutralizing carriage returns in Python # comments, allowing attacker-controlled GraphQL schema content to inject Python code into generated models that runs when imported. This issue is fixed in version 0.60.1.
Title `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in GraphQL Union description
Weaknesses CWE-1336
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:34:35.056Z

Reserved: 2026-06-15T20:07:02.184Z

Link: CVE-2026-54621

cve-icon Vulnrichment

Updated: 2026-07-29T12:34:31.575Z

cve-icon NVD

Status : Deferred

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

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

Link: CVE-2026-54621

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

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

Weaknesses
  • CWE-1336

    Improper Neutralization of Special Elements Used in a Template Engine

  • CWE-94

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