---
id: "CVE-2026-127208"
page: "https://infrastack.ai/live/CVE-2026-127208"
kind: "vulnerability"
aliases: ["CVE-2026-127208"]
title: "datamodel-code-generator: crafted JSON Schema runs code on generating machines"
severity: "high"
cvss: 8.8
epss: null
exploited: false
status: "open"
category: "package"
products: []
ecosystems: []
tags: ["ci-cd", "datamodel-code-generator", "package", "pydantic", "python"]
not_affected_if: ["no-runtime-model-import", "trusted-schemas-only"]
published_at: "2026-11-12T21:17:22+00:00"
first_seen_at: "2026-11-12T21:40:31+00:00"
updated_at: "2026-11-12T21:42:21+00:00"
sources: [{"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-127208", "first_seen_at": "2026-11-12T21:40:31+00:00"}]
exploit_sources: []
---

# datamodel-code-generator: crafted JSON Schema runs code on generating machines

Link for people: https://infrastack.ai/live/CVE-2026-127208 (this .md is for agents)

datamodel-code-generator before 0.84.0 fails to validate the x-python-type annotation in a JSON Schema, so a malicious schema can put Python expressions into generated models. When Pydantic v2 evaluates those strings during model_rebuild(), the attacker's code runs on the developer workstation, CI pipeline, or application that imports the models.

_Summary, check and fix written by a model from the sources; labelled as such._

## How to check

- Check the installed version with `datamodel-code-generator --version` or `pip show datamodel-code-generator`.
- Search your project for any JSON Schema input from untrusted sources that uses `x-python-type`.
- Check whether generated models are imported at runtime with Pydantic v2 `model_rebuild()`.

## Fix

- datamodel-code-generator: move to `0.84.0` or later.

## Timeline

- 2026-11-12T21:40:31+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-127208

## Documents

- [advisory] Third-party advisory: www.vulncheck.com https://www.vulncheck.com/advisories/datamodel-code-generator-code-injection-via-x-python-type-annotation
- [fix] Patch: github.com https://github.com/datamodel-code-generator/datamodel-code-generator/commit/ebfc11d0644d37a71374b28aac06d98748e584ec
- [fix] Release notes: github.com https://github.com/datamodel-code-generator/datamodel-code-generator/releases/tag/0.84.0

## From the sources

datamodel-code-generator before 0.84.0 contains a code injection vulnerability that allows attackers to achieve arbitrary code execution by supplying a malicious JSON Schema with a crafted x-python-type annotation containing a string ast.Constant node in a subscript slice position, which bypasses validation in parse_python_type_annotation and _python_type_expr_from_ast. Attackers can embed malicious Python expressions such as __import__ calls within quoted string literals in the generated source code, which Pydantic v2 evaluates as a ForwardRef via eval() during model_rebuild(), resulting in arbitrary code execution on developer workstations, CI/CD pipelines, or applications that generate and import the produced models at runtime.

---

_Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai_
