CVE-2026-54654: koxudaxi datamodel-code-generator code injection in --extra-template-data

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

datamodel-code-generator is a tool used by developers to automatically create Python data models from schema definitions. A security flaw allows an attacker to inject malicious code into these generated files if they can influence the 'comment' field in the configuration data. If a developer or automated system imports the resulting Python file, the injected code 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-54654 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-54654 being exploited in the wild.
How severe is CVE-2026-54654?
High severity, with a CVSS score of 7.8, published 28 July 2026.
Which products and versions are affected?
Koxudaxi Datamodel-Code-Generator >= 0.14.1, < 0.60.2, >= 0.14.1, <= 0.60.1; datamodel-code-generator (PyPI) ECOSYSTEM:introduced=0.14.1,fixed=0.60.2.
Is there a fix for CVE-2026-54654?
Yes. datamodel-code-generator (PyPI): upgrade to 0.60.2 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-54654 attacked?
It is attacked with local access, in a software library.
Am I affected by CVE-2026-54654?
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.2 or later
    pip install "datamodel-code-generator>=0.60.2"

Technical details

A code injection vulnerability exists in datamodel-code-generator versions 0.14.1 through 0.60.1. The tool fails to neutralize carriage returns (\r), vertical tabs (\v), or form feeds (\f) within the 'comment' field provided via the --extra-template-data flag. Because the Python tokenizer treats a bare carriage return as a physical line terminator, an attacker can terminate a Python comment prematurely and inject arbitrary statements that are subsequently executed when the generated module is imported. The vulnerability affects multiple Jinja2 templates, including those for Pydantic models, dataclasses, and TypedDicts. This issue is resolved in version 0.60.2 by implementing a sanitization function that normalizes line terminators and ensures continuation lines are properly prefixed with comment characters.

Affected products

  • koxudaxi datamodel-code-generator >= 0.14.1, < 0.60.2

Identifiers

  • CVE-2026-54654
  • GHSA-wjv6-jcfj-mf9r
  • PYSEC-2026-3566

Timeline

  • 2026-06-08: patched: Fix committed and version 0.60.2 released.
  • 2026-07-28: disclosed: Public advisory published.

References

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