Arbitrary Code Injection Affecting datamodel-code-generator package, versions [,0.84.0)


Severity

Recommended
0.0
high
0
10

CVSS assessment by Snyk's Security Team. Learn more

Threat Intelligence

EPSS
0.37% (32nd percentile)

Do your applications use this vulnerable package?

In a few clicks we can analyze your entire application and see what components are vulnerable in your application, and suggest you quick fixes.

Test your applications

Snyk Learn

Learn about Arbitrary Code Injection vulnerabilities in an interactive lesson.

Start learning
  • Snyk IDSNYK-PYTHON-DATAMODELCODEGENERATOR-22565992
  • published16 Nov 2026
  • disclosed12 Nov 2026
  • creditEnrik Mustafa

Introduced: 12 Nov 2026

NewCVE-2026-127208  (opens in a new tab)
CWE-94  (opens in a new tab)

How to fix?

Upgrade datamodel-code-generator to version 0.84.0 or higher.

Overview

datamodel-code-generator is a Datamodel Code Generator

Affected versions of this package are vulnerable to Arbitrary Code Injection via _python_type_expr_from_ast and parse_python_type_annotation in _python_type_annotation_codec.py, where a malicious JSON Schema carrying a crafted x-python-type annotation can embed a string ast.Constant node in a subscript slice position. Because neither function rejects string constants outside of Literal[...] contexts, an attacker can inject Python expressions such as __import__ calls as quoted forward references into the generated source code. Pydantic v2 then evaluates these forward references 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.

CVSS Base Scores

version 4.0
version 3.1