CVE-2026-54656·Python vulnerability
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.
- Severity
- high
- Software
- Python
- Fixed in
- 0.60.2
- Published
- 2026-07-28
Affected versions
From: 0.52.1
Until: 0.60.2
Fixed in: 0.60.2
How to fix this CVE
Update datamodel-code-generator to version 0.60.2 or later to patch unsafe validator interpolation in Pydantic v2 model generation. If you use datamodel-code-generator with untrusted --extra-template-data inputs or auto-import generated models, apply this patch immediately. Verify the update by checking the installed version and regenerating any models from potentially compromised schemas.
sudo dnf update python3-datamodel-code-generator || pip3 install --upgrade datamodel-code-generator>=0.60.2Defensia detects this vulnerability
How to check if you are affected
- Run `pip3 show datamodel-code-generator | grep Version` to check the installed version; versions 0.52.1 through 0.60.1 are vulnerable
- Search your project for generated Pydantic v2 models that were created with --extra-template-data flags: `grep -r '@field_validator' . --include='*.py' | head -20`
- Check if any generated model files contain suspicious field_validator decorators with inline code: `grep -rn 'field_validator' . --include='*.py' -A 3 | grep -E '(exec|eval|__import__|subprocess)'`
- Verify the patch by running `pip3 install datamodel-code-generator==0.60.2` and then `pip3 show datamodel-code-generator | grep Version` to confirm version 0.60.2 or later is installed
FAQ
What is CVE-2026-54656?
CVE-2026-54656 is a code injection vulnerability in datamodel-code-generator versions 0.52.1–0.60.1 where unsanitized validator code from --extra-template-data is directly embedded into Pydantic v2 @field_validator decorators, enabling arbitrary Python code execution when the generated models are imported.
Is CVE-2026-54656 being actively exploited?
No, CVE-2026-54656 is not listed on the CISA Known Exploited Vulnerabilities (KEV) catalog and no public exploits are currently available. However, the vulnerability requires prompt patching as exploitation is trivial once a malicious schema is supplied.
What versions of datamodel-code-generator are affected by CVE-2026-54656?
Versions 0.52.1 through 0.60.1 are affected. Version 0.60.2 and later contain the security fix.
How do I check if my server is vulnerable to CVE-2026-54656?
Run `pip3 show datamodel-code-generator` and verify the Version field is 0.60.2 or later. If the version is between 0.52.1 and 0.60.1 inclusive, your installation is vulnerable.
Does Defensia detect CVE-2026-54656?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If datamodel-code-generator is installed on a monitored server, CVE-2026-54656 will appear in your dashboard with remediation steps.
Related Python CVEs
References
- https://github.com/koxudaxi/datamodel-code-generator/commit/a43d02906111a2fdcaf13ee5b62eb2da85376f19
- https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2
- https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-8m8r-38jm-f355
- https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-8m8r-38jm-f355
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2026-54656. Free for 1 server.
Get started free