GitPython: clone_from()/clone() omit --separate-git-dir from unsafe_git_clone_options, enabling arbitrary git-directory creation outside the destination
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
30일 내 악용 확률 예측
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N상세 설명
- CWE: CWE-73 (External Control of File Name or Path) / CWE-22 (Path Traversal, in the "escapes intended base directory" sense)
- Affected component:
git/repo/base.py,Repo.unsafe_git_clone_options(class attribute, lines 153-165) andRepo._clone()(lines 1477-1520), reached via the publicRepo.clone_from()(line 1626) andRepo.clone()(line 1567) APIs. - Affected version: GitPython at HEAD (
9729ed3b948f2bde09f1f188c5311e172212b67e, 2026-08-05, VERSION3.1.58)
Reachability
Repo.clone_from(url, to_path, **kwargs) (and Repo.clone()) forward arbitrary keyword arguments to the underlying git clone invocation. Before forwarding, GitPython builds a candidate option list from the kwargs (Git._option_candidates) and checks it against a denylist, Repo.unsafe_git_clone_options, via Git.check_unsafe_options() — unless the caller passes allow_unsafe_options=True. This denylist mechanism is exactly the guard that the last ~16 published GHSAs against this repo (2026-07-12 → 2026-08-05) have repeatedly found incomplete or bypassable for other options (--template, --upload-pack, --config, --exec, --output, --index-output, --pathspec-from-file, etc.).
git clone also accepts --separate-git-dir=<path>, which redirects the repository's entire .git metadata directory to an arbitrary, caller-controlled filesystem path, leaving only a gitlink text file (gitdir: <path>) at the intended destination. This is the exact same primitive already recognized as unsafe by GitPython's own code: Repo.unsafe_git_init_options (line 145-150) blocks --separate-git-dir for Repo.init(), with the comment "Redirects the repository metadata to a caller-controlled path". The Repo._clone()/clone()/clone_from() docstring (line 1450-1452) is even more explicit:
1:param allow_unsafe_options: 2 Allow unsafe options to be used, such as ``--template`` and 3 ``--separate-git-dir``.i.e. the maintainers' own documentation states that allow_unsafe_options=False (the default) is supposed to block --separate-git-dir for clone. But Repo.unsafe_git_clone_options does not contain it:
1unsafe_git_clone_options = [ 2 "--upload-pack", 3 "-u", 4 "--config", 5 "-c", 6 "--template", 7 "--bundle-uri", 8]So any application that forwards a separate_git_dir (or separate-git-dir) kwarg into Repo.clone_from() / Repo.clone() — e.g. a CI/build service, a Git-hosting proxy, or any tool that exposes a subset of clone options to a client, the exact threat model already accepted for the sibling --template/--upload-pack/--config entries in this same list — gets no protection at all for --separate-git-dir, even with the default allow_unsafe_options=False.
Root cause
Parity gap between two sibling denylists that guard the same underlying primitive (arbitrary redirection of git metadata storage): unsafe_git_init_options correctly lists --separate-git-dir; unsafe_git_clone_options, covering the same option on a different git subcommand that also accepts it, does not — despite the function's own docstring claiming otherwise. This is the same "denylist omits an equally-dangerous sibling option" pattern already responsible for GHSA-539m-9xh6-q6rr (archive denylist missing --add-file/--add-virtual-file) and GHSA-6p8h-3wgx-97gf (clone denylist missing --template, since fixed).
Exploit path
- Attacker-controlled input reaches a
separate_git_dir=...(or equivalently"separate-git-dir") keyword argument passed intoRepo.clone_from()/Repo.clone()by the host application, withallow_unsafe_optionsleft at its defaultFalse. Git._option_candidates()renders this as--separate-git-dirandGit.check_unsafe_options()checks it againstRepo.unsafe_git_clone_options— no match, noUnsafeOptionErrorraised.Git.transform_kwargs()renders the same kwarg into the real command line as--separate-git-dir=<attacker path>and GitPython executesgit clone -v --separate-git-dir=<attacker path> -- <url> <dest>viasubprocess(no shell).gititself creates the full repository metadata tree (config,description,HEAD,hooks/,index,objects/,refs/,packed-refs,logs/) at the attacker-specified path — which can be any path outside the intended clone destination that the process has permission to create — and leaves a gitlink file at the intended destination pointing to it.
Impact
Arbitrary directory/file creation at a path fully controlled by the attacker (bounded only by filesystem permissions of the process running GitPython), matching the impact class of the already-published, High-severity GHSA-hmq2-w58f-27jc ("Arbitrary Git Repository Creation Outside the Working Tree", CVSS 8.2). Concretely:
- Planting a git repository structure (including a
hooks/directory) at an attacker-chosen location outside the sandboxed clone destination the calling application intended to confine the operation to. - If the attacker-chosen path collides with an existing directory the process can write into (e.g. another repository's
.git, a shared cache path, a predictable temp location), the clone silently populates/overwritesconfig,HEAD,hooks/*,refs/*,packed-refs, andindexthere — an integrity violation of a resource outside the intended destination. - Combined with any later operation that runs
gitagainst that redirected/colliding directory (common in CI/build systems that reuse or predict working-directory layouts), this can escalate to hook execution, matching the RCE class already accepted for--templateinGHSA-9rj7-rf2p-w77r.
Preconditions
- The calling application forwards a caller-influenced value into a
separate_git_dirkwarg ofRepo.clone_from()/Repo.clone()(or into themulti_optionslist as a raw--separate-git-dir=...token) without itself validating/rejecting it, and does not passallow_unsafe_options=Trueintentionally. This is the identical trust model GitPython's own denylist already defends for--template/--upload-pack/--config/--bundle-urion the very same code path — i.e. this option was clearly meant to be covered by the same guard and was simply omitted. - No authentication/role requirement inside GitPython itself; the vulnerable code runs the moment the host application calls the API with the option present.
Evidence
git/repo/base.py:145-151—unsafe_git_init_optionsincludes"--separate-git-dir"with the comment "Redirects the repository metadata to a caller-controlled path".git/repo/base.py:153-165—unsafe_git_clone_options(the list actually enforced on_clone) does not include"--separate-git-dir".git/repo/base.py:1450-1452— docstring ofclone_from/cloneexplicitly documents--separate-git-diras one of the optionsallow_unsafe_optionsis supposed to gate.git/repo/base.py:1495-1518—_clone()special-casesseparate_git_dironly toGit.polish_url()it (path normalization for URL-like values), then runs it throughGit.check_unsafe_options(options=..., unsafe_options=cls.unsafe_git_clone_options)— which, per the list above, does not flag it.- PoC (
gitpython-001-poc.py, embedded below) run against this exact checkout confirms the option reaches the realgit clonesubprocess unguarded and creates a full git directory outside the destination path, withallow_unsafe_optionsat its defaultFalse.
False-positive check (adversarial re-read)
- Is there a value-level check that would still stop this? No —
check_unsafe_optionsonly inspects option names (via_canonicalize_option_name) against the denylist; it performs no filesystem/path validation onseparate_git_dir's value, and no other guard in_clone()touches this kwarg besides theGit.polish_url()normalization (which does not reject arbitrary paths). - Is
--separate-git-dirperhaps a no-op or safely sandboxed forclonespecifically (unlikeinit)? No — confirmed empirically: the option reaches the realgitbinary unmodified and git honors it exactly as documented, writing the full metadata tree to the given path. - Could this be the exact bug already covered by one of the 26 published GHSAs? Checked all 26 entries in
_known-advisories.json(Filter 0):GHSA-9rj7-rf2p-w77rcovers--templateinRepo.init;GHSA-6p8h-3wgx-97gfcovers--templatein clone (already fixed, present inunsafe_git_clone_options);GHSA-hmq2-w58f-27jccovers arbitrary repo creation via unvalidated.gitmodulessubmodule names (a different code path —Submodule, notRepo.clone_from()kwargs). None reference--separate-git-diron the clone path. This is a distinct, currently-unpatched gap. - Does this require an unrealistic precondition? The precondition (host app forwards a kwarg into
clone_from/clone) is identical to the precondition already accepted by the maintainers for the sibling entries in the same list (--template,--upload-pack,--config,--bundle-uri) — i.e. it is the same threat model the guard exists to cover, just missing one entry. - Verdict: no concrete blocker found. CONFIRMED.
Remediation
Add "--separate-git-dir" (and its - alias if git ever adds one — currently there is none) to Repo.unsafe_git_clone_options in git/repo/base.py, matching unsafe_git_init_options. Since Repo._clone() already special-cases separate_git_dir for Git.polish_url() normalization, the fix is a one-line addition to the existing list, consistent with how GHSA-6p8h-3wgx-97gf added --template to the same list.
Confidence
High. Root cause is a one-line, unambiguous omission the maintainers' own docstring contradicts; PoC reproduces cleanly and deterministically against the current HEAD; no plausible false-positive path found.
Proof-of-Concept source (gitpython-001-poc.py)
1#!/usr/bin/env python3 2""" 3GITPYTHON-001 PoC: Repo.clone_from(separate_git_dir=...) is not in 4unsafe_git_clone_options, so it reaches `git clone` unguarded and writes a 5full git directory (config, hooks/, objects/, refs/, ...) to an 6attacker-controlled path OUTSIDE the intended destination directory, with 7allow_unsafe_options left at its default of False. 8 9Run against the GitPython source tree under test, e.g.:10 PYTHONPATH="<repo>:<repo>/gitdb:<repo>/smmap" python3 gitpython-001-poc.py <workdir>11 12Benign: only writes/reads inside the given workdir. No destructive/exfiltrating13payload. Exits non-zero and prints "NOT VULNERABLE" if the guard blocks the option14or the write does not escape the destination directory.15"""16import os17import sys18import subprocess19 20 21def main():22 workdir = sys.argv[1] if len(sys.argv) > 1 else "/tmp/gitpython-001-poc"23 src = os.path.join(workdir, "src")24 dest = os.path.join(workdir, "dest")25 sentinel_dir = os.path.join(workdir, "OUTSIDE_SENTINEL")26 target_gitdir = os.path.join(sentinel_dir, "redirected.git")27 28 for p in (src, dest, sentinel_dir):29 os.makedirs(p, exist_ok=True)30 31 # Minimal benign source repo to clone from.32 subprocess.run(["git", "init", "-q", "-b", "main", src], check=True)33 subprocess.run(["git", "-C", src, "config", "user.email", "test@example.com"], check=True)34 subprocess.run(["git", "-C", src, "config", "user.name", "Test"], check=True)35 with open(os.path.join(src, "file.txt"), "w") as f:36 f.write("hello\n")37 subprocess.run(["git", "-C", src, "add", "file.txt"], check=True)38 subprocess.run(["git", "-C", src, "commit", "-q", "-m", "init"], check=True)39 40 import git # gitpython under test41 42 print("unsafe_git_clone_options =", git.Repo.unsafe_git_clone_options)43 assert "--separate-git-dir" not in git.Repo.unsafe_git_clone_options, (44 "guard now includes --separate-git-dir; PoC no longer applicable, target patched"45 )46 47 try:48 repo = git.Repo.clone_from(src, dest, separate_git_dir=target_gitdir)49 except git.exc.UnsafeOptionError as e:50 print("NOT VULNERABLE: blocked by UnsafeOptionError:", e)51 sys.exit(1)52 53 wrote_outside = os.path.isdir(os.path.join(target_gitdir, "hooks")) and os.path.isfile(54 os.path.join(target_gitdir, "config")55 )56 gitlink_points_outside = False57 with open(os.path.join(dest, ".git")) as f:58 gitlink = f.read().strip()59 gitlink_points_outside = target_gitdir in gitlink60 61 print("repo.git_dir =", repo.git_dir)62 print("wrote git directory outside dest (sentinel) =", wrote_outside)63 print("dest/.git gitlink points outside dest =", gitlink_points_outside)64 65 if wrote_outside and gitlink_points_outside:66 print("VULNERABLE: git directory created at attacker-controlled path "67 f"outside the clone destination: {target_gitdir}")68 sys.exit(0)69 else:70 print("NOT VULNERABLE: sentinel not observed")71 sys.exit(1)72 73 74if __name__ == "__main__":75 main()AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 8
링크 내용 불러오는 중…