Summary
A path traversal vulnerability in Dulwich allows a malicious repository's stashed changes to write files outside the intended worktree through intermediate directory symlinks. If an attacker can cause the repository's stash to be popped, the written content may modify Git hook locations and enable code execution during a later checkout.
A path traversal vulnerability in Dulwich allows a malicious repository's stashed changes to write files outside the intended worktree through intermediate directory symlinks. If an attacker can cause the repository's stash to be popped, the written content may modify Git hook locations and enable code execution during a later checkout.
Affected context
The vulnerability occurs in Dulwich's stash handling when stash.py processes a popped stash. It becomes risky when a repository contains attacker-controlled paths or intermediate symlinks and the stash operation does not sufficiently constrain resolved destinations to the worktree. The affected behavior is associated with Dulwich releases from 0.22.5 through versions before 1.2.8.
The vulnerability occurs in Dulwich's stash handling when stash.py processes a popped stash. It becomes risky when a repository contains attacker-controlled paths or intermediate symlinks and the stash operation does not sufficiently constrain resolved destinations to the worktree. The affected behavior is associated with Dulwich releases from 0.22.5 through versions before 1.2.8.
Exploit preconditions
- Attack surface: Repository and stash-processing functionality in Dulwich
- Required access: Ability to provide or induce processing of a malicious repository and its stash
- Trigger point: Execution of the stash
pop()operation - Why exploitation is possible: Intermediate directory symlinks can redirect file writes outside the intended worktree, allowing attacker-controlled content to reach sensitive repository paths
- Attack surface: Repository and stash-processing functionality in Dulwich
- Required access: Ability to provide or induce processing of a malicious repository and its stash
- Trigger point: Execution of the stash
pop()operation - Why exploitation is possible: Intermediate directory symlinks can redirect file writes outside the intended worktree, allowing attacker-controlled content to reach sensitive repository paths
Why this happens
The underlying bug is insufficient containment of file paths during stash restoration. Path components are processed without reliably preventing symlink-mediated resolution outside the intended worktree, allowing a crafted repository to redirect writes to arbitrary filesystem locations. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal.
The underlying bug is insufficient containment of file paths during stash restoration. Path components are processed without reliably preventing symlink-mediated resolution outside the intended worktree, allowing a crafted repository to redirect writes to arbitrary filesystem locations. This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, commonly known as path traversal.
Potential impact
- An attacker may write arbitrary files accessible to the Dulwich process.
- Repository metadata or Git hook files could be modified.
- Code could execute when a modified hook is triggered by a later checkout.
- Local credentials, source code, or other files could be altered or damaged.
- A compromised developer or automation environment could facilitate further attacks.
- An attacker may write arbitrary files accessible to the Dulwich process.
- Repository metadata or Git hook files could be modified.
- Code could execute when a modified hook is triggered by a later checkout.
- Local credentials, source code, or other files could be altered or damaged.
- A compromised developer or automation environment could facilitate further attacks.
General mitigation guidance
Mitigation typically focuses on enforcing destination confinement during all repository file operations.
Common defensive patterns include:
- Canonicalizing and validating resolved paths before writing files.
- Rejecting symlinked parent directories when restoring worktree content.
- Ensuring every destination remains beneath the intended worktree after filesystem resolution.
- Using secure file-creation and extraction APIs that do not follow unsafe links.
- Processing repositories with least-privilege accounts and restricted filesystem access.
- Treating externally supplied repositories and stashes as untrusted input.
- Applying repository policy controls that limit executable hooks in automated environments.
Mitigation typically focuses on enforcing destination confinement during all repository file operations.
Common defensive patterns include:
- Canonicalizing and validating resolved paths before writing files.
- Rejecting symlinked parent directories when restoring worktree content.
- Ensuring every destination remains beneath the intended worktree after filesystem resolution.
- Using secure file-creation and extraction APIs that do not follow unsafe links.
- Processing repositories with least-privilege accounts and restricted filesystem access.
- Treating externally supplied repositories and stashes as untrusted input.
- Applying repository policy controls that limit executable hooks in automated environments.
How teams detect issues like this
Organizations commonly detect this class of issue through:
- Static analysis for path joins, archive extraction, and file writes that lack canonical containment checks.
- Code review searches for filesystem operations that follow symlinks during repository or stash restoration.
- Tests using symlinked parent directories to verify that writes cannot escape the designated worktree.
- Runtime monitoring for unexpected writes to
.git/hooksor other files outside repository boundaries. - Policy enforcement that restricts hook execution and filesystem permissions in CI or automation.
Automated security review tools may help identify unsafe path handling patterns, but filesystem-behavior tests remain important.
Organizations commonly detect this class of issue through:
- Static analysis for path joins, archive extraction, and file writes that lack canonical containment checks.
- Code review searches for filesystem operations that follow symlinks during repository or stash restoration.
- Tests using symlinked parent directories to verify that writes cannot escape the designated worktree.
- Runtime monitoring for unexpected writes to
.git/hooksor other files outside repository boundaries. - Policy enforcement that restricts hook execution and filesystem permissions in CI or automation.
Automated security review tools may help identify unsafe path handling patterns, but filesystem-behavior tests remain important.

