A developer reviews a Git commit and sees an ordinary Python package. Later, an installer retrieves that same commit and builds a different package containing attacker-controlled code. The commit ID has not changed. The difference comes from how two Git implementations interpret the commit's contents.

I found this inconsistency in Dulwich, a Python implementation of Git. Vulnerable Dulwich selected the last of two tree headers in a malformed commit, while core Git selected the first. Because Poetry uses Dulwich by default when installing dependencies directly from Git repositories, this parsing difference could cross from source-code review into package installation. In a controlled test, the alternate package's setup.py executed during installation.

I tested the attack on GitHub.com and GitLab CE 19.5.5. Both accepted the crafted commit, and their review views displayed the benign files, while Poetry with vulnerable Dulwich installed and built the alternate files. The mismatch works on the Git hosting platforms most teams already use.

What Git, Dulwich and Poetry each do

The names can be confusing because they appear in the same workflow but solve different problems.

Component Its job in this story
Git The version-control system. It stores commits and uses a tree to describe the files in a revision.
GitHub / GitLab Services that host Git repositories and display code for human review.
Dulwich A Python library that reads Git data without requiring the system git executable. This is where the bug was.
Poetry A Python package manager. It installs a project's dependencies and, by default, uses Dulwich when one of those dependencies comes from Git.

Most Python packages are installed from PyPI. Git dependencies are another supported option, useful when a team needs an internal library or a particular commit that has not been published as a package. For example, a project can declare a Git-hosted package in pyproject.toml:

[tool.poetry.dependencies]
report-helper = { git = "https://github.com/example/report-helper.git", rev = "<reviewed-commit>" }

When a developer or CI runner executes poetry install, Poetry retrieves the selected dependency revision. In the affected configuration, it delegates Git operations to Dulwich. Poetry is not the vulnerable parser. It is a realistic consumer of the parser, and its later build step creates a possible route to code execution.

The Git detail that makes the bug possible

A normal commit has one root tree header. The tree identifies a snapshot of the project, including files and subdirectories. Git also stores the commit's parent, author, committer and message.

# Normal commit, simplified

tree AAA111
parent CCC333
author Alice <alice@example.test> ...
committer Alice <alice@example.test> ...

Update report helper

The commit ID is derived from the raw commit object's bytes. It does not promise that every application will interpret malformed content consistently.

The problematic object has two tree headers:

# Malformed commit, simplified

tree AAA111    # benign project snapshot
tree BBB222    # alternate project snapshot
parent CCC333
...

For this kind of commit, core Git uses AAA111, the first tree. The affected Dulwich parser continued assigning a variable each time it encountered a tree header, so it ended up using BBB222, the last one. Both implementations were reading the same commit object and the same commit ID, but they selected different file snapshots.

One commit object with two tree headers. Git and code review take the first, benign tree. Dulwich and Poetry take the last, attacker-controlled tree.
Same commit sha, two tree headers, two different checkouts depending on who parses it.

The affected code was in dulwich/objects.py, in the commit read path _parse_commit. Conceptually, the vulnerable operation looked like this:

# Simplified to show the parsing mistake
for field, value in headers:
    if field == b"tree":
        tree = value  # a later tree overwrites the first

Dulwich had a separate validation method that could reject duplicate headers, but the vulnerable read path did not require that check before selecting the checkout tree. The fix makes tree selection agree with Git, choosing the first tree, and tightens other header-ordering behavior.

The complete sequence, from attacker to installer

