# GHSA-fwj4-72fm-c93g: Under-validated ComSpec and cmd.exe resolution in Mutagen projects

> Attackers can execute arbitrary commands on Windows by manipulating ComSpec or PATH environment variables to hijack shell resolution in Mutagen.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 5 May 2023
- **Also known as:** GO-2023-1758

## What is GHSA-fwj4-72fm-c93g?

GHSA-fwj4-72fm-c93g is a command injection vulnerability in github.com/mutagen-io/mutagen, published on 5 May 2023. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

### Impact

Mutagen projects offer shell-based execution functionality.  On Windows, the shell is resolved using the standard `%ComSpec%` mechanism, with a fallback to a `%PATH%`-based search for `cmd.exe`.  While this is the standard practice on Windows systems, it presents somewhat risky behavior.

Firstly, `%ComSpec%` could, in theory, be set maliciously.  Unfortunately, there's not much that can be done to prevent this attack surface, because `%ComSpec%` is the official mechanism for shell specification on Windows.  We can, however, validate that it points to an absolute path, which one would expect for a properly set value.

Secondly, a fallback to a relative `cmd.exe` path, resolved via `%PATH%`, could be risky.  The risk is largely mitigated by changes in Go 1.19 and later, but prior to that a malicious `cmd.exe` could been resolved in the current working directory.  To mitigate this issue, Mutagen now uses the `%SystemRoot%` environment variable (also validated to be an absolute path) to resolve `cmd.exe` in the event that `%ComSpec%` is not set correctly.

### Patches

The problem has been patched in Mutagen v0.16.6 and v0.17.1. Earlier versions of Mutagen are no longer supported and will not be patched. Versions of Mutagen after v0.18.0 will also have the patch merged.

### Workarounds

Maintain control of the environment variable settings on your system, in particular the `ComSpec` environment variable.

### References

More information on `%ComSpec%` can be found [online](https://en.wikipedia.org/wiki/COMSPEC).

More information on Go's `PATH`-based lookup changes can be found [here](https://go.dev/blog/path-security), [here](https://go.dev/doc/go1.19#os-exec-path), and [here](https://github.com/golang/go/issues/43947).

A [similar issue](https://github.com/python/cpython/issues/101283) that was addressed within the Python subprocess module also provides additional discussion.

## Which versions are affected by GHSA-fwj4-72fm-c93g?

5 open source packages ship an affected version, including github.com/mutagen-io/mutagen.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/mutagen-io/mutagen` | Go | All versions | 0.16.6, 0.17.1 |
| `github.com/mutagen-io/mutagen` | Go | All versions | 0.16.6 |
| `github.com/mutagen-io/mutagen` | Go | All versions | 0.16.6 |
| `github.com/mutagen-io/mutagen` | Go | From 0.17.0 | 0.17.1 |
| `github.com/mutagen-io/mutagen` | Go | From 0.17.0 | 0.17.1 |

## How do I fix GHSA-fwj4-72fm-c93g?

Upgrade github.com/mutagen-io/mutagen to a fixed version for your release line: 0.16.6 or 0.17.1.

## Is GHSA-fwj4-72fm-c93g being exploited?

There is no known exploitation of GHSA-fwj4-72fm-c93g in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-fwj4-72fm-c93g and fix it if it is affected.

What it is: GHSA-fwj4-72fm-c93g is a command injection vulnerability in github.com/mutagen-io/mutagen, published on 5 May 2023. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-fwj4-72fm-c93g in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/mutagen-io/mutagen (Go): affected all versions; fixed in 0.16.6, 0.17.1
- github.com/mutagen-io/mutagen (Go): affected all versions; fixed in 0.16.6
- github.com/mutagen-io/mutagen (Go): affected all versions; fixed in 0.16.6
- github.com/mutagen-io/mutagen (Go): affected from 0.17.0; fixed in 0.17.1
- github.com/mutagen-io/mutagen (Go): affected from 0.17.0; fixed in 0.17.1

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-fwj4-72fm-c93g/ (Markdown: https://insights.sbomify.com/GHSA-fwj4-72fm-c93g/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-fwj4-72fm-c93g

---
From sbomify Insights: https://insights.sbomify.com/GHSA-fwj4-72fm-c93g/
Summaries are generated and may contain mistakes; the official description above is the record.
