Vulnerabilities in pkg:pypi/datamodel-code-generator

PACKAGE
Advisory Identifier: GHSA-77xj-x4rm-935c
Advisory Summary

CVE-2026-107377 is a HIGH (CVSS 7.5) path traversal vulnerability (CWE-73: External Control of File Name or Path) affecting datamodel-code-generator libraries in the PyPI ecosystem. The issue involves protobuf weak-import path traversal allows files to be written outside the temporary directory. Remediation is available by upgrading affected packages to version 0.81.0.

13 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/datamodel-code-generator

13 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/datamodel-code-generator. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-77xj-x4rm-935c CVE-2026-107377 HIGH datamodel-code-generator: Protobuf weak-import path traversal allows files to be written outside the temporary directory
GHSA-wjv6-jcfj-mf9r CVE-2026-54654 HIGH `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in `--extra-template-data` `comment` field
GHSA-8359-h9fx-j6v9 CVE-2026-55389 HIGH datamodel-code-generator vulnerable to arbitrary local file read via JSON-Schema `$ref` (`file://` and `../` traversal), bypassing `--no-allow-remote-refs`
GHSA-386q-5hp3-95m9 CVE-2026-54653 HIGH `datamodel-code-generator` vulnerable to code injection in via attacker-controlled `default_factory` schema field
GHSA-vx7x-vcc2-c44g CVE-2026-55391 HIGH datamodel-code-generator vulnerable to SSRF protection bypass via DNS rebinding
GHSA-8m8r-38jm-f355 CVE-2026-54656 HIGH `datamodel-code-generator` vulnerable to code execution on import via unescaped `validators` entries in --extra-template-data
GHSA-954p-556p-r752 CVE-2026-54690 HIGH datamodel-code-generator vulnerable to SSRF via JSON-Schema `$ref` to HTTP URL (silent by default)
GHSA-5578-w22f-pfx9 CVE-2026-55415 HIGH datamodel-code-generator vulnerable to code injection via `x-python-import` / `customTypePath` in generated import statements
GHSA-j884-q54q-mmx3 CVE-2026-54621 HIGH `datamodel-code-generator` vulnerable to code injection via unescaped carriage return in GraphQL Union description
GHSA-m34r-v34r-rf9q CVE-2026-54655 HIGH `datamodel-code-generator` vulnerable to code execution on import via `x-python-type` JSON-Schema extension in datamodel-code-generator
GHSA-r5vv-ff45-prp2 CVE-2026-55403 LOW datamodel-code-generator: Authorization / request headers leaked to cross-origin redirect target when fetching remote schemas
GHSA-rfr2-mq9m-x2qx CVE-2026-54691 HIGH datamodel-code-generator vulnerable to SSRF via --url: no host/IP validation, follows redirects
GHSA-442q-2j6p-642g CVE-2026-55390 HIGH datamodel-code-generator vulnerable to arbitrary local file read via XSD `schemaLocation` (`xs:include`/`xs:import`) path traversal, with no remote-ref gate

CVE-2026-107377 at a Glance

