# CVE-2021-21237: Git LFS can execute a Git binary from the current directory on Windows

> Git LFS on Windows executes a malicious Git binary from the current directory, allowing arbitrary code execution when processing untrusted repositories.

- **Severity:** High 7.2 (`CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 15 Jan 2021
- **Updated:** 3 Aug 2024
- **Also known as:** BIT-git-lfs-2021-21237, GHSA-cx3w-xqmc-84g5, GO-2021-0098

## What is CVE-2021-21237?

CVE-2021-21237 is a high-severity command injection vulnerability in git-lfs, published on 15 Jan 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

Git LFS is a command line extension for managing large files with Git. On Windows, if Git LFS operates on a malicious repository with a git.bat or git.exe file in the current directory, that program would be executed, permitting the attacker to execute arbitrary code. This does not affect Unix systems. This is the result of an incomplete fix for CVE-2020-27955. This issue occurs because on Windows, Go includes (and prefers) the current directory when the name of a command run does not contain a directory separator. Other than avoiding untrusted repositories or using a different operating system, there is no workaround. This is fixed in v2.13.2.

Weakness: CWE-426 (Untrusted Search Path)

## Which versions are affected by CVE-2021-21237?

4 open source packages ship an affected version, including github.com/git-lfs/git-lfs and git-lfs. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/git-lfs/git-lfs` | Go | All versions | 1.5.1-0.20210113180018-fc664697ed2c |
| `github.com/git-lfs/git-lfs` | Go | All versions | 2.13.2 |
| `github.com/git-lfs/git-lfs` | Go | All versions | 2.13.2 |
| `git-lfs` | Bitnami | All versions | 2.13.2 |

Products: Git Large File Storage Project Git Large File Storage.

## How do I fix CVE-2021-21237?

Upgrade github.com/git-lfs/git-lfs to a fixed version for your release line: 1.5.1-0.20210113180018-fc664697ed2c or 2.13.2.

## Is CVE-2021-21237 being exploited?

There is no known exploitation of CVE-2021-21237 in the wild and no public exploit code.

## Other vulnerabilities in git-lfs

- [CVE-2022-24826](https://insights.sbomify.com/CVE-2022-24826/): Git LFS can execute a binary from the current directory on Windows (critical 9.8)
- [CVE-2020-27955](https://insights.sbomify.com/CVE-2020-27955/): Git LFS can execute a Git binary from the current directory (critical 9.8)
- [CVE-2017-17831](https://insights.sbomify.com/CVE-2017-17831/): GitHub Git LFS Arbitrary command execution vulnerability (high 8.8)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-21237 and fix it if it is affected.

What it is: CVE-2021-21237 is a high-severity command injection vulnerability in git-lfs, published on 15 Jan 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-21237 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/git-lfs/git-lfs (Go): affected all versions; fixed in 1.5.1-0.20210113180018-fc664697ed2c
- github.com/git-lfs/git-lfs (Go): affected all versions; fixed in 2.13.2
- github.com/git-lfs/git-lfs (Go): affected all versions; fixed in 2.13.2
- git-lfs (Bitnami): affected all versions; fixed in 2.13.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-21237/ (Markdown: https://insights.sbomify.com/CVE-2021-21237/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-21237
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-21237
- OSV: https://osv.dev/vulnerability/CVE-2021-21237

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-21237/
Summaries are generated and may contain mistakes; the official description above is the record.
