Summary
Dulwich: Symlink directory traversal in filter-branch index_filter via cross-commit state persistence
Dulwich's filter_branch.py CommitFilter._apply_index_filter() is vulnerable to symlink directory traversal. When processing commit history, materialized tree entries (including symlinks) persist in the working directory between commits, allowing a symlink from an ancestor commit to redirect file writes from a descendant commit to arbitrary filesystem locations.
Root Cause
_apply_index_filter() at dulwich/filter_branch.py:212 calls build_index_from_tree(".", tmp_index_path, ...) which materializes all tree entries to the current working directory. The finally block (line 229-230) only cleans up the temporary index file (os.unlink(tmp_index_path)), NOT the filesystem files written to CWD. When process_commit() processes parents recursively first (line 260), files materialized from ancestor commits persist and affect processing of descendant commits.
On dulwich 1.2.7, build_file_from_blob() has no symlink protection, and validate_path_element only validates name patterns, not filesystem state.
Attack Scenario
- Attacker creates a repository where commit history (linearized) has:
- Ancestor commit: tree entry
evil(mode 120000, symlink →/target_dir) - Descendant commit: tree entry
evil/payload(mode 100644, attacker content)
- Ancestor commit: tree entry
- Victim clones repository and runs
filter_branchwith an index filter process_commit()processes ancestor first → materializesevilas symlink to/target_dirin CWD- CWD is NOT cleaned between commits
- Processing descendant:
os.path.exists("./evil")→ True (symlink exists).build_file_from_blob(blob, mode, "./evil/payload")→open("./evil/payload", "wb")follows intermediate symlink → writes to/target_dir/payload
Reported by zx (Jace)
Impact
An attacker can craft a malicious repository where running filter_branch with an index filter writes attacker-controlled content to arbitrary filesystem locations via symlink traversal. This achieves RCE if the write targets .git/hooks/.
Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files. Typical impact: unauthorized file read or write outside the intended directory.
GHSA-5FQC-MRG8-W798 has a CVSS score of 8.6 (High). The vector is requires local access, no privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (1.2.8); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
Clean the CWD between commit iterations in _apply_index_filter(), or verify that no intermediate path components are symlinks before writing files.
Frequently Asked Questions
- What is GHSA-5FQC-MRG8-W798? GHSA-5FQC-MRG8-W798 is a high-severity path traversal vulnerability in dulwich (pip), affecting versions >= 0.23.1, <= 1.2.7. It is fixed in 1.2.8. Input manipulates file paths to reach files outside the intended directory, such as configuration or credential files.
- How severe is GHSA-5FQC-MRG8-W798? GHSA-5FQC-MRG8-W798 has a CVSS score of 8.6 (High). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which versions of dulwich are affected by GHSA-5FQC-MRG8-W798? dulwich (pip) versions >= 0.23.1, <= 1.2.7 is affected.
- Is there a fix for GHSA-5FQC-MRG8-W798? Yes. GHSA-5FQC-MRG8-W798 is fixed in 1.2.8. Upgrade to this version or later.
- Is GHSA-5FQC-MRG8-W798 exploitable, and should I be worried? Whether GHSA-5FQC-MRG8-W798 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether GHSA-5FQC-MRG8-W798 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix GHSA-5FQC-MRG8-W798? Upgrade
dulwichto 1.2.8 or later.