CVE-2026-127208: datamodel-code-generator < 0.84.0 Code Injection via x-python-type Annotation
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 parsepythontypeannotation and pythontypeexprfromast. 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 modelrebuild(), resulting in arbitrary code execution on developer workstations, CI/CD pipelines, or applications that generate and import the produced models at runtime.
Event History
Frequently Asked Questions
Who is exposed to this issue?
Developer workstations, CI/CD pipelines, and applications are exposed when they process an attacker-supplied JSON Schema with datamodel-code-generator and then import the generated models or rebuild them at runtime.
What does an attacker need to exploit it?
An attacker needs to supply a malicious JSON Schema containing a crafted x-python-type annotation. Exploitation also requires user interaction in the form of generating and importing the resulting models, or otherwise invoking Pydantic v2 model_rebuild() on them.
What versions should be remediated?
Versions of datamodel-code-generator earlier than 0.84.0 are affected. Upgrade to version 0.84.0 or later.
How can teams identify potentially affected generated code?
Review schemas and generated model source for x-python-type annotations and suspicious quoted Python expressions, particularly expressions containing __import__ calls. Treat generated models derived from untrusted schemas as potentially unsafe if they were imported or rebuilt with Pydantic v2.