CVE-2026-54621: `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in GraphQL Union 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.
Security readout for executives and security teams
Plain-English summary
A malicious GraphQL schema can turn generated model code into a delivery path for attacker-controlled Python. The injected code executes only when someone generates models from the crafted schema and later imports them, but successful exploitation could compromise confidentiality, integrity, and availability.
Executive priority
Prioritize remediation for build systems accepting partner, customer, repository, or internet-sourced GraphQL schemas. Upgrade promptly and examine previously generated artifacts. Lower urgency is reasonable only after confirming affected versions are absent or schema inputs are fully trusted.
Technical view
Versions 0.25.0 through 0.60.0 fail to neutralize carriage returns in GraphQL Union descriptions rendered into Python comments. A carriage return can escape the intended comment context and inject Python into generated models. Importing the generated module executes that code. Version 0.60.1 fixes both affected UnionTypeStatement templates.
Likely exposure
Exposure is most likely in development, CI/CD, or automation workflows using affected versions to process GraphQL schemas from untrusted or externally influenced sources. Systems that neither generate from GraphQL schemas nor import resulting models are unlikely to reach the vulnerable execution path.
Exploitation context
Exploitation requires attacker-controlled GraphQL Union description content, model generation, and subsequent import of the generated Python. User or workflow interaction is therefore required. The supplied record is not in KEV, and the provided sources do not establish active exploitation.
Researcher notes
The affected range is 0.25.0 through 0.60.0. The weakness is template-context code injection involving carriage returns inside Python comment output, mapped to CWE-1336 and CWE-94. Evidence supports arbitrary Python execution upon import, but the bundle provides no evidence of exploitation in the wild.
Mitigation direction
Upgrade datamodel-code-generator to version 0.60.1 or later.
Restrict schema inputs to trusted, authenticated sources until upgrading.
Regenerate affected models with the fixed version before importing or deploying them.
Review previously generated Python before continued use where schema provenance is uncertain.
Validation and detection
Inventory installed and CI-pinned datamodel-code-generator versions.
Identify workflows that generate Python models from GraphQL schemas.
Verify whether external parties can influence GraphQL Union descriptions.
Confirm regenerated models use version 0.60.1 or later.
Review historical generated files and build artifacts from untrusted schemas.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cwe · low confidence lookup
CWE-1336: Exact CWE lookup
Use the exact CWE identifier as the starting point before reviewing related ATT&CK behavior. Open the exact CWE lookup page first, then review the ATT&CK searches from that MITRE weakness context. This is a Glexia lookup hint, not an official ATT&CK mapping.
Code execution and unsafe deserialization weaknesses often justify reviewing execution behavior and process telemetry. Open the exact CWE lookup page first, then review the ATT&CK searches from that MITRE weakness context. This is a Glexia lookup hint, not an official ATT&CK mapping.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.
1CVSS vectors
3Timeline events
1ADP providers
4Source links
SSVC decision data
CISA-ADPCISA Coordinator
Timestamp
Version
2.0.3
Exploitation: noneAutomatable: noTechnical Impact: total
CVSS vector scores
1 official score
We collect every scored CVSS vector available in the official CNA and ADP containers. When more than one version is present, the table keeps the source vectors side by side instead of collapsing them into the highest score.
CWE links open Glexia weakness intelligence pages with official CWE context, developer remediation guidance, and related CVE mappings.
CWE-1336 · source CWE mapping
Improper Neutralization of Special Elements Used in a Template Engine
Improper Neutralization of Special Elements Used in a Template Engine represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.
Improper Control of Generation of Code ('Code Injection')
Improper Control of Generation of Code ('Code Injection') represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.