CVE-2026-55390: Datamodel code generator Path Traversal Vulnerability

HIGH
Advisory Identifier: GHSA-442q-2j6p-642g
CVSS 7.5
CWE-610 CWE-200 CWE-22
Published
Advisory Summary

CVE-2026-55390 is a HIGH (CVSS 7.5) path traversal vulnerability (CWE-610: Externally Controlled Reference to a Resource in Another Sphere) affecting Datamodel code generator libraries in the PyPI ecosystem. The issue involves include`/`xs:import`) path traversal, with no remote-ref gate. Remediation is available by upgrading affected packages to version 0.62.0.

CVE-2026-55390 at a Glance

CVE Identifier CVE-2026-55390
GHSA Identifier GHSA-442q-2j6p-642g
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-610: Externally Controlled Reference to a Resource in Another Sphere
Affected Product Datamodel code generator
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2026-55390

To remediate this vulnerability, upgrade all affected Datamodel code generator dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

datamodel-code-generator fixed: 0.62.0
pip install datamodel-code-generator>=0.62.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show datamodel-code-generator

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2026-55390, inspect your installed packages using pip:

pip show datamodel-code-generator

Analyze the terminal output to locate any version of Datamodel code generator in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.62.0), your application is affected.

Note: The pip show datamodel-code-generator command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-610: Externally Controlled Reference to a Resource in Another Sphere, where the product uses an externally controlled name or reference that resolves to a resource that is outside of the intended control sphere. In Datamodel code generator, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary When generating models from an XML Schema (`--input-file-type xmlschema`), `datamodel-code-generator` resolves `<xs:include>`, `<xs:import>`, `<xs:redefine>`, and `<xs:override>` `schemaLocation` attributes against the source directory and reads the target with no restriction to the input/base directory. An attacker who controls the input XSD can read arbitrary files via `../` traversal or an absolute path, and the included schema's contents (type names, restrictions, enumerations) are folded into the generated output. Unlike the JSON-Schema `$ref` path, there is no `allow_remote_refs` control for XSD, so `--no-allow-remote-refs` does not mitigate it. This is an unauthenticated path-traversal / information-disclosure issue reachable in the default configuration. ### Details The XSD parser walks include-style children and reads each `schemaLocation` with only an `is_file()` check (`src/datamodel_code_generator/parser/xmlschema.py`): ```python location = (source_dir / schema_location).resolve() # .resolve() collapses ../, escapes base if location in seen or not location.is_file(): continue included_root = self._parse_schema(_read_xml_text(location, self.encoding), location) ``` `schema_location` is attacker-controlled and `_read_xml_text` does `path.read_bytes()`. Because `(source_dir / schema_location).resolve()` normalizes `..` and accepts absolute paths, the resolved target can be any file the process can read; there is no `is_relative_to(base_path)` containment (contrast the JSON-Schema HTTP-local branch, which does enforce it). The same unbounded read occurs both during version detection and during the main include-processing pass, so the included content is incorporated into the generated module. Related vectors that were tested and do NOT apply (stdlib `xml.etree.ElementTree` is used): external-entity XXE file read does not occur (ElementTree does not fetch external entities), and entity-expansion "billion laughs" is rejected by CPython's expat amplification limit. ### PoC Self-contained reproducer (creates a temp dir, runs the generator, cleans up): https://gist.github.com/thegr1ffyn/c7096b797926348875d888652867eeb4 (`poc.py`). Minimal manual reproduction: ```bash mkdir -p /tmp/x/secret /tmp/x/proj cat > /tmp/x/secret/leak.xsd <<'EOF' <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="LEAK_5150"><xs:restriction base="xs:string"/></xs:simpleType> </xs:schema> EOF cat > /tmp/x/proj/attack.xsd <<'EOF' <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:include schemaLocation="../../x/secret/leak.xsd"/> <xs:element name="Root" type="LEAK_5150"/> </xs:schema> EOF datamodel-codegen --input /tmp/x/proj/attack.xsd --input-file-type xmlschema --no-allow-remote-refs --output /tmp/x/out.py grep LEAK_5150 /tmp/x/out.py # content from outside the project dir appears in generated code ``` An absolute `schemaLocation="/abs/path/leak.xsd"` works identically. ### Impact Arbitrary local file read / path traversal (CWE-22) leading to information disclosure (CWE-200). Any application, CI pipeline, or multi-tenant service that generates models from an attacker-supplied XSD and exposes (returns, logs, commits, renders) the generated code is affected. The attacker can read files outside the input tree whose data is addressable as XSD content (other schemas, configs), and the read itself is an arbitrary-file-access primitive. No flag mitigates it. The attacker controls only the input schema; no authentication or special privileges are required. (Raw bytes of files that are not valid XML are read into the process but not echoed verbatim, since parsing fails; verbatim disclosure applies to XML/XSD-shaped data.) ### Suggested remediation Reject resolved `schemaLocation` targets that are not `resolved.is_relative_to(self.base_path)`, and bring XSD includes under the same remote/external-reference policy enforced for JSON-Schema `$ref`. ### Maintainer status Confirmed by maintainer review and regression tests. The private fix PR was merged and released in `0.62.0`: https://github.com/koxudaxi/datamodel-code-generator-ghsa-442q-2j6p-642g/pull/1 Fix summary: reject XSD `schemaLocation` targets that resolve outside the input base path, including relative traversal and absolute paths. Release status: fixed in `0.62.0`. XML Schema input support was introduced in `0.59.0`, so affected versions are `>= 0.59.0, <= 0.61.0`. Validation: `uv run --group test --extra http pytest tests/main/xmlschema/test_main_xmlschema.py` passed locally; `uv run --group fix ruff check src/datamodel_code_generator/parser/xmlschema.py tests/main/xmlschema/test_main_xmlschema.py` passed. Submitted by: Hamza Haroon (thegr1ffyn)

