Executive brief
datamodel-code-generator is a tool used to automatically create Python code from data schema definitions. A security flaw in how it handles XML schemas allows an attacker to provide a malicious schema file that forces the tool to read sensitive files from the local system, such as configuration files or other source code. If this tool is used in an automated pipeline or a shared service, an attacker could steal private information by having it included in the generated code output.
Technical details
A path traversal vulnerability exists in the XML Schema (XSD) parser of datamodel-code-generator within `src/datamodel_code_generator/parser/xmlschema.py`. The parser fails to validate that `schemaLocation` attributes in `xs:include`, `xs:import`, `xs:redefine`, and `xs:override` tags remain within the input base directory. By using `../` sequences or absolute paths, an attacker can force the application to read arbitrary local files that the process has permissions to access. If the target file contains XML-structured data, its contents may be reflected in the generated Python models. This issue is reachable in the default configuration and is not mitigated by the `--no-allow-remote-refs` flag. The vulnerability was introduced in version 0.59.0 and is fixed in version 0.62.0 by enforcing that all resolved paths are relative to the base input directory.
Affected products
- koxudaxi datamodel-code-generator >= 0.59.0, < 0.62.0
Timeline
- 2026-06-10: patched: Version 0.62.0 released
- 2026-06-12: advisory: GitHub Security Advisory published
- 2026-07-28: disclosed: CVE published to NVD