# CVE-2026-127208: datamodel-code-generator < 0.84.0 Code Injection via x-python-type Annotation

> A malicious JSON schema can inject Python code into generated models, executing arbitrary code on developer workstations or CI pipelines that import them.

- **Severity:** High 8.6 (`CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Harmful if only installed:** No
- **Needs a specific call:** No
- **Fix available:** No
- **Published:** 12 Nov 2026
- **Updated:** 13 Nov 2026
- **Also known as:** GHSA-5hqf-87jh-5c5q

## What is CVE-2026-127208?

CVE-2026-127208 is a high-severity code injection vulnerability in datamodel-code-generator, published on 12 Nov 2026. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

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.

Weakness: CWE-94 (Improper Control of Generation of Code)

## Which versions are affected by CVE-2026-127208?

1 open source package ship an affected version, including datamodel-code-generator.

An affected version is exposed as installed. No special setting or call is needed.


| Package | Ecosystem | PURL | Affected | Fixed in |
| --- | --- | --- | --- | --- |
| `datamodel-code-generator` | PyPI | `pkg:pypi/datamodel-code-generator` | All versions | 0.84.0 |

## How do I fix CVE-2026-127208?

Upgrade datamodel-code-generator to 0.84.0 or later.

## Is CVE-2026-127208 being exploited?

There is no known exploitation of CVE-2026-127208 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2026-127208 and fix it if it is affected.

What it is: CVE-2026-127208 is a high-severity code injection vulnerability in datamodel-code-generator, published on 12 Nov 2026. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2026-127208 in the wild and no public exploit code.
Exposure: An affected version is exposed as installed. No special setting or call is needed.

Affected packages and fixed versions:
- datamodel-code-generator (PyPI): affected all versions; fixed in 0.84.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2026-127208/ (Markdown: https://insights.sbomify.com/CVE-2026-127208/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2026-127208
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2026-127208
- OSV: https://osv.dev/vulnerability/CVE-2026-127208

---
From sbomify Insights: https://insights.sbomify.com/CVE-2026-127208/
Summaries are generated and may contain mistakes; the official description above is the record.
