{"id":2497,"cve":"CVE-2026-107377","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-107377\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":7.5,"published":"2026-10-08","owasp":"A04 Insecure Design","odc":"Assignment","cdc":"Missing Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Path traversal in Protobuf schema allows file creation\/overwrite (weak_imports).","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-107377\/","description":"datamodel-code-generator generates Python data models from schema definitions. From 0.59.0 until 0.81.0, an attacker-controlled Protobuf schema can supply absolute or parent-directory paths captured by WEAK_IMPORT_PATTERN and consumed by _write_missing_weak_imports in src\/datamodel_code_generator\/parser\/protobuf.py. Exploitation requires a victim or automated job to process the attacker-controlled schema with Protobuf input support, which requires the grpcio-tools package. The paths escape the weak_imports temporary directory before protoc runs, allowing creation of directory trees and new files or overwrite of existing writable files with a generated Protobuf syntax declaration. The effect persists when later Protobuf compilation fails. The written content is limited to a proto2 or proto3 syntax declaration, and direct arbitrary code execution has not been demonstrated. This issue is fixed in version 0.81.0.","solution":"Upgrade\u202fdatamodel-code-generator\u202fto version\u202f0.81.0\u202for newer.","affected_component":"datamodel-code-generator","fixed_by_upgrading":true,"vulnerable_code":"import os\nimport tempfile\n\ndef _write_missing_weak_imports(imports):\n    \"\"\"\n    Write placeholder proto files for missing imports into a temporary\n    directory used by the protobuf compiler.\n    \"\"\"\n    weak_dir = tempfile.mkdtemp(prefix=\"weak_imports_\")\n    for imp in imports:\n        # VULNERABLE: path traversal via unvalidated import path\n        dest_path = os.path.join(weak_dir, imp)  # may contain '..\/..\/evil.proto'\n        os.makedirs(os.path.dirname(dest_path), exist_ok=True)\n        with open(dest_path, \"w\", encoding=\"utf-8\") as f:\n            f.write(\"syntax = \\\"proto3\\\";\")\n    return weak_dir\n","patched_code":"import os\nimport tempfile\n\ndef _write_missing_weak_imports(imports):\n    \"\"\"\n    Write placeholder proto files for missing imports into a temporary\n    directory used by the protobuf compiler.\n    \"\"\"\n    weak_dir = tempfile.mkdtemp(prefix=\"weak_imports_\")\n    for imp in imports:\n        # FIX: sanitize path to prevent escaping the temporary directory\n        safe_rel = os.path.normpath(imp).lstrip(os.sep)\n        dest_path = os.path.join(weak_dir, safe_rel)\n        # Ensure the resolved path is still inside weak_dir\n        if not os.path.commonpath([weak_dir, dest_path]) == weak_dir:\n            continue  # skip unsafe paths\n        os.makedirs(os.path.dirname(dest_path), exist_ok=True)\n        with open(dest_path, \"w\", encoding=\"utf-8\") as f:\n            f.write(\"syntax = \\\"proto3\\\";\")\n    return weak_dir\n","payload_needed":true,"payload":null,"payload_status":"model_refused","published_fix":[{"repository":"datamodel-code-generator\/datamodel-code-generator","commit_url":"https:\/\/github.com\/datamodel-code-generator\/datamodel-code-generator\/commit\/5e94b8f4203198798ec66b8e48217f70af69a0dc","commit_subject":"Merge commit from fork","units":[{"file":"src\/datamodel_code_generator\/parser\/protobuf.py","function":"_ProtoInputPreparer._write_missing_weak_imports"},{"file":"src\/datamodel_code_generator\/parser\/protobuf.py","function":"_ProtoInputPreparer.__enter__"}]}],"references":null}