# CVE-2024-52308: Connecting to a malicious Codespaces via GH CLI could allow command execution on the user's computer

> A malicious Codespaces SSH server can inject arguments to execute arbitrary commands on the user's workstation via GitHub CLI.

- **Severity:** High 8.0 (`CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 14 Nov 2024
- **Updated:** 15 Nov 2024
- **Also known as:** AZL-53217, DEBIAN-CVE-2024-52308, GHSA-p2h2-3vg9-4p87, GO-2024-3269, ROOT-OS-DEBIAN-12-CVE-2024-52308, UBUNTU-CVE-2024-52308, USN-7130-1, openSUSE-SU-2024:14509-1, openSUSE-SU-2025:0021-1

## What is CVE-2024-52308?

CVE-2024-52308 is a high-severity command injection vulnerability in cli, published on 14 Nov 2024. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

### Official description

The GitHub CLI version 2.6.1 and earlier are vulnerable to remote code execution through a malicious codespace SSH server when using `gh codespace ssh` or `gh codespace logs` commands. This has been patched in the cli v2.62.0.

Developers connect to remote codespaces through an SSH server running within the devcontainer, which is generally provided through the [default devcontainer image]( https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-... https://docs.github.com/en/codespaces/setting-up-your-project-for-codespaces/adding-a-dev-container-configuration/introduction-to-dev-containers#using-the-default-dev-container-configuration) . GitHub CLI [retrieves SSH connection details]( https://github.com/cli/cli/blob/30066b0042d0c5928d959e288144300cb28196c9/internal/codespaces/rpc/inv... https://github.com/cli/cli/blob/30066b0042d0c5928d959e288144300cb28196c9/internal/codespaces/rpc/invoker.go#L230-L244 ), such as remote username, which is used in [executing `ssh` commands]( https://github.com/cli/cli/blob/e356c69a6f0125cfaac782c35acf77314f18908d/pkg/cmd/codespace/ssh.go#L2... https://github.com/cli/cli/blob/e356c69a6f0125cfaac782c35acf77314f18908d/pkg/cmd/codespace/ssh.go#L263 ) for `gh codespace ssh` or `gh codespace logs` commands.

This exploit occurs when a malicious third-party devcontainer contains a modified SSH server that injects `ssh` arguments within the SSH connection details. `gh codespace ssh` and `gh codespace logs` commands could execute arbitrary code on the user's workstation if the remote username contains something like `-oProxyCommand="echo hacked" #`.  The `-oProxyCommand` flag causes `ssh` to execute the provided command while `#` shell comment causes any other `ssh` arguments to be ignored.

In `2.62.0`, the remote username information is being validated before being used.

Weakness: CWE-77 (Improper Neutralization of Special Elements used in a Command)

## Which versions are affected by CVE-2024-52308?

6 open source packages ship an affected version, including github.com/cli/cli and github.com/cli/cli/v2. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `github.com/cli/cli` | Go | All versions | None |
| `github.com/cli/cli` | Go | All versions | 2.62.0 |
| `github.com/cli/cli` | Go | All versions | 2.62.0 |
| `github.com/cli/cli/v2` | Go | All versions | 2.62.0 |
| `github.com/cli/cli/v2` | Go | All versions | 2.62.0 |
| `github.com/cli/cli/v2` | Go | All versions | 2.62.0 |
| `gh` | SUSE:Package Hub 15 SP6 | All versions | 2.65.0-bp156.2.17.1 |
| `gh` | openSUSE:Leap 15.6 | All versions | 2.65.0-bp156.2.17.1 |
| `gh` | openSUSE:Tumbleweed | All versions | 2.62.0-1.1 |

Products: Github Cli.

## How do I fix CVE-2024-52308?

Upgrade github.com/cli/cli to 2.62.0 or later.

## Is CVE-2024-52308 being exploited?

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

## Other vulnerabilities in cli

- [CVE-2026-48501](https://insights.sbomify.com/CVE-2026-48501/): GitHub CLI tokens leak via `gh attestation` commands (high 7.4)
- [CVE-2026-45803](https://insights.sbomify.com/CVE-2026-45803/): gh: GitHub Actions log output in `gh run view` allows terminal escape sequence injection (low 3.5)

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-52308 and fix it if it is affected.

What it is: CVE-2024-52308 is a high-severity command injection vulnerability in cli, published on 14 Nov 2024. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2024-52308 in the wild and no public exploit code.

Affected packages and fixed versions:
- github.com/cli/cli (Go): affected all versions; no fix listed
- github.com/cli/cli (Go): affected all versions; fixed in 2.62.0
- github.com/cli/cli (Go): affected all versions; fixed in 2.62.0
- github.com/cli/cli/v2 (Go): affected all versions; fixed in 2.62.0
- github.com/cli/cli/v2 (Go): affected all versions; fixed in 2.62.0
- github.com/cli/cli/v2 (Go): affected all versions; fixed in 2.62.0

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-2024-52308/ (Markdown: https://insights.sbomify.com/CVE-2024-52308/index.md)
```

## Sources

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

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