# CVE-2026-54653: koxudaxi datamodel-code-generator code injection via default_factory field

Source: https://junglewise.ai/threats/cve-2026-54653-koxudaxi-datamodel-code-generator-code-injection-via-default  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2026-07-28. Updated: 2026-07-28  
License: CC BY 4.0 with a link back

CVE-2026-54653 · Severity: high · CVSS 8.8 · Published 2026-07-28

datamodel-code-generator is a tool used by developers to automatically create Python code from data schemas like OpenAPI or JSON Schema. A security flaw allows a malicious schema to inject hidden Python code into the generated files. If a developer or automated system generates code from an untrusted schema and then imports that code, the attacker's hidden commands will execute immediately, potentially leading to data theft, system compromise, or unauthorized access to the development environment.

Technologies: [Koxudaxi Datamodel-Code-Generator](https://junglewise.ai/threats/technologies/datamodel-code-generator), [datamodel-code-generator (PyPI)](https://junglewise.ai/threats/technologies/pypi-datamodel-code-generator). Vendors: [Koxudaxi](https://junglewise.ai/threats/vendors/koxudaxi), [PyPI](https://junglewise.ai/threats/vendors/pypi).

## Quick answers

**Is CVE-2026-54653 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2026-54653 being exploited in the wild.

**How severe is CVE-2026-54653?** High severity, with a CVSS score of 8.8, published 28 July 2026.

**Which products and versions are affected?** Koxudaxi Datamodel-Code-Generator >= 0.17.0, < 0.60.2, >= 0.17.0, <= 0.60.1; datamodel-code-generator (PyPI) ECOSYSTEM:introduced=0.17.0,fixed=0.60.2.

**Is there a fix for CVE-2026-54653?** Yes. datamodel-code-generator (PyPI): upgrade to 0.60.2 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2026-54653 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2026-54653?** Check whether you run Koxudaxi Datamodel-Code-Generator or datamodel-code-generator (PyPI) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- datamodel-code-generator (PyPI): upgrade to 0.60.2 or later

  ```sh
  pip install "datamodel-code-generator>=0.60.2"
  ```


## Technical details

The vulnerability is a code injection flaw (CWE-94/CWE-1336) residing in the JSON Schema parser component. The generator preserves attacker-controlled 'default_factory' values from input schemas (OpenAPI, JSON Schema, etc.) and interpolates them verbatim into the generated Python code's Field() or field() arguments without proper sanitization or escaping. Because these assignments are evaluated at class-definition time, the injected Python expressions execute automatically when the resulting module is imported. The attack requires the victim to run the generator against a malicious schema and subsequently import the output. This affects Pydantic v2, dataclass, and msgspec output types. The issue is fixed in version 0.60.2 by restricting 'default_factory' values to a safe allowlist (dict, list, set).

## Affected products

- koxudaxi datamodel-code-generator >= 0.17.0, < 0.60.2

## Identifiers

- CVE-2026-54653
- GHSA-386q-5hp3-95m9
- PYSEC-2026-3555

## Timeline

- 2026-06-08: patched: Fixed in version 0.60.2
- 2026-06-08: advisory: GitHub Security Advisory GHSA-386q-5hp3-95m9 published
- 2026-07-28: disclosed: CVE-2026-54653 published to NVD

## References

- [https://github.com/koxudaxi/datamodel-code-generator/commit/17fc235e234cbcfaaadef8c74cb72c9687db0d1d](https://github.com/koxudaxi/datamodel-code-generator/commit/17fc235e234cbcfaaadef8c74cb72c9687db0d1d)
- [https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2](https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.60.2)
- [https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-386q-5hp3-95m9](https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-386q-5hp3-95m9)

## Related threats

- [datamodel-code-generator Protobuf path traversal allows files to be written outside directory](https://junglewise.ai/threats/cve-2026-107377-datamodel-code-generator-protobuf-weak-import-path-traversal)
- [koxudaxi datamodel-code-generator code injection in generated imports](https://junglewise.ai/threats/cve-2026-55415-koxudaxi-datamodel-code-generator-code-injection-in-generated)
- [koxudaxi datamodel-code-generator credential leak in cross-origin redirects](https://junglewise.ai/threats/cve-2026-55403-koxudaxi-datamodel-code-generator-credential-leak-in-cross-origin)
- [koxudaxi datamodel-code-generator SSRF via DNS rebinding](https://junglewise.ai/threats/cve-2026-55391-koxudaxi-datamodel-code-generator-ssrf-via-dns-rebinding)
- [koxudaxi datamodel-code-generator path traversal in XML Schema parsing](https://junglewise.ai/threats/cve-2026-55390-koxudaxi-datamodel-code-generator-path-traversal-in-xml-schema)
