CVE-2026-54654 `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in `--extra-template-data` `comment` field

High 7.8 Published Updated

Attackers can inject Python code into generated models via unescaped carriage returns in template data, leading to code execution upon import.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Local or same network only
Victim action needed
A user has to click or open something
Fix
Available

What is CVE-2026-54654?

CVE-2026-54654 is a high-severity code injection vulnerability in koxudaxi datamodel-code-generator, published on 28 Jul 2026. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

Official 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.

Weakness: CWE-94, CWE-1336

Which versions are affected by CVE-2026-54654?

3 open source packages ship an affected version, including datamodel-code-generator.

PackageAffectedFixed in
datamodel-code-generator PyPIFrom 0.14.10.60.2
datamodel-code-generator PyPIFrom 0.14.10.60.2
datamodel-code-generator PyPIFrom 0.14.10.60.2

How do I fix CVE-2026-54654?

Upgrade datamodel-code-generator to 0.60.2 or later.

Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.

Is CVE-2026-54654 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2026-54654 exists.

Sources

Also known as GHSA-wjv6-jcfj-mf9r, MINI-rfqh-p392-g9cv, PYSEC-2026-3566.

Is CVE-2026-54654 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free