/

CVE-2026-55390

Severity:

HIGH RISK

(7.5)

XML Schema path traversal (CWE-22) in code generator

CVE-2026-55390

Deferred

Vulnerability type

Category:

Path Traversal / External Entity Inclusion

CWE:

CWE-22, CWE-200, CWE-610

Impact:

Local File Disclosure via Code Generation

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

XML Schema parsing in datamodel-code-generator follows schemaLocation references outside the intended base path, enabling unauthorized local file reads during model generation.

When attackers can influence XML Schema inputs or referenced locations, they may exfiltrate local file contents into the generated Python models.

XML Schema parsing in datamodel-code-generator follows schemaLocation references outside the intended base path, enabling unauthorized local file reads during model generation.

When attackers can influence XML Schema inputs or referenced locations, they may exfiltrate local file contents into the generated Python models.

Affected context

This vulnerability affects projects that use datamodel-code-generator with --input-file-type xmlschema to generate Python models from XML Schema definitions.

Risk arises when the tool processes schemas containing xs:include, xs:import, xs:redefine, or xs:override with attacker-controlled or untrusted schemaLocation values.

The issue appears in environments where the generator runs on machines that store sensitive files accessible via the same filesystem, and where generated models can be inspected or exfiltrated.

This vulnerability affects projects that use datamodel-code-generator with --input-file-type xmlschema to generate Python models from XML Schema definitions.

Risk arises when the tool processes schemas containing xs:include, xs:import, xs:redefine, or xs:override with attacker-controlled or untrusted schemaLocation values.

The issue appears in environments where the generator runs on machines that store sensitive files accessible via the same filesystem, and where generated models can be inspected or exfiltrated.

Exploit preconditions

  • Attack surface: The XML Schema input and any referenced XSDs used by datamodel-code-generator.
  • Required access: Ability to supply or modify an XML Schema, or to influence schemaLocation values in referenced schema files.
  • Trigger point: Running datamodel-code-generator with --input-file-type xmlschema so that the parser resolves xs:include, xs:import, xs:redefine, or xs:override.
  • Why exploitation is possible: The XML Schema parser resolves schemaLocation paths without constraining them to the original input base directory, enabling traversal to arbitrary readable files whose contents can be reflected into the generated code.
  • Attack surface: The XML Schema input and any referenced XSDs used by datamodel-code-generator.
  • Required access: Ability to supply or modify an XML Schema, or to influence schemaLocation values in referenced schema files.
  • Trigger point: Running datamodel-code-generator with --input-file-type xmlschema so that the parser resolves xs:include, xs:import, xs:redefine, or xs:override.
  • Why exploitation is possible: The XML Schema parser resolves schemaLocation paths without constraining them to the original input base directory, enabling traversal to arbitrary readable files whose contents can be reflected into the generated code.

Why this happens

The root cause is insufficient validation and restriction of filesystem paths when resolving XML Schema schemaLocation references.

Instead of enforcing a strict base directory or whitelist, the parser in xmlschema.py allows xs:include, xs:import, xs:redefine, and xs:override to point to locations outside the input base path.

This behavior aligns with CWE-22 (Path Traversal) and CWE-610 (Externally Controlled Reference to a Resource in Another Sphere), as untrusted schema inputs control which local resources are loaded, leading to CWE-200 (Information Exposure) when file contents are echoed into generated models.

The root cause is insufficient validation and restriction of filesystem paths when resolving XML Schema schemaLocation references.

Instead of enforcing a strict base directory or whitelist, the parser in xmlschema.py allows xs:include, xs:import, xs:redefine, and xs:override to point to locations outside the input base path.

This behavior aligns with CWE-22 (Path Traversal) and CWE-610 (Externally Controlled Reference to a Resource in Another Sphere), as untrusted schema inputs control which local resources are loaded, leading to CWE-200 (Information Exposure) when file contents are echoed into generated models.

Potential impact

  • Local filesystem disclosure of readable files accessible to the code generation process
  • Exposure of configuration files, API keys, or secrets embedded in local resources
  • Leakage of proprietary schemas, internal libraries, or business logic via generated models
  • Contamination of generated code with unexpected or maliciously crafted structures derived from sensitive files
  • Local filesystem disclosure of readable files accessible to the code generation process
  • Exposure of configuration files, API keys, or secrets embedded in local resources
  • Leakage of proprietary schemas, internal libraries, or business logic via generated models
  • Contamination of generated code with unexpected or maliciously crafted structures derived from sensitive files

General mitigation guidance

Effective mitigation focuses on tightening trust boundaries around XML Schema resolution and file access during code generation.

