GitHub advisory · PyPI
datamodel-code-generator: Protobuf weak-import path traversal allows files to be written outside the temporary directory
Description
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.
datamodel-code-generator/datamodel-code-generator (formerly koxudaxi/datamodel-code-generator).pip install datamodel-code-generator==0.80.0) and main @ commit 834731d56c0a90c182a0919f316069cf5ff0659a (2026-09-13). Both contained the identical vulnerable sink.src/datamodel_code_generator/parser/protobuf.py, line numbers from 0.80.0):
WEAK_IMPORT_PATTERN (protobuf.py:37) —…Manual fix · PyPI
pip install --upgrade "datamodel-code-generator>=0.81.0"Sources