Skip to main content

CVE-2022-23642: CWE-94: Improper Control of Generation of Code ('Code Injection') in sourcegraph sourcegraph

Medium
Published: Fri Feb 18 2022 (02/18/2022, 22:15:11 UTC)
Source: CVE
Vendor/Project: sourcegraph
Product: sourcegraph

Description

Sourcegraph is a code search and navigation engine. Sourcegraph prior to version 3.37 is vulnerable to remote code execution in the `gitserver` service. The service acts as a git exec proxy, and fails to properly restrict calling `git config`. This allows an attacker to set the git `core.sshCommand` option, which sets git to use the specified command instead of ssh when they need to connect to a remote system. Exploitation of this vulnerability depends on how Sourcegraph is deployed. An attacker able to make HTTP requests to internal services like gitserver is able to exploit it. This issue is patched in Sourcegraph version 3.37. As a workaround, ensure that requests to gitserver are properly protected.

AI-Powered Analysis

AILast updated: 06/22/2025, 03:06:51 UTC

Technical Analysis

CVE-2022-23642 is a vulnerability affecting Sourcegraph versions prior to 3.37, specifically in the 'gitserver' service component. Sourcegraph is a widely used code search and navigation engine that integrates with git repositories to facilitate code management and review. The 'gitserver' service acts as a proxy for git exec commands, but it improperly restricts the use of the 'git config' command. This flaw allows an attacker who can send HTTP requests to internal services, such as gitserver, to manipulate the git configuration by setting the 'core.sshCommand' option. This option controls the command git uses instead of the default ssh client when connecting to remote systems. By injecting a malicious command into this configuration, an attacker can execute arbitrary code remotely on the system hosting the gitserver service. Exploitation depends heavily on deployment specifics, particularly whether the gitserver service is exposed or accessible internally without adequate protections. The vulnerability is categorized under CWE-94, indicating improper control over code generation, which in this case manifests as a code injection vulnerability. Although no public exploits have been reported in the wild, the risk remains significant due to the potential for remote code execution (RCE). The issue was addressed and patched in Sourcegraph version 3.37. Until patching, mitigating the risk involves ensuring that access to the gitserver service is tightly controlled and that HTTP requests to this service are properly authenticated and authorized to prevent unauthorized command injection.

Potential Impact

For European organizations, the impact of this vulnerability can be substantial, particularly for enterprises and development teams relying on Sourcegraph for code search and navigation. Successful exploitation could lead to remote code execution on critical infrastructure, potentially allowing attackers to gain control over development environments, access sensitive source code, or pivot to other internal systems. This could result in intellectual property theft, disruption of development workflows, and compromise of software supply chains. Organizations in sectors with stringent data protection regulations, such as finance, healthcare, and critical infrastructure, may face additional compliance risks and reputational damage. The vulnerability's exploitation does not require user interaction but does require network access to the gitserver service, which may be internal or exposed depending on deployment. Thus, organizations with less restrictive internal network segmentation or exposed internal services are at higher risk. The absence of known exploits in the wild reduces immediate threat levels but does not eliminate the risk, especially as attackers could develop exploits targeting unpatched systems.

Mitigation Recommendations

1. Upgrade Sourcegraph instances to version 3.37 or later immediately to apply the official patch addressing this vulnerability. 2. Restrict network access to the gitserver service by implementing strict firewall rules and network segmentation to ensure only authorized systems and users can communicate with it. 3. Implement strong authentication and authorization mechanisms on all internal Sourcegraph services, especially gitserver, to prevent unauthorized HTTP requests. 4. Monitor network traffic and logs for unusual or unauthorized requests targeting the gitserver service, focusing on attempts to manipulate git configuration commands. 5. Conduct regular security audits and penetration testing on Sourcegraph deployments to identify and remediate potential exposure points. 6. If immediate patching is not possible, consider deploying web application firewalls (WAFs) or reverse proxies with custom rules to detect and block suspicious git config command patterns. 7. Educate development and operations teams about the risks of exposing internal services and the importance of secure deployment practices for developer tools.

Need more detailed analysis?Get Pro

Technical Details

Data Version
5.1
Assigner Short Name
GitHub_M
Date Reserved
2022-01-19T00:00:00.000Z
Cisa Enriched
true

Threat ID: 682d9848c4522896dcbf629c

Added to database: 5/21/2025, 9:09:28 AM

Last enriched: 6/22/2025, 3:06:51 AM

Last updated: 7/28/2025, 12:03:09 PM

Views: 10

Actions

PRO

Updates to AI analysis are available only with a Pro account. Contact root@offseq.com for access.

Please log in to the Console to use AI analysis features.

Need enhanced features?

Contact root@offseq.com for Pro access with improved analysis and higher rate limits.

Latest Threats