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

High 8.0 Published Updated

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

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

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

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.

PackageAffectedFixed in
github.com/cli/cli GoAll versionsNone
github.com/cli/cli GoAll versions2.62.0
github.com/cli/cli GoAll versions2.62.0
github.com/cli/cli/v2 GoAll versions2.62.0
github.com/cli/cli/v2 GoAll versions2.62.0
github.com/cli/cli/v2 GoAll versions2.62.0
Linux distribution packages (3)
gh SUSE:Package Hub 15 SP6All versions2.65.0-bp156.2.17.1
gh openSUSE:Leap 15.6All versions2.65.0-bp156.2.17.1
gh openSUSE:TumbleweedAll versions2.62.0-1.1

Products include Github Cli.

How do I fix CVE-2024-52308?

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

Upgrade, and pass arguments to programs as a list instead of through a shell. More about Command injection.

Is CVE-2024-52308 being exploited?

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

Sources

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 and 3 more.

Is CVE-2024-52308 in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free