CVE-2026-87817
GitPython before 3.1.60 Remote Code Execution via Git Directory Impersonation
Refuses execution of repository commit hooks outside .git/hooks by Python processes to mitigate CVE-2026-87817.
High 8.7Vetted
EPSS 0.6%: the estimated chance this CVE is exploited in the next 30 days, as of 25 Nov 2026.
At a glance
CVE-2026-87817 is a high (CVSS 8.7) vulnerability in GitPython, published 9 September 2026. A vetted upatch, cve-2026-87817-hook-block, blocks it on running Linux machines with shirudo until GitPython is upgraded.
- Severity
- High 8.7 CVSS 4.0
- Chance of exploitation
- 0.6% in the next 30 days (EPSS, 25 Nov 2026)
- Known exploited
- No, not on CISA’s KEV list
- Weakness
- CWE-94
- Affected software
- GitPython (gitpython-developers)
- Upatch status
- Vetted, merged into the registry
- How to apply
- Build, sign and roll out with shirudo
Overview
CVE-2026-87817 (GHSA-239g-whfq-7xj9), "Repository content can impersonate the git directory, leading to arbitrary code execution", was published on 26 August 2026 (CVE record published 9 September 2026). In GitPython through 3.1.59, Repo.__init__ (git/repo/base.py) resolves the repository's git_dir by testing candidate paths in an order that checks for the real .git directory last. It first checks whether gitdir, commondir and HEAD exist as files in curpath (git/repo/base.py:299), and second whether is_git_dir(curpath) holds (git/repo/base.py:320), before checking curpath/.git (git/repo/base.py:341). Because Git reserves only .git and allows ordinary tracked files named gitdir, commondir, HEAD and hooks/pre-commit at the root of a repository, cloning or opening such a repository causes GitPython to resolve git_dir to the working-tree root while Git itself uses <root>/.git. When a service using GitPython calls index.commit() (git/index/base.py:1201), run_commit_hook (git/index/fun.py:73) resolves the hook path under index.repo.git_dir and executes the tracked <root>/hooks/pre-commit script with safer_popen.
Official description
GitPython before 3.1.60 fails to properly validate the git directory location, allowing attackers to impersonate the git directory using tracked files like gitdir, commondir, and HEAD. Attackers can execute arbitrary code by placing a malicious pre-commit hook in the tracked hooks directory that executes when a victim calls index.commit() on a cloned or opened repository.
Affected versions
The vulnerability is in GitPython (<= 3.1.59), fixed in GitPython 3.1.60 by commit c7cf4d13b1ed0a2e70f2a1f3c6b4fc6c2652cf0b. The upatch applies to any Linux kernel supporting BPF LSM (lsm/bprm_check_security) and BTF.
Sources
More references from NVD (1)
Mitigation
A BPF LSM program on lsm/bprm_check_security inspects the executable file being started (bprm->file->f_path.dentry) and returns -EPERM when all of the following hold:
- The file being executed is named
pre-commit,commit-msgorpost-commit, the three hooksIndexFile.commit()runs ingit/index/base.py. - Its parent directory is named
hooks. - Its grandparent directory is not named
.git. - The calling process's executable (
current->mm->exe_file->f_path.dentry) starts withpython.
The cheapest check (the executable's dentry name length and comparison against pre-commit, commit-msg and post-commit) runs first so that almost every execve on the machine returns immediately. A refusal from an earlier BPF LSM program on the same hook is preserved. Refusals are counted in the refused per-CPU array map.
Side effects
- A Python process cannot directly execute
hooks/pre-commit,hooks/commit-msgorhooks/post-commitwhen thehooksdirectory is not directly inside.git(for example in a bare repository whose directory is not named.git, a linked worktree administrative directory, or a customcore.hooksPathdirectory namedhooks). - Standard repository hooks in
.git/hooks/continue to work, as do hooks executed by thegitbinary itself or by any non-Python process. - This upatch blocks the code execution vector (
index.commit()running tracked hooks). It does not preventRepo.__init__in vulnerable GitPython from misresolvinggit_dirin memory or reading a trackedconfigfile; upgrade to GitPython 3.1.60 for the complete fix.
Preemption model and cost
The program holds no state other than the refused per-CPU counter, which is updated with __sync_fetch_and_add, making it safe under all preemption models including preemptible RCU and PREEMPT_RT. On every execve of a binary whose name is not 10 or 11 bytes long, the program performs a single length check on bprm->file->f_path.dentry->d_name.len and returns.
The policy
107 lines of BPF C, attached at lsm/bprm_check_security.
// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_core_read.h>
#define EPERM 1
char _license[] SEC("license") = "Dual BSD/GPL";
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(max_entries, 1);
__type(key, __u32);
__type(value, __u64);
} refused SEC(".maps");
static __always_inline void count_refused(void)
{
__u32 key = 0;
__u64 *value = bpf_map_lookup_elem(&refused, &key);
if (value)
__sync_fetch_and_add(value, 1);
}
static __always_inline bool name_is(const struct dentry *dentry,
const char *want, __u32 want_len)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
char buf[16] = {};
if (!dentry || BPF_CORE_READ(dentry, d_name.len) != want_len ||
want_len > sizeof(buf) - 1)
return false;
if (bpf_probe_read_kernel_str(buf, sizeof(buf), name) < 0)
return false;
for (__u32 i = 0; i < sizeof(buf) - 1; i++) {
if (i == want_len)
return true;
if (buf[i] != want[i])
return false;
}
return false;
}
static __always_inline bool name_starts_with_python(const struct dentry *dentry)
{
const unsigned char *name = BPF_CORE_READ(dentry, d_name.name);
__u32 len = BPF_CORE_READ(dentry, d_name.len);
char buf[6] = {};
if (!dentry || len < 6)
return false;
if (bpf_probe_read_kernel(buf, sizeof(buf), name))
return false;
return buf[0] == 'p' && buf[1] == 'y' && buf[2] == 't' &&
buf[3] == 'h' && buf[4] == 'o' && buf[5] == 'n';
}
static __always_inline bool is_commit_hook(const struct dentry *dentry)
{
__u32 len = BPF_CORE_READ(dentry, d_name.len);
if (len != 10)
return name_is(dentry, "post-commit", 11);
return name_is(dentry, "pre-commit", 10) ||
name_is(dentry, "commit-msg", 10);
}
static __always_inline bool current_is_python(void)
{
struct task_struct *task = bpf_get_current_task_btf();
const struct dentry *exe = BPF_CORE_READ(task, mm, exe_file, f_path.dentry);
return name_starts_with_python(exe);
}
static __always_inline int earlier_verdict(int ret)
{
return ret >= -4095 && ret < 0 ? ret : -EPERM;
}
SEC("lsm/bprm_check_security")
int BPF_PROG(cve_2026_87817_hook_exec, struct linux_binprm *bprm, int ret)
{
const struct dentry *dentry = BPF_CORE_READ(bprm, file, f_path.dentry);
const struct dentry *parent;
const struct dentry *grandparent;
if (ret)
return earlier_verdict(ret);
if (!is_commit_hook(dentry))
return 0;
parent = BPF_CORE_READ(dentry, d_parent);
if (!name_is(parent, "hooks", 5))
return 0;
grandparent = BPF_CORE_READ(parent, d_parent);
if (name_is(grandparent, ".git", 4))
return 0;
if (!current_is_python())
return 0;
count_refused();
return -EPERM;
}
The package: name, license, the program and the CVE it fixes.
[package]
name = "cve-2026-87817"
description = "Refuses execution of repository commit hooks outside .git/hooks by Python processes to mitigate CVE-2026-87817"
license = "GPL-2.0 OR BSD-2-Clause"
[[upatches]]
source = "cve-2026-87817-hook-block.bpf.c"
[upatches.tree]
id = "cve-2026-87817-hook-block"
fixes = ["CVE-2026-87817"]
Process
How this upatch was written, checked and reviewed, from the registry’s history.
- 9 Sept 2026CVECVE published
- 25 Nov 2026Pull requestPull request #103 openedAdd CVE-2026-87817: Refuses execution of repository commit hooks outside .git/hooks by Pythonromanlab
- 25 Nov 2026CIingestpassed
- 25 Nov 2026CICheck entriespassed
- 25 Nov 2026CICompile with clang 23passed
- 25 Nov 2026MergeMerged #103romanlab
- 25 Nov 2026ReviewReviewedqodo-code-review[bot] (automated)
No human review is recorded on GitHub for this upatch yet.
Evidence
On a vulnerable GitPython 3.1.59 service, the loaded upatch refused execution of the impersonated working-tree hooks/pre-commit script with EPERM when index.commit() ran. Before loading and after unloading, the hook ran.
- Tested
- 25 Nov 2026
- Target
- GitPython 3.1.59 (gitdb 4.0.12, smmap 5.0.2) on Python 3, loopback HTTP service cloning a repository with tracked gitdir, commondir, HEAD and hooks/pre-commit and calling index.commit()
- Kernel
- 7.4-shirudo-ci-20261123
- Architecture
- x86_64
- Distribution
- Ubuntu 26.04
| State | Tracked hooks/pre-commit in working tree |
|---|---|
| Before loading | reached (hooks/pre-commit in working tree executed) |
| Upatch loaded | blocked (hooks/pre-commit refused with EPERM) |
| After unloading | reached (hooks/pre-commit in working tree executed) |
tools-test.log Output of tools/test --setup showing the probe reached before loading, blocked while loaded, and reached after unloading.
tools/test --setup, 2026-11-25T16:25:18Z Target: shirudo test VM, Linux 7.4-shirudo-ci-20261123, x86_64, swtpm cve-2026-87817 setup done GITPYTHON_PROBE_URL=http://127.0.0.1:18781/probe before reached hooks/pre-commit in working tree executed loaded blocked hooks/pre-commit refused with EPERM after reached hooks/pre-commit in working tree executed PASS: reached before, blocked while loaded, reached again after
Use it
Build the upatch from source, sign it with your own shirudo key, and publish it to your own OCI registry. Machines that follow your upatch tree load it within about a minute.
git clone https://github.com/copper-helm/upatch-registry
cd upatch-registry
tools/build <shirudo-checkout> <keys-dir> 1.0.0 upatches/cve-2026-87817shirudo bpm push build/packages/cve-2026-87817-1.0.0.bee oci://<registry>/<namespace>/cve-2026-87817 --keys-dir <keys-dir>
shirudo bpm tree append build/packages/cve-2026-87817-1.0.0.bee oci://<registry>/<namespace>/<tree> --tree-id <tree-id> --keys-dir <keys-dir>