CVE-2024-52308: Github.com/cli/cli/v2 Connecting To A Malicious Codespaces Vulnerability

HIGH
Advisory Identifier: GHSA-p2h2-3vg9-4p87
CVSS 8.0
CWE-77
Published
Advisory Summary

CVE-2024-52308 is a HIGH (CVSS 8.0) connecting to a malicious codespaces vulnerability (CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')) affecting Github.com/cli/cli/v2 libraries in the Go ecosystem. The issue involves connecting to a malicious codespaces via gh cli could allow command execution on the user's computer. Remediation is available by upgrading affected packages to version 2.62.0.

CVE-2024-52308 at a Glance

CVE Identifier CVE-2024-52308
GHSA Identifier GHSA-p2h2-3vg9-4p87
Severity HIGH
CVSS v3.1 Base Score 8.0
CWE Classification CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection')
Affected Product Github.com/cli/cli/v2
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 8.0

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required Low (PR:L)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2024-52308

To remediate this vulnerability, upgrade all affected Github.com/cli/cli/v2 dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/cli/cli/v2 fixed: 2.62.0
Upgrade github.com/cli/cli/v2 to 2.62.0
github.com/cli/cli fixed: 2.62.0
Upgrade github.com/cli/cli to 2.62.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/cli/cli/v2

How to Check if You Are Affected

To determine whether your application is affected by CVE-2024-52308, inspect your project dependencies for Github.com/cli/cli/v2:

inspect dependencies for github.com/cli/cli/v2

Analyze the terminal output to locate any version of Github.com/cli/cli/v2 in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 2.62.0), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where the product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component. In Github.com/cli/cli/v2, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary A security vulnerability has been identified in GitHub CLI that could allow remote code execution (RCE) when users connect to a malicious Codespace SSH server and use the `gh codespace ssh` or `gh codespace logs` commands. ### Details The vulnerability stems from the way GitHub CLI handles SSH connection details when executing commands. When developers connect to remote Codespaces, they typically use a SSH server running within a devcontainer, often provided through the [default devcontainer image](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/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#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. ### Impact Successful exploitation could lead to arbitrary code execution on the user's workstation, potentially compromising the user's data and system. ### Remediation and Mitigation 1. Upgrade `gh` to `2.62.0` 2. Exercise caution when using custom devcontainer images, prefer default or pre-built devcontainers from trusted sources.

CVE-2024-52308 Affected Github.com/cli/cli/v2 Versions

2 component(s)
Fixed Versions:
2.62.0
Product / Package Ecosystem Affected Versions Fixed Version
github.com/cli/cli/v2
Go
< 2.62.0
2.62.0
github.com/cli/cli
Go
< 2.62.0
2.62.0

References

Frequently Asked Questions

What is CVE-2024-52308?
CVE-2024-52308 is a security vulnerability in Github.com/cli/cli/v2 involving Connecting to a malicious Codespaces via GH CLI could allow command execution on the user's computer under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection').
Which Github.com/cli/cli/v2 versions are affected?
Affected versions include releases prior to 2.62.0 across affected packages: github.com/cli/cli/v2, github.com/cli/cli.
What version fixes CVE-2024-52308?
Upgrading to 2.62.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/cli/cli/v2 affected?
Yes, github.com/cli/cli/v2 is affected in releases prior to 2.62.0. Upgrade your dependency to 2.62.0 or later.
Is github.com/cli/cli affected?
Yes, github.com/cli/cli is affected in releases prior to 2.62.0. Upgrade your dependency to 2.62.0 or later.
What is the CVSS score of CVE-2024-52308?
CVE-2024-52308 has a CVSS v3.1 base score of 8.0 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2024-52308?
CVE-2024-52308 is classified under CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection') (The product constructs all or part of a command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended command when it is sent to a downstream component.).
How can I check Go dependencies for CVE-2024-52308?
Run the dependency tree command: 'inspect dependencies for github.com/cli/cli/v2'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-p2h2-3vg9-4p87",
  "modified" : "2024-11-19T19:37:12Z",
  "published" : "2024-11-14T17:39:01Z",
  "aliases" : [ "CVE-2024-52308" ],
  "summary" : "Connecting to a malicious Codespaces via GH CLI could allow command execution on the user's computer",
  "details" : "### Summary\n\nA security vulnerability has been identified in GitHub CLI that could allow remote code execution (RCE) when users connect to a malicious Codespace SSH server and use the `gh codespace ssh` or `gh codespace logs` commands.\n\n### Details\n\nThe vulnerability stems from the way GitHub CLI handles SSH connection details when executing commands. When developers connect to remote Codespaces, they typically use a SSH server running within a devcontainer, often provided through the [default devcontainer image](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/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#L263) for `gh codespace ssh` or `gh codespace logs` commands.\n\nThis 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.\n\nIn `2.62.0`, the remote username information is being validated before being used.\n\n### Impact\n\nSuccessful exploitation could lead to arbitrary code execution on the user's workstation, potentially compromising the user's data and system.\n\n### Remediation and Mitigation\n\n1. Upgrade `gh` to `2.62.0`\n2. Exercise caution when using custom devcontainer images, prefer default or pre-built devcontainers from trusted sources.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:L/UI:R/S:C/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/cli/cli/v2"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.62.0"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 2.61.0"
    }
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/cli/cli"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "2.62.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/cli/cli/security/advisories/GHSA-p2h2-3vg9-4p87"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-52308"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/cli/cli"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2024-3269"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-77" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-11-14T17:39:01Z",
    "nvd_published_at" : "2024-11-14T23:15:05Z"
  }
}