Recommended high-level patterns include:

  • Restricting schema resolution to a fixed, whitelisted base directory or virtualized schema store.
  • Normalizing and validating all schemaLocation paths before use, rejecting paths that escape the allowed root.
  • Treating XML Schema inputs as untrusted and avoiding running the generator on attacker-controlled schemas in sensitive environments.
  • Running datamodel-code-generator with least-privilege filesystem access, limiting read permissions to only the directories required for code generation.
  • Applying defense-in-depth by separating build infrastructure from systems that store high-value secrets or configuration files.

Effective mitigation focuses on tightening trust boundaries around XML Schema resolution and file access during code generation.

Recommended high-level patterns include:

  • Restricting schema resolution to a fixed, whitelisted base directory or virtualized schema store.
  • Normalizing and validating all schemaLocation paths before use, rejecting paths that escape the allowed root.
  • Treating XML Schema inputs as untrusted and avoiding running the generator on attacker-controlled schemas in sensitive environments.
  • Running datamodel-code-generator with least-privilege filesystem access, limiting read permissions to only the directories required for code generation.
  • Applying defense-in-depth by separating build infrastructure from systems that store high-value secrets or configuration files.

How teams detect issues like this

Detection can focus on both code-level patterns and build-time behavior:

  • Static analysis and code review:
  • Look for XML Schema parsing code that directly resolves schemaLocation values to the local filesystem without base-path checks.
  • Flag uses of generic file-loading logic in schema resolvers that lack canonicalization and path validation.
  • Policy and pipeline enforcement:
  • Enforce CI/CD policies that disallow running code generators against untrusted or user-supplied XML Schemas.
  • Add checks that ensure schema directories and resolution roots are explicitly configured and reviewed.
  • Runtime and operational monitoring:
  • Monitor build agents for unusual file access patterns during code generation, such as reads from system directories or secret paths.
  • Use file access auditing on build hosts to detect generators reading outside expected schema directories.

Automated SAST or build security tools can be configured to highlight unrestricted resource resolution patterns in code generation utilities.

Detection can focus on both code-level patterns and build-time behavior:

  • Static analysis and code review:
  • Look for XML Schema parsing code that directly resolves schemaLocation values to the local filesystem without base-path checks.
  • Flag uses of generic file-loading logic in schema resolvers that lack canonicalization and path validation.
  • Policy and pipeline enforcement:
  • Enforce CI/CD policies that disallow running code generators against untrusted or user-supplied XML Schemas.
  • Add checks that ensure schema directories and resolution roots are explicitly configured and reviewed.
  • Runtime and operational monitoring:
  • Monitor build agents for unusual file access patterns during code generation, such as reads from system directories or secret paths.
  • Use file access auditing on build hosts to detect generators reading outside expected schema directories.

Automated SAST or build security tools can be configured to highlight unrestricted resource resolution patterns in code generation utilities.

Sources

SourceLink
github.comgithub.com/koxudaxi/datamodel-code-generator/commit/d2d5cecd9fd3a2a6dbf148bf0740b83a11fc6820
github.comgithub.com/koxudaxi/datamodel-code-generator/releases/tag/0.62.0
github.comgithub.com/koxudaxi/datamodel-code-generator/security/advisories/GHSA-442q-2j6p-642g

Frequently asked

questions

It can be indirectly exploitable if an attacker can remotely supply or modify XML Schemas consumed by the build or code generation pipeline. In such setups, a remote actor could cause local file disclosure on the system running the generator.

The attacker must be able to influence the XML Schema or referenced XSD files, particularly their schemaLocation attributes. This could occur through exposed upload endpoints, SCM contributions, or any workflow that accepts untrusted schemas into the generation process.

Constrain schema resolution to a known base directory, normalize and validate all paths, and reject any reference that attempts to traverse outside allowed locations. Combine this with running the generator under an account that has read access only to the necessary schema directories.

Treat all schemas and configuration files as untrusted inputs, enforce strict path validation for any file referenced from them, and design build pipelines so that code generators operate in tightly scoped, least-privilege environments. Regularly review tooling that resolves external resources and integrate security checks into CI to catch unsafe resolution patterns early.

It can be indirectly exploitable if an attacker can remotely supply or modify XML Schemas consumed by the build or code generation pipeline. In such setups, a remote actor could cause local file disclosure on the system running the generator.

The attacker must be able to influence the XML Schema or referenced XSD files, particularly their schemaLocation attributes. This could occur through exposed upload endpoints, SCM contributions, or any workflow that accepts untrusted schemas into the generation process.

Constrain schema resolution to a known base directory, normalize and validate all paths, and reject any reference that attempts to traverse outside allowed locations. Combine this with running the generator under an account that has read access only to the necessary schema directories.

Treat all schemas and configuration files as untrusted inputs, enforce strict path validation for any file referenced from them, and design build pipelines so that code generators operate in tightly scoped, least-privilege environments. Regularly review tooling that resolves external resources and integrate security checks into CI to catch unsafe resolution patterns early.

Find out what's already
exploitable in your codebase.