CVE-2026-55390 Affected Datamodel code generator Versions

1 component(s)
Fixed Versions:
0.62.0
Product / Package Ecosystem Affected Versions Fixed Version
datamodel-code-generator
PyPI
≥ 0.59.0
< 0.62.0
0.62.0

References

Frequently Asked Questions

What is CVE-2026-55390?
CVE-2026-55390 is a security vulnerability in Datamodel code generator involving include`/`xs:import`) path traversal, with no remote-ref gate under CWE-610: Externally Controlled Reference to a Resource in Another Sphere.
Which Datamodel code generator versions are affected?
Affected versions include releases prior to 0.62.0 across affected packages: datamodel-code-generator.
What version fixes CVE-2026-55390?
Upgrading to 0.62.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is datamodel-code-generator affected?
Yes, datamodel-code-generator is affected in releases prior to 0.62.0. Upgrade your dependency to 0.62.0 or later.
What is the CVSS score of CVE-2026-55390?
CVE-2026-55390 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N.
What CWE is associated with CVE-2026-55390?
CVE-2026-55390 is classified under CWE-610: Externally Controlled Reference to a Resource in Another Sphere (The product uses an externally controlled name or reference that resolves to a resource that is outside of the intended control sphere.).
How can I check PyPI dependencies for CVE-2026-55390?
Run the dependency tree command: 'pip show datamodel-code-generator'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-442q-2j6p-642g",
  "modified" : "2026-07-28T21:26:41Z",
  "published" : "2026-07-28T21:26:41Z",
  "aliases" : [ "CVE-2026-55390" ],
  "summary" : "datamodel-code-generator vulnerable to arbitrary local file read via XSD `schemaLocation` (`xs:include`/`xs:import`) path traversal, with no remote-ref gate",
  "details" : "### Summary\n\nWhen generating models from an XML Schema (`--input-file-type xmlschema`), `datamodel-code-generator` resolves `<xs:include>`, `<xs:import>`, `<xs:redefine>`, and `<xs:override>` `schemaLocation` attributes against the source directory and reads the target with no restriction to the input/base directory. An attacker who controls the input XSD can read arbitrary files via `../` traversal or an absolute path, and the included schema's contents (type names, restrictions, enumerations) are folded into the generated output. Unlike the JSON-Schema `$ref` path, there is no `allow_remote_refs` control for XSD, so `--no-allow-remote-refs` does not mitigate it. This is an unauthenticated path-traversal / information-disclosure issue reachable in the default configuration.\n\n### Details\n\nThe XSD parser walks include-style children and reads each `schemaLocation` with only an `is_file()` check (`src/datamodel_code_generator/parser/xmlschema.py`):\n\n```python\nlocation = (source_dir / schema_location).resolve()   # .resolve() collapses ../, escapes base\nif location in seen or not location.is_file():\n    continue\nincluded_root = self._parse_schema(_read_xml_text(location, self.encoding), location)\n```\n\n`schema_location` is attacker-controlled and `_read_xml_text` does `path.read_bytes()`. Because `(source_dir / schema_location).resolve()` normalizes `..` and accepts absolute paths, the resolved target can be any file the process can read; there is no `is_relative_to(base_path)` containment (contrast the JSON-Schema HTTP-local branch, which does enforce it). The same unbounded read occurs both during version detection and during the main include-processing pass, so the included content is incorporated into the generated module.\n\nRelated vectors that were tested and do NOT apply (stdlib `xml.etree.ElementTree` is used): external-entity XXE file read does not occur (ElementTree does not fetch external entities), and entity-expansion \"billion laughs\" is rejected by CPython's expat amplification limit.\n\n### PoC\n\nSelf-contained reproducer (creates a temp dir, runs the generator, cleans up): https://gist.github.com/thegr1ffyn/c7096b797926348875d888652867eeb4  (`poc.py`).\n\nMinimal manual reproduction:\n\n```bash\nmkdir -p /tmp/x/secret /tmp/x/proj\ncat > /tmp/x/secret/leak.xsd <<'EOF'\n<?xml version=\"1.0\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n  <xs:simpleType name=\"LEAK_5150\"><xs:restriction base=\"xs:string\"/></xs:simpleType>\n</xs:schema>\nEOF\ncat > /tmp/x/proj/attack.xsd <<'EOF'\n<?xml version=\"1.0\"?>\n<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\">\n  <xs:include schemaLocation=\"../../x/secret/leak.xsd\"/>\n  <xs:element name=\"Root\" type=\"LEAK_5150\"/>\n</xs:schema>\nEOF\ndatamodel-codegen --input /tmp/x/proj/attack.xsd --input-file-type xmlschema --no-allow-remote-refs --output /tmp/x/out.py\ngrep LEAK_5150 /tmp/x/out.py   # content from outside the project dir appears in generated code\n```\n\nAn absolute `schemaLocation=\"/abs/path/leak.xsd\"` works identically.\n\n### Impact\n\nArbitrary local file read / path traversal (CWE-22) leading to information disclosure (CWE-200). Any application, CI pipeline, or multi-tenant service that generates models from an attacker-supplied XSD and exposes (returns, logs, commits, renders) the generated code is affected. The attacker can read files outside the input tree whose data is addressable as XSD content (other schemas, configs), and the read itself is an arbitrary-file-access primitive. No flag mitigates it. The attacker controls only the input schema; no authentication or special privileges are required. (Raw bytes of files that are not valid XML are read into the process but not echoed verbatim, since parsing fails; verbatim disclosure applies to XML/XSD-shaped data.)\n\n### Suggested remediation\n\nReject resolved `schemaLocation` targets that are not `resolved.is_relative_to(self.base_path)`, and bring XSD includes under the same remote/external-reference policy enforced for JSON-Schema `$ref`.\n\n### Maintainer status\n\nConfirmed by maintainer review and regression tests. The private fix PR was merged and released in `0.62.0`: https://github.com/koxudaxi/datamodel-code-generator-ghsa-442q-2j6p-642g/pull/1\n\nFix summary: reject XSD `schemaLocation` targets that resolve outside the input base path, including relative traversal and absolute paths.\n\nRelease status: fixed in `0.62.0`. XML Schema input support was introduced in `0.59.0`, so affected versions are `>= 0.59.0, <= 0.61.0`.\n\nValidation: `uv run --group test --extra http pytest tests/main/xmlschema/test_main_xmlschema.py` passed locally; `uv run --group fix ruff check src/datamodel_code_generator/parser/xmlschema.py tests/main/xmlschema/test_main_xmlschema.py` passed.\n\nSubmitted by: Hamza Haroon (thegr1ffyn)",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "datamodel-code-generator"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.59.0"
      }, {
        "fixed" : "0.62.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.61.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-442q-2j6p-642g"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/koxudaxi/datamodel-code-generator/commit/d2d5cecd9fd3a2a6dbf148bf0740b83a11fc6820"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/koxudaxi/datamodel-code-generator"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.62.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-200", "CWE-22", "CWE-610" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-07-28T21:26:41Z",
    "nvd_published_at" : null
  }
}