CVE-2026-55415 in datamodel-code-generator
Summary
by MITRE • 07/29/2026
datamodel-code-generator generates Pydantic v2 models, dataclasses, TypedDict, and msgspec.Struct from OpenAPI, JSON Schema, GraphQL, Avro, Protobuf, and raw JSON, YAML, or CSV. From 0.11.6 until 0.64.0, datamodel-code-generator allows attacker-controlled x-python-import or customTypePath schema extensions to reach src/datamodel_code_generator/parser/jsonschema.py and generated import handling through Import.from_full_path and Imports.create_line in src/datamodel_code_generator/imports.py, allowing a newline to break out of an import statement and execute Python code when the generated model is imported. This issue is fixed in version 0.64.0.
If you want to get best quality of vulnerability data, you may have to visit VulDB.
Analysis
by VulDB Data Team • 07/29/2026
The datamodel-code-generator library presents a critical security vulnerability that enables arbitrary code execution through carefully crafted schema extensions. This flaw exists within the processing of attacker-controlled x-python-import or customTypePath schema extensions, which are designed to handle Python import paths during model generation. The vulnerability stems from insufficient input validation and sanitization in the import handling mechanism, specifically in the jsonschema.py parser and imports.py modules.
The technical exploitation occurs when the library processes schema files containing malicious import paths that include newline characters or other control sequences. These sequences break out of normal import statement boundaries and allow attackers to inject arbitrary Python code into the generated model files. The vulnerability manifests through the Import.from_full_path method in the parser module, which directly translates user-provided import paths without proper sanitization. Subsequently, the Imports.create_line function in imports.py constructs import statements that execute this malicious code when the generated models are imported by unsuspecting users.
This issue represents a severe privilege escalation vulnerability that can be exploited across multiple attack vectors including OpenAPI specifications, JSON Schema files, GraphQL schemas, and other supported data formats. The impact extends beyond simple code execution to potential remote code execution on systems where these generated models are imported, particularly in automated environments or CI/CD pipelines. The vulnerability affects all versions from 0.11.6 through 0.64.0, making it a widespread concern for organizations using this library in production environments.
The security implications align with CWE-94 (Improper Control of Generation of Code) and CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component). This vulnerability maps directly to ATT&CK technique T1059.006 (Python) and T1203 (Exploitation for Client Execution), as it enables attackers to execute malicious Python code through legitimate library usage patterns. Organizations should immediately upgrade to version 0.64.0 or later, which implements proper input sanitization and import path validation to prevent the exploitation of this vulnerability.
The flaw demonstrates a classic insecure deserialization issue where external data is directly processed without adequate sanitization before code generation. Attackers can leverage this to inject malicious Python code that executes with the privileges of the system running the datamodel-code-generator, potentially leading to complete system compromise if the generated models are executed in privileged contexts. This vulnerability particularly affects development environments where schema files might be sourced from untrusted origins or where automated code generation processes import external specifications without proper validation layers.
Organizations should implement additional security controls such as input validation for schema extensions, restricted file access during code generation, and runtime monitoring of imported modules to detect anomalous behavior patterns. The fix in version 0.64.0 addresses the core issue by implementing proper sanitization of import paths and preventing newline injection attacks through comprehensive input validation mechanisms that ensure all import statements remain within safe boundaries during the model generation process.