`datamodel-code-generator` vulnerable to code injection in via attacker-controlled `default_factory` schema field
Summary
| CVE | CVE-2026-54653 |
|---|---|
| State | PUBLISHED |
| Assigner | GitHub_M |
| Source Priority | CVE Program / NVD first with legacy fallback |
| Published | 2026-07-28 22:17:40 UTC |
| Updated | 2026-07-30 19:07:59 UTC |
| Description | 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. |
Risk And Classification
Primary CVSS: v3.1 8.8 HIGH from [email protected]
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
EPSS: 0.003490000 probability, percentile 0.276380000 (date 2026-08-01)
Problem Types: CWE-94 | CWE-1336 | CWE-94 CWE-94: Improper Control of Generation of Code ('Code Injection') | CWE-1336 CWE-1336: Improper Neutralization of Special Elements Used in a Template Engine
| Version | Source | Type | Score | Severity | Vector |
|---|---|---|---|---|---|
| 3.1 | [email protected] | Secondary | 8.8 | HIGH | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
| 3.1 | CNA | DECLARED | 8.8 | HIGH | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
CVSS v3.1 Breakdown
Attack Vector
NetworkAttack Complexity
LowPrivileges Required
NoneUser Interaction
RequiredScope
UnchangedConfidentiality
HighIntegrity
HighAvailability
HighCVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
Vendor Declared Affected Products
| Source | Vendor | Product | Version | Platforms |
|---|---|---|---|---|
| CNA | Koxudaxi | Datamodel-code-generator | affected >= 0.17.0, < 0.60.2 | Not specified |
References
| Reference | Source | Link | Tags |
|---|---|---|---|
| gist.github.com/thegr1ffyn/9648b0fe4fcf7d569ac8e61dd11eebaf | 134c704f-9b21-4f2e-91b3-4a467353bcc0 | gist.github.com | |
| github.com/koxudaxi/datamodel-code-generator/commit/17fc235e234cbcfaaade... | [email protected] | github.com | |
| github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-38... | [email protected] | github.com | |
| github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2 | [email protected] | github.com | |
| CVE Program record | CVE.ORG | www.cve.org | canonical |
| NVD vulnerability detail | NVD | nvd.nist.gov | canonical, analysis |
No vendor comments have been submitted for this CVE.
There are currently no legacy QID mappings associated with this CVE.