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

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.

Technologies: Koxudaxi Datamodel-Code-Generator, datamodel-code-generator (PyPI). Vendors: Koxudaxi, PyPI.

Quick answers

Is CVE-2026-54621 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-54621 being exploited in the wild.
How severe is CVE-2026-54621?
High severity, with a CVSS score of 7.8, published 28 July 2026.
Which products and versions are affected?
Koxudaxi Datamodel-Code-Generator >= 0.25.0, < 0.60.1; datamodel-code-generator (PyPI) ECOSYSTEM:introduced=0.25.0,fixed=0.60.1.
Is there a fix for CVE-2026-54621?
Yes. datamodel-code-generator (PyPI): upgrade to 0.60.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-54621 attacked?
It is attacked with local access, in a software library.
Am I affected by CVE-2026-54621?
Check whether you run Koxudaxi Datamodel-Code-Generator or datamodel-code-generator (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • datamodel-code-generator (PyPI): upgrade to 0.60.1 or later
    pip install "datamodel-code-generator>=0.60.1"

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

Identifiers

  • CVE-2026-54621
  • GHSA-j884-q54q-mmx3
  • PYSEC-2026-3561

Timeline

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

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.