Junglewise Threat Intelligence

CVE-2026-54621: koxudaxi datamodel-code-generator code injection in GraphQL Union templates

CVE-2026-54621 · Severity: high · CVSS 7.8 · Published 2026-07-28

Technologies: Koxudaxi Datamodel-Code-Generator. Vendors: Koxudaxi, PyPI.

Executive brief

datamodel-code-generator is a tool used by developers to automatically create Python code from data schemas like GraphQL. A security flaw allows a malicious schema to "break out" of a code comment and inject hidden, unauthorized Python code into the generated files. If a developer or automated system imports this generated code, the hidden malicious commands will execute, potentially leading to a full system compromise or data theft.

Technical details

A code injection vulnerability exists in datamodel-code-generator due to improper neutralization of carriage return (\r) characters in GraphQL Union descriptions. While the Jinja2 templates correctly escaped newline (\n) characters to maintain Python comments, they failed to account for carriage returns, which the Python tokenizer also treats as physical line terminators. An attacker providing a crafted GraphQL schema can use literal \r escapes to terminate a comment early and inject arbitrary Python code at the module level. This code executes immediately upon import of the generated module. The issue is fixed in version 0.60.1 by normalizing all line endings to \n before rendering.

Affected products

  • koxudaxi datamodel-code-generator >= 0.25.0, < 0.60.1

Timeline

  • 2026-06-07: patched: Fix committed to repository
  • 2026-07-28: advisory: NVD and GitHub advisory published

References

Related threats