Repository navigation
Update dependency GitPython to ==3.2.* [SECURITY] - #241
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
==3.1.*→==3.2.*GitPython validates a submodule's ".git" path only after cloning into it (RCE)
CVE-2026-114145 / GHSA-83vg-56qc-22m7
More information
Details
Summary
create_submodule(name, path, url)clones a submodule into the repo's own.gitdirectory before it rejects the path. A
pathof ".git/hooks" is accepted by thepre-clone check, so the submodule is cloned straight into the live hooks directory,
and a file named
post-checkoutin the submodule becomes an executable.git/hooks/post-checkout. On 3.2.0+ the later index check does raiseValueError,but only after the clone already wrote to disk, and it does not remove the planted
hook; on 3.1.x there is no such check and the call succeeds silently. Either way the
hook runs on the next git operation (e.g. checkout), giving code execution.
Details
The checkout path is validated too late, after the clone has already mutated disk.
This breaks the "validate before mutation" invariant that commit 43a43cd8 ("Validate
submodule checkout and metadata paths before mutation") set out to enforce.
Submodule.add() calls the permissive path check before cloning, and the strict check
only reaches the ".git" alias at index time, after _clone_repo has written to disk:
git/objects/submodule/base.py (Submodule.add)
599: path = cls._to_relative_path(repo, path) # accepts ".git/hooks"
673: mrepo = cls._clone_repo(repo, url, path, name, ...) # clones into /.git/hooks
714: index.add([sm], write=True) # strict check only triggers here
git/index/base.py (IndexFile._preprocess_add_items)
732: _validate_repo_path(entry.path) # rejects ".git", too late
_to_relative_path only blocks
../absolute/out-of-tree paths;.gitaliases arerejected only by _validate_repo_path, which was added in 3.2.0 (commit a75aedf3) and
runs at the index boundary. The ValueError it raises at line 732 does not roll back
what _clone_repo already wrote.
Version-dependent behavior:
hook is already on disk and is not removed (incorrect order of validation vs. clone).
not reject
.git; create_submodule(path=".git/hooks", ...) returns with no error atall and the hook is planted silently.
Proof of concept
Setup:
evilsub/ : a git repo whose ROOT contains an executable file named post-checkout (the payload)
victim/ : a git repo with at least 1 commit and a second branch, whose .git/hooks has NO
sample hooks (the state of a minimal/CI checkout, or
git initwith an emptytemplate dir, or GIT_TEMPLATE_DIR/init.templateDir empty)
import git, os.path as osp
try:
git.Repo("victim").create_submodule(name="x", path=".git/hooks", url=osp.abspath("evilsub"))
except ValueError:
pass # 3.2.0+: ".git" is rejected, but only AFTER the clone, so the plant already happened.
# 3.1.x: no exception is raised at all; the call succeeds and still plants the hook.
victim/.git/hooks/post-checkout now exists, mode 0755, attacker-controlled, on every
affected version. Any later checkout runs it:
git -C victim checkout -> the hook runs -> code execution
Verified live:
git/index/base.py:732, yet .git/hooks/post-checkout was present and executable, and
git checkoutexecuted it.and executed by
git checkout.Impact
Arbitrary code execution. A library/app that creates a submodule from an
attacker-influenced
pathends up with an attacker-controlled executable in.git/hooks, which git runs on ordinary later operations. This affects any servicethat derives a submodule checkout path from untrusted data, e.g. one that ingests a
submodule spec (name/path/url) from a user-supplied manifest or API request and feeds
pathinto create_submodule. On 3.2.0+ the library's own validation is the thing thatfails: it correctly rejects the
.gitpath, but only after the submodule has alreadybeen cloned into place, so an app that traps the ValueError reasonably believes the
unsafe path was blocked.
Preconditions (hence AC:H): (1) the app passes an attacker-influenced submodule
path;(2) the target hook name is free in
.git/hooks, true for minimal/CI/containercheckouts and whenever init.templateDir/GIT_TEMPLATE_DIR is empty. With the default
sample hooks present,
git clonerefuses the non-empty destination and no plant occurs.Affected: all tested versions from 3.1.x (3.1.59) through the current tip bda18e08
(3.2.0 + 3 commits). 3.1.x plants silently; 3.2.0+ plants despite raising ValueError.
Severity
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
GitPython: Submodule.move() follows an attacker-committed intermediate symlink outside the worktree
GHSA-gq48-pqfc-9p58
More information
Details
Summary
GitPython's public
Submodule.move()API verifies that its destination is lexically inside the parent repository, but it does not reject symbolic links in the destination's intermediate components before filesystem operations. On systems that check out Git symlinks, an untrusted repository can therefore redirect a fixed, application-selected move destination outside the parent worktree.The reporter reproduced this on the latest release, GitPython 3.1.62, and current
main. In the strict scenario, the repository commitsvendor -> ../outside, while the consuming application independently passes the fixed literalvendor/module.Submodule.move()followsvendor, moves the initialized submodule checkout tooutside/module, rewrites.gitmodulesand the index to the symlinked path, and leaves the index unable to produce a tree.The same result occurs when the committed symlink contains an absolute path to an external directory. No attacker-controlled API argument, local symlink planting, race, Git hook, unsafe-option flag, or network access during the proof is required.
Trust boundary and preconditions
The attacker controls:
120000tracked symlink namedvendor;The consuming application controls the call and uses a fixed layout rule:
The trigger requires the application to initialize the submodule and later call
Submodule.move()with a path below the attacker-committed symlink. Ordinary clone or submodule update does not automatically make this call. Windows was not tested. The primitive applies where Git materializes the tracked entry as a real symlink; on Windows that generally requirescore.symlinks=truewith Developer Mode or sufficient privilege. Configurations that materialize it as an ordinary file do not take this path.Product and directly verified revisions
GitPython(pipecosystem)db47516dac750c5968b8f6d388b18712c355df50main:b62e91be897f687a622e40cd1e59c33dce45f124git/objects/submodule/base.pySHA-256 in both revisions:a4355d49e0b75c7c7e74d33ac70ff9550f940c977848c99da40eb41e034b189cOnly these two revisions were directly tested.
Severity and weakness
The demonstrated impact is an integrity boundary violation: repository content selects an existing directory outside the worktree, and GitPython moves an attacker-influenced checkout into a missing or empty child path there with the victim process's permissions. It also removes the original checkout and corrupts the parent repository's index/configuration state.
For a downstream service that remotely accepts repositories and performs this exact layout operation with user involvement retained,
AV:Ngives a conditional application-level score of 7.1. A fully automatic service may warrant a differentUIassessment. The library report usesAV:Lbecause the vulnerable API call is a separate application action and is not part of GitPython's ordinary clone/update flow.No confidentiality impact, code execution, overwrite of an existing file, or overwrite of a non-empty directory was demonstrated.
Reproducer
The following script creates only temporary local repositories and a self-generated canary. It passes
protocol.file.allow=alwaysseparately with-con each fixture Git invocation; that permission is process-scoped and is not persisted to global or repository configuration.Run it from a fresh source checkout:
--absolute-linkcommits the temporary external directory's absolute path instead of../outside.Observed result
The relative and absolute symlink variants produced the same security-relevant result on both directly tested revisions:
move()module/SELF_GENERATED_CANARY.txtexistsoutside/moduleabsentoutside/module.gitmodules,module,vendor.gitmodules,vendor,vendor/module.gitmodulespathmodulevendor/modulecore.worktree../../../module../../../vendor/modulegit write-treeThe failure after the move is:
The tracked attacker input is present in the clean clone before the call:
With the proposed patch, the same calls raise before mutation:
The checkout, external directory, index,
.gitmodules, and module configuration then remain unchanged, andgit write-treesucceeds.Root cause
Submodule._to_relative_path()delegates to a helper that usesabspath(),commonpath(), andrelpath()to enforce lexical containment. These operations normalize.., but they do not resolve or reject an existing intermediate symbolic link.The relevant helper is
git.util._to_relative_path():Submodule.move()then joins the accepted relative path to the worktree and passes it to filesystem operations, includingos.listdir()andos.renames():The operating system resolves
vendor/modulethrough the checked-outvendorlink at that point.GitPython already applies the intended component check to the source checkout through
Submodule.abspath: it walks every component and rejectsos.path.islink(path). The destination inmove()does not use that guard.Suggested fix
The proposed patch below factors the existing component walk into a shared checkout-path helper and applies it to the normalized move destination before any filesystem, index, or configuration mutation. It:
Submodule.abspath's all-component guard intact.The final-component exception preserves current compatibility. The existing code first uses
isfile()andlistdir()to classify the link target, then usesos.remove()to unlink an empty-directory leaf symlink before moving the checkout. Tests confirm that an empty-directory leaf link is replaced while its target remains unchanged; non-empty-directory and file targets are rejected; a dangling leaf producesOSErrorwithout changing repository state. Because the pre-removalisfile(),exists(), andlistdir()calls follow the leaf link, the existing behavior retains an existence/emptiness oracle for that external target; the proof demonstrates no write through the leaf link.The component check closes the non-racing, attacker-committed symlink case reported here. It is not a claim of protection against a concurrent same-user process replacing a checked directory after validation; descriptor-relative traversal and rename would be needed if that separate race is in scope. Because
move()is decorated with@unbare_repo,working_tree_dirshould be present; the helper nevertheless changes an impossible or malformedNonestate from the previousstr(None)path construction to an explicitNotADirectoryError.Validation
The strict clean-clone proof was run with both relative and absolute committed symlink targets:
mainb62e91bBoth platforms were ARM64 on the same physical Mac; Linux ran in a local LinuxKit VM image. All runs used Python 3.14.7. The Linux runs used a local image by immutable SHA-256, with networking disabled, a read-only container root and source mount, and a temporary writable
/tmp.Pinned reproducer SHA-256:
513b6f32fc44cc74bee1ca8e81e8ed3f48ae89bfdc332dd6782886bfd1d6a79c.The documented shallow-clone command was also executed from a new temporary directory at 3.1.62. The reproducer resolved
git,gitdb, andsmmapfrom that checkout (git/__init__.py,gitdb/gitdb/__init__.py, andsmmap/smmap/__init__.py) and reproduced the same external move. In that exact checkout,git ls-tree HEAD gitdb smmap git/extreports ordinary mode-040000trees for rootgitdbandsmmap, no.gitmodulesfile exists, andgit submodule status --recursiveproduces no entries. No recursive submodule checkout or preinstalled GitPython dependency was used for that bootstrap check. The evidence package includes both the raw local tree transcript and the matching official GitHub tree API entries.The revised patch also passed 12 focused tests on each revision on each platform (48 test executions total). They cover:
Submodule.abspathleaf-link guard;Ruff 0.16.6 lint and format checks, Python compilation, patch application, and patched-file byte comparison passed for both revisions. GitPython's complete upstream test suite and mypy were not run against the patch; the test claim is limited to the focused matrix described above.
Additional saved controls on both revisions record rejection of
../and absolute API destinations, preservation of existing files and non-empty directories, the final-component link behavior, andRootModule.update()rejecting the tested commit-to-commit symlinked path before its internal move. These controls are separate from the strict 16-run proof.Impact limits and compatibility observations
../and an absolute API destination outside the worktree are already rejected; the bypass is filesystem resolution of a lexically in-tree path.RootModule.update()rejects the tested commit-to-commit symlinked path before its internalmove()call, so ordinary clone/update is not an automatic trigger.AI assistance and credit
This report was prepared with AI assistance. The working proof was executed locally against both pinned revisions on macOS and Linux, and every reported state transition was checked against saved structured output. The proposed patch and focused tests were executed independently from the vulnerable proof.
Requested credit: GitHub user
dpfkdlemtp.Severity
Medium
References
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
Release Notes
gitpython-developers/GitPython (GitPython)
v3.2.1Compare Source
What's Changed
.gitmodulesby @Keerthana-64 in #22782026101by @Byron in #2284New Contributors
Full Changelog: gitpython-developers/GitPython@3.2.0...3.2.1
v3.2.0: - SecurityCompare Source
What's Changed
New Contributors
Full Changelog: gitpython-developers/GitPython@3.1.62...3.2.0
Configuration
📅 Schedule: (UTC)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.