{"id":"CVE-2026-54653","published":"2026-07-28T21:48:04Z","modified":"2026-07-29T13:27:46Z","title":"`datamodel-code-generator` vulnerable to code injection in via attacker-controlled `default_factory` schema field","vendor":"koxudaxi","product":"datamodel-code-generator","tier":"tail","description":{"text":"datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. From  0.17.0 until 0.60.2, datamodel-code-generator preserves attacker-controlled default_factory values in src/datamodel_code_generator/parser/jsonschema.py through JsonSchemaObject.init and get_field_extras and emits them into Field(default_factory=...) or field(default_factory=...), allowing Python expression execution when the generated model is imported. This issue is fixed in version 0.60.2.","provenance":"source","from":"CVE.org"},"cvss":{"score":8.8,"severity":"HIGH","version":"3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00711,"percentile":0.5447,"provenance":"source"},"cwes":[{"id":"CWE-94","name":"Improper Control of Generation of Code"},{"id":"CWE-1336","name":"Improper Neutralization of Special Elements Used in a Template Engine"}],"references":[{"url":"https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-386q-5hp3-95m9","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/commit/17fc235e234cbcfaaadef8c74cb72c9687db0d1d","tags":["x_refsource_MISC"]},{"url":"https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2","tags":["x_refsource_MISC"]},{"url":"https://gist.github.com/thegr1ffyn/9648b0fe4fcf7d569ac8e61dd11eebaf","tags":["exploit"]}],"priority":{"score":22.1,"factors":[{"name":"EPSS percentile","points":10.89},{"name":"Public exploit code","points":5.0},{"name":"CVSS severity","points":6.16}]},"vendorSlug":"koxudaxi","affectedVersions":[{"vendor":"koxudaxi","product":"datamodel-code-generator","versions":[">= 0.17.0, < 0.60.2"]}],"ssvc":{"exploitation":"none","automatable":"no","technicalImpact":"total","timestamp":"2026-07-29T13:26:58.871228Z","from":"CISA ADP","provenance":"source"},"affected":[{"ecosystem":"PyPI","package":"datamodel-code-generator","vulnerableRanges":[">=0.17.0, <0.60.2"],"patched":["0.60.2"],"from":["GHSA-386q-5hp3-95m9","PYSEC-2026-3555"],"provenance":"source"}],"summary":{"text":"The flaw is a code injection issue in the datamodel-code-generator product's JSON Schema parser (src/datamodel_code_generator/parser/jsonschema.py), where attacker-controlled default_factory values are preserved and emitted into generated Field(default_factory=...) or field(default_factory=...) code. An attacker who can supply a malicious schema field can achieve Python expression execution when the generated model is imported, with user interaction required to trigger the import.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T06:47:02Z"},"euvd":{"id":"EUVD-2026-50077","exploited":false,"provenance":"source"},"exploitRefs":["https://gist.github.com/thegr1ffyn/9648b0fe4fcf7d569ac8e61dd11eebaf"]}