Junglewise Threat Intelligence

CVE-2026-54653: koxudaxi datamodel-code-generator code injection via default_factory field

CVE-2026-54653 · Severity: high · CVSS 8.8 · Published 2026-07-28

Technologies: Koxudaxi Datamodel-Code-Generator, datamodel-code-generator (PyPI). 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 a malicious schema to inject hidden Python code into the generated files. If a developer or automated system generates code from an untrusted schema and then imports that code, the attacker's hidden commands will execute immediately, potentially leading to data theft, system compromise, or unauthorized access to the development environment.

Technical details

The vulnerability is a code injection flaw (CWE-94/CWE-1336) residing in the JSON Schema parser component. The generator preserves attacker-controlled 'default_factory' values from input schemas (OpenAPI, JSON Schema, etc.) and interpolates them verbatim into the generated Python code's Field() or field() arguments without proper sanitization or escaping. Because these assignments are evaluated at class-definition time, the injected Python expressions execute automatically when the resulting module is imported. The attack requires the victim to run the generator against a malicious schema and subsequently import the output. This affects Pydantic v2, dataclass, and msgspec output types. The issue is fixed in version 0.60.2 by restricting 'default_factory' values to a safe allowlist (dict, list, set).

Affected products

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

Timeline

  • 2026-06-08: patched: Fixed in version 0.60.2
  • 2026-06-08: advisory: GitHub Security Advisory GHSA-386q-5hp3-95m9 published
  • 2026-07-28: disclosed: CVE-2026-54653 published to NVD

References

Related threats