CVE Identifier CVE-2026-107377
GHSA Identifier GHSA-77xj-x4rm-935c
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-73: External Control of File Name or Path
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:N/I:H/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 None (C:N)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2026-107377

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.81.0
pip install datamodel-code-generator>=0.81.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-107377, 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.81.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-73: External Control of File Name or Path, where the product allows user input to control or influence paths or file names that are used in filesystem operations. 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 processing an attacker-controlled Protobuf schema, vulnerable versions of `datamodel-code-generator` could write a generated weak-import stub outside the intended `__weak_imports__` temporary directory. Absolute import paths and relative paths containing `..` could escape this directory. An attacker could create directories and new files at locations writable by the process. Relative path traversal could also overwrite existing writable files because the existence check and the stub write used different base directories. An existing absolute target was skipped by the existence check. Written content was limited to a generated Protobuf syntax declaration, `syntax = "proto2";` or `syntax = "proto3";`, followed by a newline. This issue did not provide fully attacker-controlled file contents, and direct arbitrary code execution has not been demonstrated. These filesystem side effects occurred before `protoc` ran. A subsequent compilation error did not undo them. A user or CI job must process the attacker-controlled schema for the issue to be triggered, whether the schema is supplied as a local file or fetched via `--url`. The fix has been merged into the parent repository's `main` branch in [5e94b8f](https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc). A patched package release is not yet available. The technical details and PoC below describe the vulnerable implementation before that fix. ## Affected component - Repository: `datamodel-code-generator/datamodel-code-generator` (formerly `koxudaxi/datamodel-code-generator`). - Analyzed at: released **0.80.0** (`pip install datamodel-code-generator==0.80.0`) and `main` @ commit `834731d56c0a90c182a0919f316069cf5ff0659a` (2026-09-13). Both contained the identical vulnerable sink. - Sink / entry point (`src/datamodel_code_generator/parser/protobuf.py`, line numbers from 0.80.0): - Source: `WEAK_IMPORT_PATTERN` (`protobuf.py:37`) — attacker-controlled capture group. - Sink: `_write_missing_weak_imports` (`protobuf.py:391-393`) — `weak_import_dir / import_path` + `mkdir(parents=True)` + `write_text`. - Timing: called from `_ProtoInputPreparer.__enter__` (`protobuf.py:333`), before `protoc.main(...)` runs inside the `with` body. - Preconditions: victim runs the tool (CLI or Python API) with `--input-file-type protobuf` on an attacker-controlled `.proto`, supplied as a local file (`--input`) or a remote URL (`--url`). Requires the `grpcio-tools` package (Protobuf support). The attacker does not need privileges on the affected system; filesystem effects are limited to locations writable by the code-generation process. ## Severity Proposed: **High**. `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N` = **7.5**. - Scored to match the project's own rating of the sibling path-traversal advisories CVE-2026-55389 / CVE-2026-55390, both `AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N` = 7.5. This finding is the same attack surface (unvalidated path from a processed schema) with the impact moved from confidentiality (read) to **integrity (write)**, hence `C:N/I:H`. - `AV:N`: the malicious schema can be fetched over the network via `--url`, consistent with how the siblings were scored. - `I:H`: attacker fully controls the write path and can create arbitrary directory trees and overwrite existing files; only the file *content* is constrained (a fixed `syntax = "proto{2,3}";` line). - `A:N` chosen conservatively; overwriting build-critical files (lock files, `__init__.py`, entry points) can cause availability loss, which would argue `A:L`. - Honest alternative: if the reviewer treats "the victim must run the tool on the file" as user interaction (`UI:R`), the score is **6.5 (Moderate)**. The project used `UI:N` for the identical read-path siblings, so `UI:N` is used here for consistency. ## Details Source pattern — the imported path is captured with no character restriction: ```python # protobuf.py:37 WEAK_IMPORT_PATTERN = re.compile(r'^\s*import\s+weak\s+"([^"]+)"\s*;', re.MULTILINE) ``` Sink — the captured path is joined and written with no boundary check: ```python # protobuf.py:383-393 (_write_missing_weak_imports) for import_path in WEAK_IMPORT_PATTERN.findall(text): if any((include_path / import_path).exists() for include_path in include_paths): continue stub = self.weak_import_dir / import_path # no resolve(), no is_relative_to() stub.parent.mkdir(parents=True, exist_ok=True) # arbitrary directory tree stub.write_text(syntax, encoding=self.parser.encoding) ``` Two escape mechanisms, both from `pathlib`'s `/` semantics: - **Absolute path**: `Path(".../__weak_imports__") / "/etc/x"` == `/etc/x` (an absolute right operand replaces the base). Creates new files anywhere the process can write. - **`../` traversal**: `Path(".../__weak_imports__") / "../../x"` climbs out of the temp directory. Why the existence guard (line 389) does not protect the write: it checks `include_path / import_path`, using a **different base** (`include_paths`) than the actual write, which uses `self.weak_import_dir / import_path`. For a *relative* path the two bases resolve to different directories, so the guard checks a location that is not the real write target and misses it — enabling **overwrite of existing files**. (For an absolute path the guard and the write coincide, so an already- existing absolute target is skipped; absolute paths thus create new files but do not overwrite. Overwrite is reached via the relative-traversal path.) Timing: `_write_missing_weak_imports` runs inside `__enter__` (line 333), and `protoc.main(...)` runs later in the `with` body. `protoc` rejects the malformed virtual path (`Backslashes, consecutive slashes, "." or ".." are not allowed in the virtual path`) and the overall command exits non-zero — but the file has already been written; the filesystem side effect is not rolled back. ### Attack path 1. Attacker crafts `evil.proto` containing e.g. `import weak "/home/victim/.config/x";` and/or `import weak "../../overwrite_me.txt";`, and gets the victim to process it (third-party schema, or `--url` to an attacker-hosted file). 2. `_write_missing_weak_imports` writes the stub to the attacker-chosen path, creating any intermediate directories and overwriting an existing file (relative case). 3. `protoc` then fails, but the file(s) are already on disk. ## Proof of Concept Two self-contained scripts (`poc/reproduce.sh` for `--input`, `poc/reproduce-url.sh` for `--url`) install the released `datamodel-code-generator==0.80.0`, serve/point a malicious `.proto`, and assert the writes. The PoC drives the **released** package unmodified; the sink file's sha256 is recorded in `REPRODUCE.md`. Local `--input` run against 0.80.0 — real output: ``` [*] installed version: 0.80.0 [test A] absolute-path arbitrary file + mkdir(parents): [PASS] new file created at attacker-controlled absolute path [PASS] content is the fixed syntax stub [test B] relative-traversal overwrite of pre-existing file: [PASS] pre-existing victim.txt content was overwritten [PASS] victim.txt now holds the injected stub ==================== RESULT: 4 passed, 0 failed ==================== ``` Remote `--url` run against 0.80.0 — real output (proto served over HTTP, then the same writes fire): ``` [*] serving malicious proto at http://127.0.0.1:<port>/evil_url.proto [PASS] server actually served the proto (HTTP 200) [PASS] absolute-path arbitrary file created [PASS] pre-existing victim overwritten via ../ ==================== RESULT: 3 passed, 0 failed ==================== ``` ## Impact Any user or CI pipeline that runs an affected version of `datamodel-code-generator` on an untrusted Protobuf schema (a downloaded third-party `.proto`, or `--url` to a remote source) is exposed to arbitrary file/directory creation and overwrite by the schema author, with the process's own permissions. Concrete harms: - Overwrite source, config, `.env`, lock files, or `__init__.py` / entry-point files → project corruption, broken builds, denial of service. - Create arbitrary directory trees / drop files into watched or auto-loaded locations. Direct arbitrary code execution has not been demonstrated. The written content is limited to a generated `syntax = "proto2";` or `syntax = "proto3";` line and is not fully attacker-controlled. ## Resolution The fix was merged into the parent repository's `main` branch in [5e94b8f](https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc). The Protobuf input preparer now resolves the dedicated temporary weak-import directory and each candidate stub path. If a resolved candidate is outside that directory, it raises `SchemaParseError` before checking include paths, creating parent directories, or writing the stub. The containment check rejects absolute-path escapes and relative `..` traversal that would leave the sandbox. Input-preparation failures also immediately clean up the temporary directory. Regression tests cover: - rejection of absolute weak-import paths outside the sandbox; - rejection of relative `..` traversal outside the sandbox; - preservation of a pre-existing file outside the sandbox. Local tox validation of the patch passed across the Python 3.10–3.14 and formatter matrix, the CI compatibility environments, and the repository checks. Combined line and branch coverage, including the changed files, reached 100%. A fixed package has not yet been published to PyPI; the latest published version at the time of this update is 0.80.0. `Patched versions` remains unset until a release containing this fix is available. The advisory remains private pending that release. ## References - GHSA-8359-h9fx-j6v9 / CVE-2026-55389 — datamodel-code-generator arbitrary local file **read** via JSON-Schema `$ref` path traversal (CWE-22/200/610, 7.5, patched 0.62.0). Same class, read primitive; sibling entry point. - GHSA-442q-2j6p-642g / CVE-2026-55390 — datamodel-code-generator arbitrary local file **read** via XSD `schemaLocation` path traversal (CWE-22/200/610, 7.5, affected `>= 0.59.0, <= 0.61.0`, patched 0.62.0). Same class, read primitive; the fix sweep that missed the Protobuf entry point. - Python `pathlib` — `PurePath.__truediv__`: an absolute right-hand operand discards the left operand; `..` segments are not normalized. (https://docs.python.org/3/library/pathlib.html) ## Discovery Found via source review and a reproducing PoC on `datamodel-code-generator/datamodel-code-generator`, released 0.80.0 and `main` @ `834731d56c0a90c182a0919f316069cf5ff0659a`, 2026-09.

