CVE-2024-52308 Overview
The GitHub CLI version 2.6.1 and earlier contains a critical remote code execution vulnerability that can be exploited through a malicious codespace SSH server. When developers use the gh codespace ssh or gh codespace logs commands, the CLI retrieves SSH connection details including the remote username from the codespace's devcontainer. A malicious third-party devcontainer with a modified SSH server can inject malicious SSH arguments within these connection details, leading to arbitrary code execution on the user's workstation.
Critical Impact
Attackers can achieve remote code execution on developer workstations by hosting malicious devcontainers that inject commands through crafted SSH usernames, potentially compromising development environments and source code.
Affected Products
- GitHub CLI versions prior to 2.62.0
- GitHub CLI version 2.6.1 and earlier
- Systems using gh codespace ssh or gh codespace logs commands
Discovery Timeline
- 2024-11-14 - CVE CVE-2024-52308 published to NVD
- 2024-11-20 - Last updated in NVD database
Technical Details for CVE-2024-52308
Vulnerability Analysis
This vulnerability represents a Command Injection flaw (CWE-77) in the GitHub CLI's handling of SSH connection details from codespace environments. When developers connect to remote codespaces, they rely on an SSH server running within the devcontainer, typically provided through GitHub's default devcontainer image. The GitHub CLI retrieves SSH connection parameters, including the remote username, and passes these directly to the system's ssh command without proper validation.
The core issue stems from the lack of input sanitization when constructing SSH commands. The remote username retrieved from the codespace is incorporated directly into the command-line arguments passed to the SSH binary. An attacker who controls the devcontainer can craft a malicious username containing SSH options and shell metacharacters that alter the behavior of the SSH command execution.
Root Cause
The root cause lies in the GitHub CLI's trust of user-controlled data from the remote codespace environment. Specifically, the SSH connection details including the username are retrieved via RPC calls to the codespace and then used directly in constructing shell commands. The code paths in internal/codespaces/rpc/invoker.go and pkg/cmd/codespace/ssh.go did not validate or sanitize the remote username before incorporating it into SSH command arguments.
Attack Vector
The attack exploits the command injection vulnerability by embedding malicious SSH options within the remote username field. An attacker creates a malicious devcontainer with a modified SSH server that returns a crafted username such as -oProxyCommand="echo hacked" #. When the victim connects using gh codespace ssh or views logs with gh codespace logs:
- The GitHub CLI retrieves the malicious username from the codespace
- The CLI constructs an SSH command incorporating the username
- The -oProxyCommand flag causes SSH to execute the attacker's command
- The # shell comment character causes subsequent legitimate SSH arguments to be ignored
- Arbitrary code executes on the victim's local workstation with their privileges
This attack requires user interaction—the victim must connect to the malicious codespace—but requires no privileges on the victim's system beyond what the user already has.
Detection Methods for CVE-2024-52308
Indicators of Compromise
- Unexpected SSH connections from GitHub CLI with unusual -o options in process command lines
- Processes spawned as children of SSH connections initiated by gh codespace commands
- Suspicious outbound network connections from processes spawned during codespace SSH sessions
- Log entries showing gh codespace ssh or gh codespace logs commands with malformed usernames
Detection Strategies
- Monitor process creation events for SSH commands containing -oProxyCommand or other injection patterns
- Audit GitHub CLI version across development environments to identify vulnerable installations
- Implement endpoint detection rules for unusual process trees originating from gh CLI executions
- Review devcontainer configurations in repositories for suspicious SSH server modifications
Monitoring Recommendations
- Enable command-line auditing on developer workstations to capture SSH command arguments
- Configure SentinelOne Singularity to alert on suspicious SSH command patterns and process injection behaviors
- Monitor for unexpected child processes of SSH sessions initiated through the GitHub CLI
- Implement repository scanning to detect potentially malicious devcontainer configurations
How to Mitigate CVE-2024-52308
Immediate Actions Required
- Upgrade GitHub CLI to version 2.62.0 or later immediately across all development environments
- Audit recent gh codespace ssh and gh codespace logs usage for connections to untrusted repositories
- Review and verify devcontainer configurations in any third-party repositories before connecting
- Temporarily avoid using gh codespace ssh or gh codespace logs with untrusted codespaces until patched
Patch Information
The vulnerability has been patched in GitHub CLI version 2.62.0. The fix implements proper validation of the remote username information before it is used in SSH command construction, preventing injection of malicious SSH arguments. Users should update their GitHub CLI installation to version 2.62.0 or later. For detailed information, see the GitHub Security Advisory.
Workarounds
- Only connect to codespaces from trusted repositories with verified devcontainer configurations
- Manually inspect devcontainer configurations before initiating codespace SSH sessions
- Use alternative SSH connection methods that do not rely on GitHub CLI's automatic username retrieval
- Implement network segmentation to limit potential damage from workstation compromise
# Upgrade GitHub CLI to patched version
# On macOS with Homebrew:
brew upgrade gh
# On Linux with apt:
sudo apt update && sudo apt install gh
# Verify installed version is 2.62.0 or later:
gh --version
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

