Junglewise Threat Intelligence

CVE-2026-54655: koxudaxi datamodel-code-generator code injection via x-python-type extension

CVE-2026-54655 · 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 to automatically create Python code from data schemas like OpenAPI or JSON Schema. A security flaw allows a malicious schema to inject hidden Python code into the generated files. If a developer or automated system imports the resulting Python file, the injected code will automatically execute, potentially allowing an attacker to steal data, disrupt operations, or compromise the developer's workstation or CI/CD environment.

Technical details

A code injection vulnerability exists in datamodel-code-generator's JSON Schema parser within the `_get_python_type_override` method. The tool fails to sufficiently validate values provided in the `x-python-type` extension, forwarding them verbatim into generated Python field annotations. An attacker can craft a schema using specific syntax (e.g., using semicolons or brackets) to bypass the single sanitization check and embed arbitrary Python statements. These statements are executed at class-definition time when the generated module is imported. The vulnerability affects multiple output formats including Pydantic models, dataclasses, and TypedDicts. The issue is resolved in version 0.60.2 by implementing AST-based validation of type annotations.

Affected products

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

Timeline

  • 2026-06-08: patched: Fix included in version 0.60.2
  • 2026-07-28: disclosed: CVE-2026-54655 published

References

Related threats