CVE-2026-55389 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. Prior to 0.62.0, datamodel-code-generator resolves JSON Schema $ref targets in src/datamodel_code_generator/parser/jsonschema.py through is_url and _get_ref_body without containing file:// or ../ traversal references to the input directory and without honoring --no-allow-remote-refs, allowing arbitrary local file reads. This issue is fixed in version 0.62.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 tool presents a critical security vulnerability that enables unauthorized local file access through improper handling of JSON Schema $ref references. This flaw exists in versions prior to 062.0 and stems from inadequate validation of reference targets during the code generation process. The vulnerability specifically manifests in the src/datamodel_code_generator/parser/jsonschema.py file where is_url and _get_ref_body functions fail to properly sanitize input references, allowing attackers to traverse local file systems without proper authorization.
The technical implementation of this vulnerability exploits the tool's inability to distinguish between legitimate remote references and malicious local file access attempts. When processing JSON Schema documents containing $ref targets, the parser does not adequately verify that references adhere to safe protocols or remain within designated boundaries. This allows an attacker to craft schema files that reference local system files through relative paths or direct file:// URLs, bypassing normal security restrictions that would typically prevent such access patterns.
The operational impact of this vulnerability extends beyond simple information disclosure, as it enables potential escalation to arbitrary code execution or data exfiltration depending on the target system configuration. An attacker could leverage this flaw to read sensitive files from the local filesystem including configuration files, credentials, or other system artifacts that might be accessible to the user running the datamodel-code-generator process. The vulnerability particularly affects environments where the tool processes untrusted schema inputs, such as continuous integration pipelines or automated code generation workflows.
This security issue maps directly to CWE-22 - Improper Limitation of a Pathname to a Restricted Directory and aligns with ATT&CK technique T1059.006 - Command and Scripting Interpreter: Python within the execution phase of cyber attacks. The vulnerability represents a path traversal flaw that allows unauthorized access to local files through the code generation process, potentially enabling attackers to gather sensitive information from the target system or compromise the integrity of the code generation environment.
Mitigation strategies for this vulnerability require immediate upgrading to version 0.62.0 or later where proper reference validation has been implemented. Organizations should also implement strict input validation policies for schema files processed by the tool, particularly in automated environments where untrusted inputs may be present. Additionally, system administrators should consider restricting file access permissions for users running the datamodel-code-generator and implementing network segmentation to limit potential impact if exploitation occurs. The fix implemented in version 0.62.0 addresses both the --no-allow-remote-refs flag handling and proper validation of local file references, ensuring that only authorized file access occurs during the code generation process.