LOW 3.3

CVE-2026-47712: Dulwich Path-Traversal Vulnerability in Patch File Generation

Dulwich, a Python library for working with Git repositories, has a path-traversal vulnerability in how it generates patch file names. When creating patch files from Git commits, the library previously used the commit's subject line to create the filename without properly sanitizing it. An attacker could craft a malicious commit with special characters (like slashes, backslashes, or double-dots) in the subject line to trick the library into writing patch files outside the intended directory. This could allow unauthorized file creation in unexpected locations on a system using Dulwich to process untrusted commits.

Source data · NVD / CISA · public domain

CVSS
3.1 · 3.3 LOW · CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:L/A:N
Weaknesses (CWE)
CWE-22
Affected products
0 configuration(s)
Published / Modified
2026-06-10 / 2026-06-17

NVD description (verbatim)

Dulwich is a pure-Python implementation of the Git file formats and protocols. Starting in version 0.24.0 and prior to version 1.2.5, dulwich.porcelain.format_patch(outdir=...) derives each patch filename from the commit's subject line. Prior to this fix, get_summary only replaced spaces with dashes - path separators (/, \), parent-directory components (..), and other filename-hostile characters (e.g. :) were preserved verbatim and passed straight into os.path.join(outdir, f"{i:04d}-{summary}.patch"). A malicious commit subject could therefore direct the generated patch file outside the requested outdir. This is fixed in Dulwich 1.2.5. Users should upgrade to 1.2.5 or later. dulwich.patch.get_summary now mirrors git's format_sanitized_subject: only `[A-Za-z0-9._]` are kept, runs of other characters collapse to a single -, consecutive . collapse to a single ., trailing ./- are stripped, and the result is length-limited. This makes the returned string safe to embed as a filename component, so format_patch can no longer be steered out of outdir via the commit subject. Until upgrading, callers that pass untrusted commits to porcelain.format_patch can use stdout=True and write the patch to a destination they control, rather than letting format_patch choose the filename; validate the chosen path before opening - e.g. compare os.path.realpath(returned_path) against os.path.realpath(outdir) and reject any patch whose resolved path is not inside outdir; and/or pre-screen commits and refuse to format any whose subject's first line contains /, \, .., or other characters that are not safe on the target filesystem.

3 reference(s) · View on NVD →

SEC.co analysis · AI-assisted, reviewed against source

Technical summary

CVE-2026-47712 is a path-traversal vulnerability in Dulwich versions 0.24.0 through 1.2.4 affecting the dulwich.porcelain.format_patch() function. The vulnerability stems from insufficient sanitization of commit subject lines when deriving patch filenames. The original get_summary() function only replaced spaces with dashes but left path separators (/, \), parent-directory traversal sequences (..), and other filesystem-hostile characters intact. These unsanitized characters were then passed directly to os.path.join(outdir, filename), allowing a crafted commit subject to construct relative paths that escape the target output directory. The fix implements Git's format_sanitized_subject sanitization scheme: retaining only alphanumeric characters, periods, and underscores; collapsing runs of other characters to single dashes; collapsing consecutive periods to single periods; stripping trailing dots and dashes; and enforcing a length limit. This ensures the resulting filename is safe for use in path operations.

Business impact

The business risk is contained to organizations that use Dulwich to process untrusted or adversarially-controlled Git repositories. Primary concerns include: (1) unauthorized file creation in system directories or other sensitive locations if a path-traversal payload escapes the intended patch output directory; (2) potential code injection if generated patches are later executed or imported without validation; (3) denial-of-service scenarios where files are written to fill disk space or overwrite critical application files. Organizations using Dulwich in automated CI/CD pipelines, patch-processing workflows, or code review systems with external repository sources face the highest risk.

Affected systems

Dulwich versions 0.24.0 through 1.2.4 are vulnerable. The library is used by Python-based Git tools and integrations; identify systems running affected versions by checking Dulwich dependencies in your codebase. The vulnerability only manifests when format_patch() is called with untrusted or malicious commit data—local, trusted repositories pose minimal risk. Systems that download or clone external Git repositories and automatically generate patches are particularly exposed.

Exploitability

