Code Injection Flaw in datamodel-code-generator Lets Malicious Schemas Poison Generated Models
Vulnerability Disclosure · 4 sources · Updated 3mo ago · First seen Jun 8, 2026

A high-severity code injection vulnerability, CVE-2026-54653, affects datamodel-code-generator versions 0.17.0 through 0.60.1, allowing attacker-controlled JSON Schema input to inject unsafe default_factory values into generated Python models. When a victim later imports the generated code, the embedded Python expression can execute, creating a remotely exploitable path from untrusted schema parsing to code execution. The issue is tracked with CVSS 8.8 and mapped to CWE-94 and CWE-1336.
Project maintainers addressed the flaw in version 0.60.2, which includes fixes for this and other code-injection vectors involving schema-provided default_factory, x-python-type, comment data passed through --extra-template-data, and Pydantic v2 validator definitions supplied via --validators or --extra-template-data. The patch for default_factory now limits accepted values to an allowlist of dict, list, and set, rejecting code-like strings, lambdas, function references, and None; defenders are advised to upgrade to 0.60.2, review previously generated models for unsafe default_factory usage, and avoid importing generated code produced from untrusted schemas until updated.


