CVE-2026-54656: `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
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.52.1 until 0.60.2, datamodel-code-generator interpolates validators from --extra-template-data in src/datamodel_code_generator/model/pydantic_v2/base_model.py through _process_validators into @field_validator decorators without safe validation, allowing Python code execution when the generated Pydantic v2 model is imported. This issue is fixed in version 0.60.2.
Security readout for executives and security teams
Plain-English summary
A flaw in datamodel-code-generator can turn untrusted validator metadata into Python code embedded in generated Pydantic v2 models. That code runs when a developer or automated system imports the generated model, potentially compromising the account or build environment performing the import.
Executive priority
Prioritize remediation in CI, developer tooling, or generation services that process externally influenced schemas or template metadata. Upgrade promptly where generated models are automatically imported with valuable credentials. Lower urgency may be reasonable only after confirming trusted inputs, no affected Pydantic v2 workflow, and no vulnerable generated artifacts.
Technical view
Versions 0.52.1 through 0.60.1 insufficiently validate validators supplied through --extra-template-data before placing them into field_validator decorators. Importing the resulting Pydantic v2 model can execute injected Python code. The issue is CWE-94, carries CVSS 3.1 score 7.8, and is fixed in 0.60.2.
Likely exposure
Exposure requires an affected version, Pydantic v2 model generation, attacker-influenced extra template data containing validator entries, and subsequent import of generated code. Developer workstations, CI pipelines, and code-generation services accepting untrusted metadata are the most plausible at-risk environments. Presence of the package alone does not establish exploitability.
Exploitation context
The vector is local and requires user interaction because generated code must be imported. No privileges are required to supply malicious input where a workflow already accepts untrusted template data. Successful exploitation could affect confidentiality, integrity, and availability. The supplied sources do not report active exploitation, and the CVE is not listed as KEV.
Researcher notes
The vulnerable path processes validators from extra template data into Pydantic v2 field_validator decorators without safe validation. Assess both the generator installation and already generated artifacts, since upgrading does not automatically remove unsafe code previously emitted. The supplied evidence establishes the vulnerable range and fix but provides no evidence of exploitation in the wild.
Mitigation direction
Upgrade datamodel-code-generator to version 0.60.2 or later.
Restrict --extra-template-data to trusted, reviewed sources.
Regenerate affected Pydantic v2 models after upgrading.
Review generated models before importing them into developer or automated environments.
Isolate code-generation and import workflows with minimal credentials and permissions.
Validation and detection
Inventory installed and build-pinned datamodel-code-generator versions.
Identify workflows generating Pydantic v2 models with --extra-template-data.
Trace whether external users or repositories can influence validator metadata.
Review previously generated field_validator decorators for unexpected validator expressions.
Confirm regenerated models use version 0.60.2 or later and pass existing tests.
Generated from the cited source records. This long-tail analysis has not been individually reviewed by a named human.
Potential ATT&CK relevance
Conservative CVE-to-ATT&CK context
These mappings and lookup hints may be relevant to the vulnerability behavior, CWE, affected product, or exposure path. Glexia-inferred context is not an official MITRE, ATT&CK, CWE, or CVE Program mapping.
ATT&CK lookup starting points
Use these exact CWE pages and searches to review the Glexia ATT&CK library from this CVE's weakness and description context.
cwe · medium confidence lookup
CWE-94: Code execution behavior lookup
Code execution and unsafe deserialization weaknesses often justify reviewing execution behavior and process telemetry. Open the exact CWE lookup page first, then review the ATT&CK searches from that MITRE weakness context. This is a Glexia lookup hint, not an official ATT&CK mapping.
The CVE wording references code or command execution, so execution technique review may help defensive triage. This is a Glexia inferred lookup path, not an official MITRE, ATT&CK, or CVE Program mapping.
These fields come from the CVE record and ADP containers, not from Glexia's Take. They preserve time-varying source decisions such as CISA SSVC, KEV status, CVSS metrics, and provider references.
1CVSS vectors
3Timeline events
0ADP providers
4Source links
CVSS vector scores
1 official score
We collect every scored CVSS vector available in the official CNA and ADP containers. When more than one version is present, the table keeps the source vectors side by side instead of collapsing them into the highest score.
CWE links open Glexia weakness intelligence pages with official CWE context, developer remediation guidance, and related CVE mappings.
CWE-94 · source CWE mapping
Improper Control of Generation of Code ('Code Injection')
Improper Control of Generation of Code ('Code Injection') represents a recurring weakness pattern that can create exploitable paths when design, validation, or implementation controls are missing.