Description
datamodel-code-generator generates Python data models from schema definitions. From 0.14.1 until 0.60.2, the --extra-template-data comment field is rendered into Python comments in src/datamodel_code_generator/model/template/TypeAliasAnnotation.jinja2, src/datamodel_code_generator/model/template/TypedDict.jinja2, src/datamodel_code_generator/model/template/dataclass.jinja2, src/datamodel_code_generator/model/template/msgspec.Struct.jinja2, src/datamodel_code_generator/model/template/pydantic/BaseModel.jinja2, and src/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 without neutralizing carriage returns in Python # comments, allowing an attacker-controlled comment value to inject Python code into generated models that runs when 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 defect allows an attacker to supply a comment string via the --extra-template-data option that is written directly into Python comment lines in several Jinja2 templates without neutralising carriage returns. Because the injected text can terminate the comment and begin an executable statement, the generated Python module becomes a vector for arbitrary code execution when it is later imported. This leads to loss of confidentiality, integrity and availability at the process level, matching CWE-1336 (Unsanitised Input) and CWE-94 (Code Injection).

Affected Systems

The vulnerability is present in the datamodel-code-generator package from vendor koxudaxi. Any installation of versions 0.14.1 through 0.60.1 is affected; the problem is fixed in release 0.60.2 and later, while earlier pre‑0.14.1 builds are not impacted according to the available data.

Risk and Exploitability

The CVSS score of 7.8 indicates high potential impact. The EPSS score of less than 1 % denotes a very low likelihood of exploitation, and the vulnerability is not listed in CISA’s KEV catalog. Exploitation requires an attacker to control the comment input when running datamodel-code-generator and then cause the produced module to be imported in a trusted environment, such as a continuous‑integration job that automatically loads generated models. Successful exploitation would give the attacker full code execution on the host running the import.

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

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade to datamodel-code-generator version 0.60.2 or later, which removes the unsanitised injection path.
  • Sanitise the comment string before passing it to --extra-template-data, for example by stripping carriage returns or rejecting non‑trusted content.
  • Audit all build or automation workflows that invoke datamodel-code-generator to ensure that --extra-template-data is used only with trusted sources and that generated modules are not automatically imported into secure contexts.

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

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-wjv6-jcfj-mf9r `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in `--extra-template-data` `comment` field
History

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

Type Values Removed Values Added
Metrics ssvc

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


Tue, 28 Jul 2026 22: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 21:30:00 +0000

Type Values Removed Values Added
Description datamodel-code-generator generates Python data models from schema definitions. From 0.14.1 until 0.60.2, the --extra-template-data comment field is rendered into Python comments in src/datamodel_code_generator/model/template/TypeAliasAnnotation.jinja2, src/datamodel_code_generator/model/template/TypedDict.jinja2, src/datamodel_code_generator/model/template/dataclass.jinja2, src/datamodel_code_generator/model/template/msgspec.Struct.jinja2, src/datamodel_code_generator/model/template/pydantic/BaseModel.jinja2, and src/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2 without neutralizing carriage returns in Python # comments, allowing an attacker-controlled comment value to inject Python code into generated models that runs when imported. This issue is fixed in version 0.60.2.
Title `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in `--extra-template-data` `comment` field
Weaknesses CWE-1336
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-29T15:24:23.911Z

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

Link: CVE-2026-54654

cve-icon Vulnrichment

Updated: 2026-07-29T14:33:57.871Z

cve-icon NVD

Status : Deferred

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

Modified: 2026-07-30T20:02:44.977

Link: CVE-2026-54654

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

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

Weaknesses
  • CWE-1336

    Improper Neutralization of Special Elements Used in a Template Engine

  • CWE-94

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