CVE-2026-5917 Overview
CVE-2026-5917 is a shell command injection vulnerability in libgit2 versions v0.27.0 through v1.9.0 when built with the libssh2 SSH backend (USE_SSH=libssh2). The gen_proto() function in ssh_libssh2.c inserts a repository path directly into a shell command string without escaping shell metacharacters before passing it to libssh2_channel_exec(). Remote attackers can supply repository paths containing single quotes, semicolons, or pipes to execute arbitrary commands on the SSH server under the victim's SSH user account. The flaw is classified under [CWE-78] (Improper Neutralization of Special Elements used in an OS Command).
Critical Impact
A malicious .gitmodules file can trigger arbitrary command execution on a remote SSH server during a recursive clone by any client using an affected libgit2 build.
Affected Products
- libgit2 versions v0.27.0 through v1.9.0
- Applications linking libgit2 built with USE_SSH=libssh2
- Downstream tooling that performs recursive Git clones using libgit2
Discovery Timeline
- 2026-08-11 - CVE-2026-5917 published to NVD
- 2026-08-12 - Last updated in NVD database
Technical Details for CVE-2026-5917
Vulnerability Analysis
The vulnerability resides in the SSH transport layer of libgit2 when compiled against libssh2. During SSH-based Git operations, libgit2 constructs a remote shell command such as git-upload-pack '<repo-path>' to invoke the Git service on the remote host. The gen_proto() function in ssh_libssh2.c concatenates the caller-supplied repository path into this command string with no shell escaping. The resulting command is handed to libssh2_channel_exec(), which executes it under the remote user's login shell. Any shell metacharacter present in the repository path is interpreted by the remote shell, turning path parsing into arbitrary command execution.
Exploitation is straightforward through Git submodules. An attacker publishes a repository containing a .gitmodules file whose submodule URL embeds shell metacharacters in the path component. When a victim runs a recursive clone with a vulnerable libgit2 client, libgit2 opens an SSH channel to the attacker-controlled host and expands the malicious path into the exec command. The remote shell then interprets injected operators such as ;, |, or command substitution, executing whatever the attacker chose.
Root Cause
The root cause is missing input neutralization in gen_proto(). The function trusts the repository path component of an SSH URL and performs string concatenation rather than shell-safe quoting. Because libssh2_channel_exec() runs the argument through the remote shell, any metacharacter in the path is executed rather than treated as literal text.
Attack Vector
The attack vector is network-based and requires limited user interaction: the victim must clone or update a repository that references a malicious submodule. Delivery paths include public repositories, pull requests that modify .gitmodules, and internal mirrors that fetch untrusted upstreams. Execution occurs on the SSH server side with the privileges of the SSH user targeted by the malicious URL, and can pivot to the client host if the client trusts server output. See the VulnCheck Advisory on libgit2 for additional technical detail.
Detection Methods for CVE-2026-5917
Indicators of Compromise
- .gitmodules entries whose url field contains shell metacharacters such as ', ;, |, $(, or backticks in the path portion of an SSH URL.
- SSH server audit logs showing exec requests with git-upload-pack or git-receive-pack arguments containing unexpected shell operators.
- Child processes of the SSH daemon spawning shells or non-Git binaries immediately after a Git protocol session.
Detection Strategies
- Inspect ingested repositories for .gitmodules files and parse each submodule URL, flagging any path component that contains characters outside a strict allowlist.
- On SSH servers, log the full command line passed to the user shell and alert on Git service invocations that include shell metacharacters.
- Inventory build artifacts that link libgit2 and identify those compiled with the libssh2 backend using ldd, otool -L, or package metadata.
Monitoring Recommendations
- Monitor endpoints and CI runners for unexpected process ancestry where git, sshd, or libgit2-based tools spawn sh, bash, or scripting interpreters.
- Forward SSH server authentication and channel-exec telemetry to a centralized log store for correlation across hosts.
- Track outbound SSH connections from developer workstations and build systems to unapproved Git hosts.
How to Mitigate CVE-2026-5917
Immediate Actions Required
- Upgrade libgit2 to a fixed release beyond v1.9.0 as published by the maintainers on the GitHub libgit2 Repository.
- Rebuild and redistribute any downstream applications, language bindings, or container images that statically link or bundle libgit2.
- Audit CI/CD pipelines and developer workstations for recursive clones of untrusted repositories performed since libgit2 v0.27.0 was deployed.
Patch Information
Apply the upstream fix from the libgit2 maintainers, which adds shell-safe quoting to the repository path before it is passed to libssh2_channel_exec(). Distribution packages that ship libgit2 with the libssh2 backend must be refreshed. Alternatively, rebuild libgit2 against a non-libssh2 SSH transport that does not invoke a remote shell in the vulnerable manner.
Workarounds
- Build libgit2 without the libssh2 backend by omitting USE_SSH=libssh2 at configuration time.
- Disable recursive submodule processing in automated workflows and require manual review of .gitmodules changes.
- Restrict Git clients to trusted remotes using network policy or Git configuration allowlists until patched binaries are deployed.
# Configuration example: build libgit2 without the vulnerable SSH backend
cmake -DUSE_SSH=OFF -B build -S .
cmake --build build
# Or, in CI, avoid recursive submodule resolution on untrusted inputs
git clone <repo> # no --recursive
git -c protocol.ext.allow=never submodule update --init --depth=1
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

