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.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.
Published: 2026-07-28
Score: 7.8 High
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

The vulnerability in datamodel-code-generator allows arbitrary Python code to be executed when a generated Pydantic v2 model is imported. The flaw stems from the interpolation of validators supplied via the --extra-template-data option; the tool places these raw strings into @field_validator decorators without escaping. As a result, an attacker who can influence the content of the validators can inject and run malicious code during import of the generated model, compromising the confidentiality, integrity, and availability of the runtime environment.

Affected Systems

The issue affects versions 0.52.1 through 0.60.2 of datamodel-code-generator from the vendor koxudaxi. Any environment that uses these versions and generates Pydantic v2 models from external schemas with the --extra-template-data flag is potentially impacted.

Risk and Exploitability

The CVSS score of 7.8 indicates a high severity, while the EPSS score of less than 1% suggests a low but non-zero probability of exploitation at the time of this assessment. The vulnerability is not yet listed in the CISA KEV catalog. Exploitation requires the attacker to supply custom validators via the command line or configuration file; the code then runs when the generated module is imported, making the attack vector a trusted-code module import scenario.

Generated by OpenCVE AI on August 3, 2026 at 14:10 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade datamodel-code-generator to version 0.60.2 or newer, where the problematic interpolation has been removed.
  • If an upgrade is not immediately possible, avoid using the --extra-template-data option with untrusted inputs, or ensure the validator strings are strictly validated and escaped before being passed to the tool.
  • In environments where the tool must stay on an older version, consider monkey-patching the _process_validators function to sanitize inputs or restrict the generator to a whitelist of safe validator patterns.

Generated by OpenCVE AI on August 3, 2026 at 14:10 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-8m8r-38jm-f355 `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
History

Wed, 29 Jul 2026 15:30:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'poc', 'Technical Impact': 'total'}, 'version': '2.0.3'}


Wed, 29 Jul 2026 00:45:00 +0000

Type Values Removed Values Added
First Time appeared Koxudaxi
Koxudaxi datamodel-code-generator
Vendors & Products Koxudaxi
Koxudaxi datamodel-code-generator

Tue, 28 Jul 2026 22:00:00 +0000

Type Values Removed Values Added
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.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.
Title `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
Weaknesses CWE-94
References
Metrics cvssV3_1

{'score': 7.8, 'vector': 'CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H'}


Subscriptions

Koxudaxi Datamodel-code-generator
cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-07-29T14:12:17.588Z

Reserved: 2026-06-15T20:16:46.199Z

Link: CVE-2026-54656

cve-icon Vulnrichment

Updated: 2026-07-29T14:11:43.053Z

cve-icon NVD

Status : Analyzed

Published: 2026-07-28T22:17:40.507

Modified: 2026-08-06T20:10:31.107

Link: CVE-2026-54656

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-08-03T14:15:05Z

Weaknesses
  • CWE-94

    Improper Control of Generation of Code ('Code Injection')