CVE-2026-54653: `datamodel-code-generator` vulnerable to code injection in via attacker-controlled `default_factory` schema field
datamodel-code-generator is vulnerable to code injection when generating Python models from an attacker-controlled JSON Schema, OpenAPI, YAML, JSON, Avro, Protobuf, or XSD schema. When a property carries a "default_factory" key, its value is interpolated verbatim — as a raw Python expression — into the generated Field(default_factory=...) / field(default_factory=...) call. Because this assignment is evaluated at class-definition time (i.e. on import of the generated module), an attacker who controls the schema controls a Python expression that runs in the consumer’s process. No special CLI flags are required.
References
- github.com/advisories/GHSA-386q-5hp3-95m9
- github.com/koxudaxi/datamodel-code-generator/commit/17fc235e234cbcfaaadef8c74cb72c9687db0d1d
- github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2
- github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-386q-5hp3-95m9
- nvd.nist.gov/vuln/detail/CVE-2026-54653
Code Behaviors & Features
Detect and mitigate CVE-2026-54653 with GitLab Dependency Scanning
Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Dependency Scanning using SBOM also detects vulnerabilities from proprietary advisories that this site does not include. Learn more about Dependency Scanning using SBOM →