Résumé
datamodel-code-generator: Protobuf weak-import path traversal allows files to be written outside the temporary directory
Détails de l’avis
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. 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(formerlykoxudaxi/datamodel-code-generator). - Analyzed at: released 0.80.0 (
pip install datamodel-code-generator==0.80.0) andmain@ commit834731d56c0a90c182a0919f316069cf5ff0659a(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), beforeprotoc.main(...)runs inside thewithbody.
- Source:
- Preconditions: victim runs the tool (CLI or Python API) with
--input-file-type protobufon an attacker-controlled.proto, supplied as a local file (--input) or a remote URL (--url). Requires thegrpcio-toolspackage (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), henceC: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 fixedsyntax = "proto{2,3}";line).A:Nchosen conservatively; overwriting build-critical files (lock files,__init__.py, entry points) can cause availability loss, which would argueA: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 usedUI:Nfor the identical read-path siblings, soUI:Nis used here for consistency.
Details
Source pattern — the imported path is captured with no character restriction:
# 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:
# 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
- Attacker crafts
evil.protocontaining e.g.import weak "/home/victim/.config/x";and/orimport weak "../../overwrite_me.txt";, and gets the victim to process it (third-party schema, or--urlto an attacker-hosted file). _write_missing_weak_importswrites the stub to the attacker-chosen path, creating any intermediate directories and overwriting an existing file (relative case).protocthen 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:
Références
- https://github.com/advisories/GHSA-77xj-x4rm-935c
- https://github.com/datamodel-code-generator/datamodel-code-generator/security/advisories/GHSA-77xj-x4rm-935c
- https://github.com/datamodel-code-generator/datamodel-code-generator/commit/5e94b8f4203198798ec66b8e48217f70af69a0dc
- https://github.com/datamodel-code-generator/datamodel-code-generator/releases/tag/0.81.0
Vulnérabilités liées
Tout Supply chain →- MEDIUMCVE-2026-60089
PraisonAI: Project config can auto-save agent output outside the project root
- HIGHCVE-2026-105744
Docling has arbitrary file read/write (and command execution when shell-escape is enabled) when rendering untrusted TikZ with the opt-in Tectonic engine
- HIGHCVE-2026-105865
Payload: Incomplete validation during the upload file lifecycle
- MEDIUMCVE-2026-105676
Ghost: Path Traversal via Locale Setting
- MEDIUMCVE-2026-106559
Backstage: Improper input validation in Confluence to Markdown scaffolder module
- MEDIUMCVE-2026-106494
Backstage: Improper input validation in cloud storage URL readers