/

CVE-2026-45570

Severity:

CRITICAL RISK

(9.6)

Improper Input Encoding in SSH Exec Command (CWE-116) in go-git SSH Transport

CVE-2026-45570

Analyzed

Vulnerability type

Category:

Improper Output Encoding / Command Construction

CWE:

CWE-116

Impact:

Remote Command Injection via SSH Transport

Severity:

CRITICAL RISK

(9.6)

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

go-git's SSH transport constructs a remote shell exec command by wrapping the repository path in single quotes without properly escaping embedded single quotes.

If an attacker can influence the repository path used over SSH, they may be able to break out of the quoted string and inject additional shell tokens, potentially leading to arbitrary command execution on the remote Git server.

Affected context

The vulnerability arises in applications that use go-git to interact with Git repositories over SSH.

Specifically, it affects the SSH transport layer where the remote command is built as a shell exec invocation (e.g., ssh user@host 'git-upload-pack <path>') and the repository path can include attacker-controlled characters.

The issue typically manifests when:

  • Repository URLs, names, or paths are derived from user-controlled or partially trusted input, and
  • The server side or intermediate service executes a shell command constructed by go-git with that path.

Exploit preconditions

  • Attack surface: SSH-based Git operations using go-git (e.g., clone, fetch, push over SSH).
  • Required access: Ability to supply or influence the repository path (e.g., via repository URLs, multi-tenant project names, or path parameters).
  • Trigger point: Invocation of the SSH transport, where go-git builds a shell command that embeds the repository path inside single quotes.
  • Why exploitation is possible: The repository path is not properly escaped for single-quoted shell contexts. An embedded single quote in the path can terminate the quoted string and introduce additional shell tokens, allowing injection of unintended arguments or commands.

Why this happens

The core issue is improper encoding and sanitization of untrusted data when constructing a shell command string.

go-git's SSH transport wraps the repository path in single quotes to protect it from shell interpretation but fails to escape single quotes within the path itself.

This maps to CWE-116: Improper Encoding or Escaping of Output, where data that will be interpreted by a command interpreter (the shell) is not safely encoded for that context.

Rather than using structured APIs that bypass the shell or a dedicated escaping routine, the implementation relies on naive string concatenation, leaving room for command injection.

Potential impact

  • Remote execution of unintended shell commands on the Git server process host
  • Modification, exfiltration, or destruction of repositories hosted on the affected server
  • Lateral movement by executing arbitrary programs available on the server
  • Escalation of impact if the Git service runs with elevated privileges or broad filesystem access
  • Disruption of service availability through crafted repository paths that cause failures or crashes

General mitigation guidance

Effective mitigation focuses on treating repository paths as untrusted data and ensuring they are never interpolated into shell commands without proper handling.

Recommended defensive patterns include:

  • Avoiding shell-based command construction entirely by using APIs or libraries that invoke Git subcommands without a shell interpreter.
  • Applying strict escaping routines tailored to the shell and quoting strategy, including correct handling of single quotes in single-quoted strings.
  • Performing rigorous validation and normalization of repository paths before use, allowing only expected character sets and formats.
  • Running Git-related services with least privilege and constrained environments (e.g., restricted user accounts, limited filesystem access) to reduce blast radius if injection occurs.
  • Designing higher-level application logic so that user-controlled components never directly influence low-level transport commands without mediation.

How teams detect issues like this

Detection typically involves reviewing how commands are built and how user-controlled inputs flow into command execution paths.

Useful approaches include:

  • Static analysis rules that flag shell command construction using string concatenation or formatting with unescaped parameters.
  • Code review checklists that explicitly require verification of escaping or avoidance of shell invocation for any SSH or Git command execution.
  • Data flow analysis to track user-controlled repository URLs/paths into the SSH transport layer and confirm that appropriate encoding is applied.
  • Security linters or automated CI checks that search for known-dangerous patterns (e.g., "'"+path+"'" in shell contexts) and enforce approved helper functions for command construction.
  • Runtime monitoring or logging of unusual SSH command invocations, such as repository paths containing shell metacharacters, to detect potential abuse.

Sources

SourceLink
github.comgithub.com/go-git/go-git/security/advisories/GHSA-m7cr-m3pv-hgrp

Frequently asked

questions

Exploitability depends on whether an attacker can control or meaningfully influence the repository path used in SSH operations. In multi-tenant or user-facing systems that construct repository paths from user data, the exposure can be significant and remote.

Often some form of logical access is required, such as the ability to create or reference repositories by name, but not necessarily privileged access. If anonymous or low-privilege users can supply repository URLs or names that are passed into go-git's SSH transport, they may be able to trigger exploitation.

The safest pattern is to avoid constructing shell commands via string concatenation and instead use APIs that do not invoke a shell at all. If shell usage is unavoidable, apply robust, context-aware escaping for all interpolated values and centralize this logic in well-reviewed helper functions.

Adopt a development guideline that forbids direct insertion of untrusted data into shell commands, enforce this via static analysis and code review, and prefer parameterized or shell-free execution APIs. Additionally, validate and normalize all repository-related inputs and treat them as untrusted regardless of their source.

Find out what's already
exploitable in your codebase.