Categories
CVE-2026-54655 high CVSS 7.8

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

Summary

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

Original description

The description as published by the source.

Summary

datamodel-code-generator honours a custom x-python-type JSON-Schema extension that lets a schema author override the generated Python type for a field. The value is forwarded verbatim into the generated Python source as the field annotation, with a single sanitisation pass that is trivial to bypass. An attacker who controls a JSON Schema fed to datamodel-codegen can therefore embed an arbitrary Python statement in the generated module, which executes at class-definition time the moment the developer imports the file. No --extra-template-data and no special flags are required; the vulnerable code is reachable with default settings.

Details

Sink: src/datamodel_code_generator/parser/jsonschema.py, _get_python_type_override (lines 2055–2096, at tag 0.60.1 / commit a321547e):

def _get_python_type_override(self, obj: JsonSchemaObject) -> DataType | None:
    x_python_type = obj.extras.get("x-python-type")
    if not x_python_type or not isinstance(x_python_type, str):
        return None
    schema_type = obj.type if isinstance(obj.type, str) else None
    if self._is_compatible_python_type(schema_type, x_python_type):
        return None
    base_type = self._get_python_type_base(x_python_type)
    import_ = self._resolve_type_import(base_type)
    type_str = x_python_type
    prefix = x_python_type.split("[", maxsplit=1)[0]
    if "." in prefix:                                  # only sanitiser
        type_str = base_type + x_python_ty…

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-54655 has been found in datamodel-code-generator.
Attackers can target a specific entry point like _get_python_type_override 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-54655" on the vendor's site.

CVE-2026-54655 (datamodel-code-generator) — CWE-94 / CVSS v3 7.8
Attack vector: local / unauthenticated
Attack surface: _get_python_type_override / a321547e / DataType.type / import
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 _get_python_type_override without authentication.

📍 Affected scope

Check the vendor advisory for the affected versions of datamodel-code-generator. Attack surface: _get_python_type_override / a321547e / DataType.type / import.

🔥 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.51.0"},{"fixed":"0.60.2"}]}]

References

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