CVE-2026-107377 Affected datamodel-code-generator Versions

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

References

Frequently Asked Questions

What is CVE-2026-107377?
CVE-2026-107377 is a security vulnerability in datamodel-code-generator involving Protobuf weak-import path traversal allows files to be written outside the temporary directory under CWE-73: External Control of File Name or Path.
Which datamodel-code-generator versions are affected?
Affected versions include releases prior to 0.81.0 across affected packages: datamodel-code-generator.
What version fixes CVE-2026-107377?
Upgrading to 0.81.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.81.0. Upgrade your dependency to 0.81.0 or later.
What is the CVSS score of CVE-2026-107377?
CVE-2026-107377 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:N/I:H/A:N.
What CWE is associated with CVE-2026-107377?
CVE-2026-107377 is classified under CWE-73: External Control of File Name or Path (The product allows user input to control or influence paths or file names that are used in filesystem operations.).
How can I check PyPI dependencies for CVE-2026-107377?
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-77xj-x4rm-935c",
  "modified" : "2026-10-08T17:58:01Z",
  "published" : "2026-10-08T17:58:01Z",
  "aliases" : [ "CVE-2026-107377" ],
  "summary" : "datamodel-code-generator: Protobuf weak-import path traversal allows files to be written outside the temporary directory",
  "details" : "## Summary\n\nWhen processing an attacker-controlled Protobuf schema, vulnerable versions of\n`datamodel-code-generator` could write a generated weak-import stub outside the\nintended `__weak_imports__` temporary directory. Absolute import paths and relative\npaths containing `..` could escape this directory.\n\nAn attacker could create directories and new files at locations writable by the\nprocess. Relative path traversal could also overwrite existing writable files\nbecause the existence check and the stub write used different base directories.\nAn existing absolute target was skipped by the existence check.\n\nWritten content was limited to a generated Protobuf syntax declaration,\n`syntax = \"proto2\";` or `syntax = \"proto3\";`, followed by a newline. This issue did\nnot provide fully attacker-controlled file contents, and direct arbitrary code\nexecution has not been demonstrated.\n\nThese filesystem side effects occurred before `protoc` ran. A subsequent\ncompilation error did not undo them. A user or CI job must process the\nattacker-controlled schema for the issue to be triggered, whether the schema is\nsupplied as a local file or fetched via `--url`.\n\nThe fix has been merged into the parent repository's `main` branch in\n[5e94b8f](https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc). A patched package release is not yet available.\nThe technical details and PoC below describe the vulnerable implementation before\nthat fix.\n\n## Affected component\n\n- Repository: `datamodel-code-generator/datamodel-code-generator` (formerly `koxudaxi/datamodel-code-generator`).\n- Analyzed at: released **0.80.0** (`pip install datamodel-code-generator==0.80.0`) and `main` @ commit `834731d56c0a90c182a0919f316069cf5ff0659a` (2026-09-13). Both contained the identical vulnerable sink.\n- Sink / entry point (`src/datamodel_code_generator/parser/protobuf.py`, line numbers from 0.80.0):\n  - Source: `WEAK_IMPORT_PATTERN` (`protobuf.py:37`) — attacker-controlled capture group.\n  - Sink: `_write_missing_weak_imports` (`protobuf.py:391-393`) — `weak_import_dir / import_path` + `mkdir(parents=True)` + `write_text`.\n  - Timing: called from `_ProtoInputPreparer.__enter__` (`protobuf.py:333`), before `protoc.main(...)` runs inside the `with` body.\n- Preconditions: victim runs the tool (CLI or Python API) with `--input-file-type protobuf` on an attacker-controlled `.proto`, supplied as a local file (`--input`) or a remote URL (`--url`). Requires the `grpcio-tools` package (Protobuf support). The attacker does not need privileges on the affected system; filesystem effects are limited to locations writable by the code-generation process.\n\n## Severity\n\nProposed: **High**. `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N` = **7.5**.\n\n- Scored to match the project's own rating of the sibling path-traversal advisories CVE-2026-55389 / CVE-2026-55390, both `AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N` = 7.5. This finding is the same attack surface (unvalidated path from a processed schema) with the impact moved from confidentiality (read) to **integrity (write)**, hence `C:N/I:H`.\n- `AV:N`: the malicious schema can be fetched over the network via `--url`, consistent with how the siblings were scored.\n- `I:H`: attacker fully controls the write path and can create arbitrary directory trees and overwrite existing files; only the file *content* is constrained (a fixed `syntax = \"proto{2,3}\";` line).\n- `A:N` chosen conservatively; overwriting build-critical files (lock files, `__init__.py`, entry points) can cause availability loss, which would argue `A:L`.\n- Honest alternative: if the reviewer treats \"the victim must run the tool on the file\" as user interaction (`UI:R`), the score is **6.5 (Moderate)**. The project used `UI:N` for the identical read-path siblings, so `UI:N` is used here for consistency.\n\n## Details\n\nSource pattern — the imported path is captured with no character restriction:\n\n```python\n# protobuf.py:37\nWEAK_IMPORT_PATTERN = re.compile(r'^\\s*import\\s+weak\\s+\"([^\"]+)\"\\s*;', re.MULTILINE)\n```\n\nSink — the captured path is joined and written with no boundary check:\n\n```python\n# protobuf.py:383-393  (_write_missing_weak_imports)\nfor import_path in WEAK_IMPORT_PATTERN.findall(text):\n    if any((include_path / import_path).exists() for include_path in include_paths):\n        continue\n    stub = self.weak_import_dir / import_path        # no resolve(), no is_relative_to()\n    stub.parent.mkdir(parents=True, exist_ok=True)   # arbitrary directory tree\n    stub.write_text(syntax, encoding=self.parser.encoding)\n```\n\nTwo escape mechanisms, both from `pathlib`'s `/` semantics:\n\n- **Absolute path**: `Path(\".../__weak_imports__\") / \"/etc/x\"` == `/etc/x` (an absolute\n  right operand replaces the base). Creates new files anywhere the process can write.\n- **`../` traversal**: `Path(\".../__weak_imports__\") / \"../../x\"` climbs out of the\n  temp directory.\n\nWhy the existence guard (line 389) does not protect the write: it checks\n`include_path / import_path`, using a **different base** (`include_paths`) than the\nactual write, which uses `self.weak_import_dir / import_path`. For a *relative*\npath the two bases resolve to different directories, so the guard checks a location\nthat is not the real write target and misses it — enabling **overwrite of existing\nfiles**. (For an absolute path the guard and the write coincide, so an already-\nexisting absolute target is skipped; absolute paths thus create new files but do not\noverwrite. Overwrite is reached via the relative-traversal path.)\n\nTiming: `_write_missing_weak_imports` runs inside `__enter__` (line 333), and\n`protoc.main(...)` runs later in the `with` body. `protoc` rejects the malformed\nvirtual path (`Backslashes, consecutive slashes, \".\" or \"..\" are not allowed in\nthe virtual path`) and the overall command exits non-zero — but the file has\nalready been written; the filesystem side effect is not rolled back.\n\n### Attack path\n\n1. Attacker crafts `evil.proto` containing e.g. `import weak \"/home/victim/.config/x\";`\n   and/or `import weak \"../../overwrite_me.txt\";`, and gets the victim to process it\n   (third-party schema, or `--url` to an attacker-hosted file).\n2. `_write_missing_weak_imports` writes the stub to the attacker-chosen path,\n   creating any intermediate directories and overwriting an existing file (relative\n   case).\n3. `protoc` then fails, but the file(s) are already on disk.\n\n## Proof of Concept\n\nTwo self-contained scripts (`poc/reproduce.sh` for `--input`, `poc/reproduce-url.sh`\nfor `--url`) install the released `datamodel-code-generator==0.80.0`, serve/point a\nmalicious `.proto`, and assert the writes. The PoC drives the **released** package\nunmodified; the sink file's sha256 is recorded in `REPRODUCE.md`.\n\nLocal `--input` run against 0.80.0 — real output:\n\n```\n[*] installed version: 0.80.0\n[test A] absolute-path arbitrary file + mkdir(parents):\n  [PASS] new file created at attacker-controlled absolute path\n  [PASS] content is the fixed syntax stub\n[test B] relative-traversal overwrite of pre-existing file:\n  [PASS] pre-existing victim.txt content was overwritten\n  [PASS] victim.txt now holds the injected stub\n==================== RESULT: 4 passed, 0 failed ====================\n```\n\nRemote `--url` run against 0.80.0 — real output (proto served over HTTP, then the\nsame writes fire):\n\n```\n[*] serving malicious proto at http://127.0.0.1:<port>/evil_url.proto\n  [PASS] server actually served the proto (HTTP 200)\n  [PASS] absolute-path arbitrary file created\n  [PASS] pre-existing victim overwritten via ../\n==================== RESULT: 3 passed, 0 failed ====================\n```\n\n## Impact\n\nAny user or CI pipeline that runs an affected version of\n`datamodel-code-generator` on an untrusted\nProtobuf schema (a downloaded third-party `.proto`, or `--url` to a remote source)\nis exposed to arbitrary file/directory creation and overwrite by the schema author,\nwith the process's own permissions. Concrete harms:\n\n- Overwrite source, config, `.env`, lock files, or `__init__.py` / entry-point\n  files → project corruption, broken builds, denial of service.\n- Create arbitrary directory trees / drop files into watched or auto-loaded\n  locations.\n\nDirect arbitrary code execution has not been demonstrated. The written content\nis limited to a generated `syntax = \"proto2\";` or `syntax = \"proto3\";` line and is\nnot fully attacker-controlled.\n\n## Resolution\n\nThe fix was merged into the parent repository's `main` branch in\n[5e94b8f](https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc).\n\nThe Protobuf input preparer now resolves the dedicated temporary weak-import\ndirectory and each candidate stub path. If a resolved candidate is outside that\ndirectory, it raises `SchemaParseError` before checking include paths, creating\nparent directories, or writing the stub. The containment check rejects\nabsolute-path escapes and relative `..` traversal that would leave the sandbox.\n\nInput-preparation failures also immediately clean up the temporary directory.\n\nRegression tests cover:\n\n- rejection of absolute weak-import paths outside the sandbox;\n- rejection of relative `..` traversal outside the sandbox;\n- preservation of a pre-existing file outside the sandbox.\n\nLocal tox validation of the patch passed across the Python 3.10–3.14 and formatter\nmatrix, the CI compatibility environments, and the repository checks. Combined\nline and branch coverage, including the changed files, reached 100%.\n\nA fixed package has not yet been published to PyPI; the latest published version\nat the time of this update is 0.80.0. `Patched versions` remains unset until a\nrelease containing this fix is available. The advisory remains private pending\nthat release.\n\n## References\n\n- GHSA-8359-h9fx-j6v9 / CVE-2026-55389 — datamodel-code-generator arbitrary local file **read** via JSON-Schema `$ref` path traversal (CWE-22/200/610, 7.5, patched 0.62.0). Same class, read primitive; sibling entry point.\n- GHSA-442q-2j6p-642g / CVE-2026-55390 — datamodel-code-generator arbitrary local file **read** via XSD `schemaLocation` path traversal (CWE-22/200/610, 7.5, affected `>= 0.59.0, <= 0.61.0`, patched 0.62.0). Same class, read primitive; the fix sweep that missed the Protobuf entry point.\n- Python `pathlib` — `PurePath.__truediv__`: an absolute right-hand operand discards the left operand; `..` segments are not normalized. (https://docs.python.org/3/library/pathlib.html)\n\n## Discovery\n\nFound via source review and a reproducing PoC on\n`datamodel-code-generator/datamodel-code-generator`, released 0.80.0 and `main` @\n`834731d56c0a90c182a0919f316069cf5ff0659a`, 2026-09.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "datamodel-code-generator"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.59.0"
      }, {
        "fixed" : "0.81.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.80.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/datamodel-code-generator/datamodel-code-generator/security/advisories/GHSA-77xj-x4rm-935c"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/datamodel-code-generator/datamodel-code-generator"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/datamodel-code-generator/datamodel-code-generator/releases/tag/0.81.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22", "CWE-73" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-10-08T17:58:01Z",
    "nvd_published_at" : null
  }
}