Summary
Dulwich, a pure-Python Git implementation, contains a path traversal flaw on Windows that allows arbitrary file writes during clone, fetch, or checkout of a malicious repository.
An attacker who controls repository contents can craft filenames that bypass NTFS path protections, potentially leading to remote code execution on affected Windows systems.
Affected context
The vulnerability occurs when Dulwich is used to clone, fetch, or check out Git repositories on Windows systems.
It is relevant to any workflow that:
- Processes untrusted or third-party Git repositories
- Uses Dulwich directly via its CLI,
porcelain.clone, or downstream tools that embed Dulwich - Runs on Windows filesystems that interpret special path syntax (e.g., NTFS)
POSIX environments are not directly exploitable but can unknowingly propagate malicious trees that later impact Windows users.
Exploit preconditions
- Attack surface: Git repository content processed by Dulwich on Windows.
- Required access: Ability to publish, push, or otherwise supply a malicious repository that a victim will clone, fetch, or check out with Dulwich.
- Trigger point: Repository operations that materialize tree entries onto disk (clone, fetch + checkout, or similar).
- Why exploitation is possible: Dulwich's filename validation accepted path elements containing bytes that Windows treats as structural path syntax, and configuration-based protections (
core.protectNTFS,core.protectHFS) were misread and effectively disabled, allowing crafted filenames to escape intended directory boundaries and overwrite arbitrary files.
Why this happens
The root cause is incomplete and misconfigured path validation when translating Git tree entries into filesystem paths on Windows.
Dulwich's path-element validator failed to reject filenames containing bytes that NTFS interprets as special path components, enabling directory traversal or placement of files in unintended locations (CWE-22).
Contributing to this, the protective configuration flags were looked up under incorrect option names, so user settings were silently ignored and safe defaults were not consistently enforced, leaving the unsafe filename handling path reachable whenever untrusted repositories were processed.
Potential impact
- Malicious repositories may cause arbitrary files to be written or overwritten on the victim's Windows filesystem.
- Attackers could place or modify scripts, configuration files, or executables that are later invoked, leading to remote code execution.
- Compromise of application configuration used by build pipelines or developer tools.
- Persistence or backdoor creation through modified startup files or service definitions.
- Indirect supply-chain compromise if affected repositories are used in CI/CD, build, or packaging workflows.
General mitigation guidance
Effective mitigation centers on strict path normalization and platform-aware validation before writing repository contents to disk.
Recommended defensive patterns include:
- Enforcing canonicalization of all paths derived from repository entries and rejecting any that escape the intended working directory.
- Validating filenames against a denylist of reserved characters, device names, and path syntax that is specific to Windows filesystems.
- Treating configuration-based safety toggles (such as NTFS/HFS protections) as secure-by-default, with explicit and clearly audited opt-outs only.
- Isolating repository checkouts in dedicated, least-privileged environments so that even if a write escapes the project tree, it cannot impact sensitive system locations.
- Decoupling execution paths from writable checkout locations (e.g., not executing directly from clone directories) to reduce the likelihood of file-write-to-RCE chains.
How teams detect issues like this
Detection efforts can focus on both code-level review and runtime behavior:
- Static analysis and manual review to locate code that maps Git tree paths to filesystem paths, checking for robust normalization, platform-specific validation, and proper enforcement of safety options.
- Rules that flag uses of raw path concatenation, unchecked handling of backslashes, device names, or relative path segments when processing repository entries on Windows.
- Configuration audits to ensure safety-related options are correctly named, parsed, and enforced, with tests that intentionally misconfigure them to confirm behavior.
- Runtime monitoring for unexpected writes outside of expected working directories during Git operations, using sandboxing logs or filesystem auditing where feasible.
- Incorporating security-oriented test repositories with crafted filenames into CI to validate that path validation and NTFS protections behave as intended.