Exploitation requires the ability to influence a commit's subject line that will be processed by vulnerable Dulwich code. In practice, this means an attacker must either: (1) push a malicious commit to a repository that a target system automatically processes, or (2) socially engineer a user into cloning a repository containing such a commit. The attack surface is limited to scenarios where Dulwich processes untrusted commits. User interaction is required (the user must initiate patch generation), and the impact is local (files written to the local filesystem). The CVSS 3.1 score of 3.3 (LOW) reflects low attack complexity, no network vector, and limited integrity impact.

Remediation

Upgrade Dulwich to version 1.2.5 or later, which implements proper subject-line sanitization. For organizations unable to upgrade immediately, the vendor advisory recommends: (1) using format_patch(..., stdout=True) to capture patch output directly rather than writing to the filesystem; (2) validating the resolved path of any generated patch file against the intended output directory using os.path.realpath() before trusting it; (3) pre-screening commit subjects and rejecting any containing path-traversal characters (/, \, ..) before calling format_patch(). These workarounds reduce risk but are not substitutes for patching.

Patch guidance

Upgrade to Dulwich 1.2.5 or later. This version is available via pip (pip install --upgrade dulwich). Verify your current version with `pip show dulwich` or in your requirements.txt/pyproject.toml. If using a package manager or container image, ensure the base image or package repository is updated. Test the upgrade in a non-production environment first, particularly if you have custom integrations with Dulwich's patch-generation API.

Detection guidance

Audit your codebase for calls to dulwich.porcelain.format_patch() with user-controlled or externally-sourced commit data. Check Git logs and patch-generation workflows for commits with unusual subject lines containing path-traversal characters. Monitor for unexpected files written outside designated patch directories. If you process untrusted repositories, review recent patch-generation logs for any anomalies. Consider deploying a simple validation wrapper around format_patch() that checks the resolved path of generated files against the intended output directory.

Why prioritize this

This vulnerability is low-severity but warrants timely attention in systems that process untrusted external Git repositories. Prioritize patching in development environments, CI/CD systems, and code-review platforms that integrate Dulwich. Organizations using Dulwich only for trusted, internal repositories can deprioritize but should still plan an upgrade cycle. The fix is straightforward and non-breaking, making this an ideal candidate for routine dependency updates.

Risk score, explained

The CVSS 3.1 score of 3.3 reflects: (1) local attack vector—the attacker must influence commit data on or before the target system processes it; (2) low attack complexity—exploiting the vulnerability requires only crafting a subject line with special characters; (3) no privileges required; (4) user interaction required—someone must call format_patch(); (5) limited scope and impact—only local integrity is affected (unauthorized file creation), with no confidentiality or availability impact. The score is appropriate for a path-traversal vulnerability with local scope, though in specific contexts (e.g., a hosted Git service), impact could be more severe.

Frequently asked questions

Does this vulnerability affect me if I only use Dulwich with trusted, internal Git repositories?

No, the vulnerability requires processing untrusted or adversarially-controlled commits. If you only clone and patch internal repositories under your control, the risk is negligible. However, if any part of your workflow processes external forks, pull requests, or user-submitted repository links, you should upgrade.

Can this vulnerability be exploited remotely?

Not directly. The vulnerability requires a malicious commit to reach a system running Dulwich's format_patch() function. An attacker might trick a user into cloning a malicious repository or could push a payload to a repository that an automated system processes, but there is no network-based remote code execution path.

What characters in a commit subject line would trigger the vulnerability?

Path separators (/ and \\), parent-directory traversal sequences (..), colons (:), and other filesystem-hostile characters. For example, a subject like "Fix ../../../etc/passwd" or "Update ..\\..\\config.ini" could direct patch output outside the intended directory.

If I'm using format_patch() with stdout=True, am I protected?

Yes. When stdout=True is used, patch content is printed rather than written to a filesystem path, so the path-traversal mechanism is bypassed. This is the safest interim workaround if you cannot upgrade immediately.

This analysis is provided for informational purposes and is based on the published CVE record and vendor advisory as of June 2026. Security risks and remediation priorities should be assessed within your organization's specific context, threat model, and dependency landscape. Always verify patch availability and compatibility before deploying updates. Consult the official Dulwich repository and security advisories for the latest information. This document does not constitute professional security advice; engage a qualified security professional for risk assessments and deployment strategies. Source: NVD (public-domain), retrieved 2026-07-20. Analysis generated by SEC.co (claude-haiku-4-5).