Severity:

HIGH RISK

(8.8)

Shell Command Injection (CWE-78) in libgit2 SSH Backend

CVE-2026-5917

Deferred

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Command Execution on an SSH Server

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

A shell command injection vulnerability in libgit2's libssh2 SSH backend allows repository paths to be incorporated into remote shell commands without adequate escaping. When a crafted submodule URL is processed during a recursive clone, an attacker may cause arbitrary commands to run on the SSH server under the victim's SSH account.

Affected context

The vulnerability affects libgit2 builds that use the libssh2 SSH backend and process SSH repository paths during clone operations, including recursive submodule handling. Risk is present when an attacker can influence a repository or its submodule metadata and a victim's client connects to an attacker-controlled or otherwise malicious SSH repository using an account with shell access.

Exploit preconditions

  • Attack surface: SSH repository access through libgit2's libssh2 backend
  • Required access: Ability to influence a repository path, such as through malicious submodule metadata, and a victim who processes the repository
  • Trigger point: Construction and execution of the remote SSH command during repository or submodule access
  • Why exploitation is possible: The repository path is inserted into a shell command without sufficient escaping, allowing the remote shell to interpret attacker-controlled metacharacters

Why this happens

The vulnerable code constructs a command string from a repository path and passes that string to a remote shell without treating the path as strictly data. Shell metacharacters within attacker-influenced input can therefore alter command interpretation and introduce additional shell operations. This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, commonly known as OS command injection.

Potential impact

  • An attacker may execute arbitrary commands on the SSH server
  • Commands could run with the privileges of the SSH account used by the client
  • Repository contents or server-side data could be modified or disclosed
  • The compromised account could be used for lateral movement or persistence
  • Build, deployment, or source-control infrastructure could be affected

General mitigation guidance

Mitigation generally focuses on ensuring repository paths remain data rather than shell syntax and reducing the privileges available to SSH sessions.

Common defensive patterns include:

  • Avoiding shell command construction when invoking remote operations
  • Using argument-safe APIs or protocol-native operations that do not invoke a shell
  • Applying strict validation and canonicalization to repository and submodule paths
  • Treating repository metadata, including submodule URLs, as untrusted input
  • Restricting SSH accounts to the minimum repository operations and filesystem permissions
  • Disabling unnecessary shell capabilities and isolating automated clone or build environments
  • Requiring review and policy checks for externally sourced repositories

How teams detect issues like this

Organizations can look for this class of issue through:

  • Static analysis rules identifying string concatenation or interpolation in shell command construction
  • Code review checks for repository paths or URLs passed directly to command-execution APIs
  • Policy enforcement that prohibits shell interpretation for externally controlled arguments
  • Tests using metacharacter-bearing input to verify that paths remain literal data
  • Monitoring SSH server command logs and unexpected child processes launched by repository accounts
  • Automated security review tools that flag OS command construction involving untrusted input

Sources

SourceLink
github.comgithub.com/libgit2/libgit2/security/advisories/GHSA-xqj4-2j5v-rr75
vulncheck.comvulncheck.com/advisories/libgit2-shell-command-injection-via-ssh-libssh2-backend

Frequently asked

questions

Yes. The attack can be triggered through repository or submodule metadata when a victim's libgit2 client connects to the relevant SSH repository, although the resulting command execution occurs on the SSH server.

An attacker generally needs to influence a repository path or submodule URL and have that metadata processed by a victim using the affected SSH backend. The victim's SSH credentials and the server's acceptance of the connection determine the resulting privileges.

Do not pass attacker-influenced repository paths through a shell command. Prefer protocol-native or argument-safe APIs, and validate paths as data before any remote operation.

Treat repository metadata as untrusted, enforce secure command-construction policies, use least-privilege SSH accounts, isolate automated repository processing, and test boundary inputs during code review and CI.

Find out what's already
exploitable in your codebase.