# GHSA-hxwm-x553-x359: Arbitrary Command Injection due to Improper Command Sanitization

> Attackers can execute arbitrary shell commands via unsanitized Git arguments in the npmcli/git library, requiring user interaction to trigger.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 5 Aug 2021

## What is GHSA-hxwm-x553-x359?

GHSA-hxwm-x553-x359 is a command injection vulnerability in @npmcli/git, published on 5 Aug 2021. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

### Summary
There exists a command injection vulnerability in `npmcli/git` versions <2.0.8 which may result in arbitrary shell command execution due to improper argument sanitization when `npmcli/git` is used to execute Git commands based on user controlled input. 

The impact of this issue is possible Arbitrary Command Injection when `npmcli/git` is run with untrusted (user controlled) Git command arguments. 

### Impact

Arbitrary Command Injection

### Details

`npmcli/git` prior to release `2.0.8` passed user controlled input as arguments to a shell command without properly sanitizing this input. Passing unsanitized input to a shell can lead to arbitrary command injection. For example passing `git+https://github.com/npm/git; echo hello world` would trigger the shell execution of `echo hello world`.  

This issue was remediated by no longer running `npmcli/git` git commands through an intermediate shell.

### Patches

This issue has been patched in release `2.0.8`

### Acknowledgements

This report was reported to us by @tyage (Ierae Security) through the [GitHub Bug Bounty Program](https://bounty.github.com).

## Which versions are affected by GHSA-hxwm-x553-x359?

2 open source packages ship an affected version, including @npmcli/git.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@npmcli/git` | npm | All versions | 2.0.8 |
| `@npmcli/git` | npm | All versions | 2.0.8 |

## How do I fix GHSA-hxwm-x553-x359?

Upgrade @npmcli/git to 2.0.8 or later.

## Is GHSA-hxwm-x553-x359 being exploited?

There is no known exploitation of GHSA-hxwm-x553-x359 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-hxwm-x553-x359 and fix it if it is affected.

What it is: GHSA-hxwm-x553-x359 is a command injection vulnerability in @npmcli/git, published on 5 Aug 2021. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of GHSA-hxwm-x553-x359 in the wild and no public exploit code.

Affected packages and fixed versions:
- @npmcli/git (npm): affected all versions; fixed in 2.0.8
- @npmcli/git (npm): affected all versions; fixed in 2.0.8

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/GHSA-hxwm-x553-x359/ (Markdown: https://insights.sbomify.com/GHSA-hxwm-x553-x359/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-hxwm-x553-x359

---
From sbomify Insights: https://insights.sbomify.com/GHSA-hxwm-x553-x359/
Summaries are generated and may contain mistakes; the official description above is the record.
