Read the docs

Code injection in datamodel-code-generator via x-python-type annotation

Priority LOW 39CWE-94Published · Updated

Key facts

Attack vector
Network
Privileges required
None
User interaction
Active
Attack complexity
Low
Attack requirements
None
Impact type
Code execution
Confidentiality · integrity · availability
High · High · High
Fix status
Fixed

Attack profile from CVSS 4.0 · CNA. Fix status from CNA. Impact type from CWE-94.

Summary

datamodel-code-generator before 0.84.0 contains a code injection flaw in how it handles crafted x-python-type annotations in JSON Schema input, tied to CWE-94. An attacker who supplies a malicious JSON Schema can run arbitrary code, because Pydantic v2 evaluates the injected expressions during model_rebuild(). The impact reaches developer workstations, CI/CD pipelines, and applications that generate and import the produced models at runtime.

Written with Claude Haiku 5.5 from the sources below · 2026-11-13

Description from the CNA

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.

Why it matters now

Exploitation None reported CISA SSVC · not in CISA KEV
EPSS 0.00371 31st percentileScored 2026-11-16
Fix Fixed datamodel-code-generator (datamodel-code-generator): 0.84.0

SSVC decision points

CISA ADP · SSVC 2.0.3

Exploitation
None
Automatable
No
Technical impact
Total

The decision (Track, Attend, Act) also depends on your mission and well-being impact; see CISA's SSVC guide.

Affected products

VendorProductAffected versionsFixed inStatusSource
datamodel-code-generatordatamodel-code-generatorbefore 0.84.00.84.0Patch availableCNA

Remediation

Upgrade datamodel-code-generator to version 0.84.0 or later, which fixes this issue.

Written with Claude Haiku 5.5 from the sources below · 2026-11-13

  • Fix · CNA datamodel-code-generator (datamodel-code-generator) Fixed in 0.84.0

Timeline

  1. 2026-11-12 Threatist record created from CVE-2026-127208
  2. 2026-11-12 Alias added: GHSA-5hqf-87jh-5c5q
  3. 2026-11-13 CISA SSVC decision points changed

References

  • TI-2026-69604 Path traversal in datamodel-code-generator lets attackers write files CVSS 3.1HIGH 7.5

Sources