Code Injection Vulnerability in datamodel-code-generator (CVE-2026-63720)
CVE-2026-63720 details a code injection vulnerability in datamodel-code-generator versions prior to 0.70.0, allowing attackers to achieve remote code execution by providing a malicious `customBasePath` value within input schemas that is unsafely embedded into a Python import statement.
datamodel-code-generator, a Python tool for generating data model code, is affected by a code injection vulnerability, CVE-2026-63720, in versions prior to 0.70.0. This flaw allows an attacker to achieve remote code execution (RCE) by manipulating input schemas. Specifically, by supplying a crafted customBasePath value containing embedded newlines and a dot-free Python expression, the attacker can cause arbitrary Python code to be emitted verbatim into a from ... import ... statement within the generated module. When this compromised module is subsequently imported, the malicious Python code executes, posing a significant risk to systems that process untrusted schemas using this tool.
Attack Chain
- An attacker prepares a malicious input schema designed for
datamodel-code-generator. - Within this schema, the attacker embeds a specially crafted
customBasePathvalue. - The
customBasePathvalue includes embedded newline characters and a dot-free Python expression (e.g.,os.system('malicious_command')). - A legitimate user or automated system processes this malicious input schema using
datamodel-code-generatorprior to version 0.70.0. - During the code generation process, the
datamodel-code-generatortool insecurely embeds the maliciouscustomBasePathverbatim into afrom ... import ...statement of the output Python module without validating the identifier. - When an application subsequently imports this newly generated, compromised Python module, the embedded malicious Python expression is executed.
- This execution leads to remote code execution (RCE) on the system where the generated module is imported, allowing the attacker to run arbitrary commands.
Impact
Successful exploitation of CVE-2026-63720 grants an attacker remote code execution capabilities on the system running the vulnerable datamodel-code-generator instance or any application that imports code generated from a malicious schema. This allows attackers to compromise the integrity and confidentiality of data, establish persistence, and potentially pivot to other systems within the environment. The severity of the impact depends on the privileges of the affected system, but generally represents a critical breach. No specific observed victims or targeted sectors are mentioned in the advisory, but any organization using affected versions of datamodel-code-generator to process untrusted schemas is at risk.
Recommendation
- Patch
datamodel-code-generatorto version 0.70.0 or later immediately to remediate CVE-2026-63720.