Junglewise Threat Intelligence

CVE-2026-54656: koxudaxi datamodel-code-generator code injection in Pydantic v2 validators

CVE-2026-54656 · 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 OpenAPI or JSON Schema. A security flaw allows an attacker to provide a malicious configuration file that injects hidden Python code into the generated files. If a developer or automated system then imports this generated code, the hidden commands will execute immediately, potentially allowing the attacker to steal data, compromise development environments, or disrupt operations.

Technical details

A code injection vulnerability exists in datamodel-code-generator versions 0.52.1 through 0.60.1 when using the Pydantic v2 output mode. The tool interpolates validator definitions from the --extra-template-data file into @field_validator decorators without proper escaping or validation. Specifically, the _process_validators function in src/datamodel_code_generator/model/pydantic_v2/base_model.py wraps field names and validator modes in unescaped single quotes. An attacker can use a single quote to break out of the string literal and inject arbitrary Python expressions. These expressions are executed at class-definition time when the generated module is imported. The issue is fixed in version 0.60.2 by implementing strict validation of validator entries and using repr() for rendering.

Affected products

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

Timeline

  • 2026-06-08: patched: Fixed in version 0.60.2
  • 2026-07-28: disclosed: Advisory published via GitHub and NVD

References

Related threats