Consider a company that uses a third-party or internal Python library directly from a Git repository. The company reviews a particular commit before accepting it as a dependency. The attacker needs enough control over the dependency source to get the crafted commit selected, such as control of the repository or a compromised maintainer account. A random pull request or an unrelated commit is not enough.

  1. The attacker prepares two snapshots. Tree A contains the innocuous package intended for review. Tree B contains the alternate package, including build behavior the attacker wants the installer to run.
  2. Both snapshots are made available in the repository. In my tests, the alternate files were also reachable through a separate docs branch. They were stored in the repository, not somehow invisible to the server. This matters because the installer must be able to retrieve the objects referenced by Tree B.
  3. The attacker publishes a crafted commit. That commit names Tree A first and Tree B second. The commit is shaped to pass the push checks on GitHub and GitLab.
  4. The victim reviews the commit. GitHub.com and GitLab CE displayed the benign snapshot in every tested view of that commit. A normal Git clone also followed the benign tree. Someone inspecting those views would not see Tree B's malicious setup.py as part of that commit.
  5. The victim installs the reviewed revision. The company's dependency configuration and, where applicable, lockfile cause Poetry to retrieve the selected commit. Poetry 2.5.1 uses the vulnerable Dulwich client in the tested setup.
  6. Dulwich chooses the other snapshot. Dulwich 1.2.17 reads the same commit but resolves its second tree. The files on disk now differ from those the reviewer saw.
  7. The package build runs code from those files. In the controlled test, Poetry executed the alternate setup.py. That establishes execution during the build/install path, not just an unexpected checkout. The code runs with the permissions available to the installing process.

This is why a malicious dependency alone is not the finding. An attacker who simply publishes an obviously malicious library does not need a parsing bug. The vulnerability allows a dependency to appear benign in the normal review path but differ in the installation path, despite both referencing the same commit ID.

Reproducing the mismatch on GitHub and GitLab

The tests answered two practical questions: whether a mainstream forge would accept the crafted commit, and whether an ordinary Poetry installation would retrieve and execute the alternate snapshot. Both answers were yes.

Test target Initial commit shape Revised commit shape Reviewed commit Vulnerable Poetry install
GitHub.com Push rejected Push accepted Benign files Alternate files and setup.py executed
GitLab CE 19.5.5 Push rejected Push accepted Benign files Alternate files and setup.py executed

For each forge, the tested review surfaces included the commit API and file API, raw file views, rendered commit page, file browser, source-code download, and a regular Git clone. All showed the benign version of the commit. The alternate package files were still present in the repository through the separate branch, but they did not appear as the files of the reviewed commit.

The installation comparison used Poetry 2.5.1 with Dulwich 1.2.17 for the affected case. Installing the same revision used the alternate tree and executed its setup.py. With Dulwich 1.2.21, the install selected the benign tree and did not execute the alternate build script. The upstream fix was first released in Dulwich 1.2.20.

This distinction is important: accepting the commit is only one part of the delivery problem. The alternate tree's objects also have to reach the installer. Keeping them reachable elsewhere in the same repository solved that part in these tests. These results should not be generalized to every hosting version, every repository setting, or every Python build configuration.

Interactive walkthrough

The interactive demo below walks through the parser difference step by step.

What the attacker gains

The attacker gets code execution through a package build nobody reviewed, which I confirmed in my tests. When the install runs on a developer workstation or CI runner, the attacker's setup.py runs with all the filesystem, process and credential access that environment has, so the payload can be a reverse shell, credential theft or anything else the attacker chooses.

The attack works because review and installation read the same commit differently. GitHub and GitLab show the reviewer one snapshot, while vulnerable Dulwich hands Poetry another.

Fix and defensive implications

Upgrade Dulwich to 1.2.20 or later. With Dulwich 1.2.21, the same install selected the benign tree. If Poetry is the consumer, verify which Dulwich version Poetry actually uses in the environment, rather than only checking the version of Poetry itself. Poetry also supports a system Git client configuration, but patching the underlying library is the direct fix for the parser inconsistency.

For teams accepting Git-based dependencies, the broader lesson is to validate unusual Git objects and ensure that review and build tools agree on the exact source snapshot. A commit hash guarantees the identity of the stored bytes. It cannot guarantee agreement between parsers that interpret malformed bytes differently.

Disclosure and references

CVE-2026-122299 was published on November 4, 2026 and is rated High, with a CVSS 3.1 score of 8.8 and CVSS 4.0 score of 8.6.

Upstream and primary references

Downstream tracking and response

  • Snyk published a vulnerability entry crediting me.
  • Amazon Linux tracked the issue and listed a fixed Amazon Linux 2027 Preview package.
  • SUSE assessed affected enterprise packages.
  • Debian Security Tracker tracked affected versions and the upstream fix.