CVE-2026-54653
PoC largeArbitrary code execution via crafted default_factory in datamodel-code-generator
datamodel-code-generator versions 0.17.0 through before 0.60.2 preserve attacker-controlled default_factory values from schema inputs (via JsonSchemaObject.init and get_field_extras in the jsonschema.py parser, which handles OpenAPI and JSON Schema-style inputs) and emit them unsanitized into Field(default_factory=...) or field(default_factory=...) calls in the generated Python source (CWE-94/CWE-1336). An attacker who can influence the schema fed to the generator can plant a Python expression that executes when a developer imports the generated model, matching the user-interaction requirement in the CVSS 3.1 vector (AV:N/AC:L/PR:N/UI:R). Successful exploitation yields arbitrary code execution in the process importing the generated code, with high impact on confidentiality, integrity, and availability (CVSS 3.1 score 8.8, High). Anyone generating Pydantic v2 models, dataclasses, TypedDict, or msgspec.Struct with an affected version and importing output derived from attacker-influenced or untrusted schemas is affected; exploitation is not currently known to be occurring in the wild (EPSS 0.4%, not in CISA KEV). A public advisory with a proof-of-concept reference exists (GHSA-386q-5hp3-95m9), and the issue is fixed in version 0.60.2.
What to do: Upgrade datamodel-code-generator to 0.60.2 or later and regenerate any models produced with versions in the affected range. Until upgraded, do not import generated models built from untrusted or attacker-controlled OpenAPI/JSON Schema inputs without reviewing the emitted Field(default_factory=...) and field(default_factory=...) arguments for unexpected embedded expressions. Treat schema documents from untrusted sources as a code-execution risk for any remaining vulnerable generator versions.
| koxudaxi datamodel-code-generator | >= 0.17.0 and < 0.60.2; fixed in 0.60.2 |
Order-of-magnitude estimate by the model from install counts, market share and public scan data it knows; verify before quoting.
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.
- Vendors
- koxudaxi
- Products
- datamodel-code-generator
- Weakness
- CWE-94, CWE-1336
- Vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H
In the news0 stories
No ingested article mentions this CVE yet.