Categories
CVE-2026-54654 high CVSS 7.8

Code Injection in datamodel-code-generator (CVE-2026-54654)

Summary

Code injection in datamodel-code-generator (CVE-2026-54654). Successful exploitation can lead to full system takeover. Exploitable via comment. Mitigation: upgrade to 0.60.2 or later.

Original description

The description as published by the source.

Summary

datamodel-code-generator is vulnerable to code injection when a developer passes an --extra-template-data file whose comment value contains a literal \r (carriage return). The comment variable is rendered into a Python # comment in six built-in templates with no line-terminator escaping. Python's tokenizer treats a bare CR as a physical-line terminator (see Python language reference — Physical lines), so the comment ends at the \r and the text after it is parsed as Python, including, when the CR is followed by suitable indentation, as a statement within the class body that follows on the next template line.

Details

The vulnerable templates each contain # {{ comment }} with no escaping:

  • src/datamodel_code_generator/model/template/TypeAliasAnnotation.jinja2:12 and :19
  • src/datamodel_code_generator/model/template/TypeAliasType.jinja2:12 and :19
  • src/datamodel_code_generator/model/template/TypeStatement.jinja2:12 and :19
  • src/datamodel_code_generator/model/template/pydantic_v2/BaseModel.jinja2:4
  • src/datamodel_code_generator/model/template/pydantic_v2/RootModel.jinja2:19
  • src/datamodel_code_generator/model/template/pydantic_v2/RootModelTypeAlias.jinja2:13

The pydantic_v2/BaseModel.jinja2:4 site is representative:

class {{ class_name }}({{ base_class }}):{% if comment is defined %}  # {{ comment }}{% endif %}

When the devel…

Source: GitHub Security Advisories (Global) NVD GitHub Advisory

Auto-generated summary

Assembled by SecPulse from the source data (CVSS, CWE, affected versions) using templates — no AI involved. Check the original description and references below for exact details.

A vulnerability tracked as CVE-2026-54654 has been found in datamodel-code-generator.
Attackers can target a specific entry point like comment over the network to misuse the product.
Successful exploitation can lead to full system takeover. CVSS score: 7.8/10.
What to do: upgrade datamodel-code-generator to 0.60.2 or later.
If unsure, ask your IT team or search "datamodel-code-generator CVE-2026-54654" on the vendor's site.

CVE-2026-54654 (datamodel-code-generator) — CWE-94 / CVSS v3 7.8
Attack vector: local / unauthenticated
Attack surface: comment / DataModel.extra_template_data / comment_safe / escape_docstring
Patched: 0.60.2 — apply immediately
Plan: 1) Audit SBOM/dependencies, 2) Stage→prod upgrade, 3) Add WAF/proxy monitoring on affected endpoints, 4) Hunt IOCs in logs.
Refs: see the GHSA / vendor advisory / patched release linked on this page.

❓ What is the problem

Arbitrary code execution (CWE-94) exists in datamodel-code-generator. Attackers reach the vulnerable code path via comment without authentication.

📍 Affected scope

Check the vendor advisory for the affected versions of datamodel-code-generator. Attack surface: comment / DataModel.extra_template_data / comment_safe / escape_docstring.

🔥 Severity

Severity: High (CVSS 7.8/10). Successful exploitation can lead to full system takeover.

🔧 How to fix

Update to 0.60.2.

🛡️ Workaround

Until the patch is applied: disable the affected feature, apply WAF rules, or restrict access via network ACLs.

🔍 Detection

Search webserver/proxy logs for unusual request patterns matching this CVE's known IOCs. Run grep -r 'datamodel-code-generator' . against your dependency files (package-lock.json, requirements.txt, go.sum) to find affected services.

Response actions

Concrete steps and command examples for SOC/SRE teams to execute in order

  1. 1
    Identify exposure identify
    grep -r 'datamodel-code-generator' . | grep -v node_modules

    リポジトリと本番環境の依存ファイル (package-lock.json / requirements.txt / go.sum / Gemfile.lock 等) で datamodel-code-generator を grep し、稼働しているサービス・バージョンを把握する。

  2. 2
    Apply patch patch
    Upgrade datamodel-code-generator to 0.60.2

    ステージング環境で 0.60.2 に上げて回帰テスト → 本番反映。回帰テストはアプリの主要ハッピーパスを含めること。

  3. 3
    Post-deployment verification verify
    Confirm patched version is live in production

    パッチ適用後、ステージングで PoC または同等の悪用パターンを再現して脆弱性が閉じたことを確認。本番ではアクセスログ・WAF でアラート再発が無いか継続監視。

Affected packages

pip datamodel-code-generator
[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"0.60.2"}]}]
PyPI datamodel-code-generator
[{"type":"ECOSYSTEM","events":[{"introduced":"0.14.1"},{"fixed":"0.60.2"}]}]

References

We use cookies for analytics and ad measurement. This setting applies to all Game co., Ltd. sites. Details