Junglewise Threat Intelligence

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

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

Executive brief

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.

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

Timeline

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

References

Related threats