/

CVE-2026-28291

Severity:

HIGH RISK

(8.1)

OS Command Injection in simple-git

CVE-2026-28291

Modified

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution via Underlying Git Process

Severity:

HIGH RISK

(8.1)

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

simple-git, a JavaScript library that wraps native Git commands, contains an OS command injection flaw in versions up to and including 3.31.1 due to incomplete blocking of dangerous Git options.

By crafting Git options that bypass the regular-expression-based blocklist, an attacker can cause execution of arbitrary commands through the underlying Git binary when simple-git is used on untrusted input.

Affected context

This vulnerability affects applications that use simple-git (≤3.31.1) to invoke Git operations, particularly when Git options or arguments are influenced by user-controlled or otherwise untrusted input.

The issue manifests in code paths that rely on the unsafe operations plugin's regex blocklist to prevent dangerous options (such as -u or --upload-pack). Because Git supports flexible and compact option combinations (e.g., -vu, -4u, -nu), this blocklist can be bypassed, allowing attackers to inject effective dangerous options through variants that still parse as valid flags to Git.

Exploit preconditions

  • Attack surface: Any API in an application that uses simple-git to run Git commands where command-line options or arguments are derived from external input (HTTP parameters, webhook payloads, configuration files, CI pipeline variables, etc.).
  • Required access: Ability to control or significantly influence Git options or parts of the Git command line passed through simple-git. This can be direct (user-provided CLI flags) or indirect (repository URLs, environment-derived options, or dynamic configuration).
  • Trigger point: Execution of a simple-git operation that engages the unsafe operations plugin's protection logic but still accepts crafted option strings containing dangerous variants (e.g., concatenated short options including u).
  • Why exploitation is possible: The protection relies on a regex-based blocklist of specific string forms (e.g., -u, --upload-pack) and does not replicate Git's full option-parsing semantics. Git interprets many different character combinations as equivalent to the blocked options, allowing bypass of the blocklist and enabling arbitrary command execution through the invoked Git process.

Why this happens

The root cause lies in attempting to secure command execution using a blocklist-based filter against a highly flexible command-line interface without modeling its full parsing rules.

simple-git introduces an "unsafe operations" plugin that scans option strings and rejects known-dangerous options like -u and --upload-pack using regular expressions. However, Git's option parsing allows dense packing and reordering of short options and recognizes numerous syntactic variants that map back to the same semantic behavior.

This creates a mismatch between the filter's simplistic string-level understanding and Git's rich parsing behavior: the filter inspects only literal substrings, while Git reconstructs options from character sequences. As a result, attackers can craft alternative forms that Git still interprets as dangerous options but that do not match the regex, exemplifying CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

Potential impact

  • Execution of arbitrary OS commands in the context of the process using simple-git.
  • Compromise of the host running the Node.js application (including reading or modifying local files accessible to the process).
  • Abuse of CI/CD agents, build servers, or deployment pipelines that rely on simple-git for repository operations.
  • Lateral movement within development or production infrastructure by leveraging the compromised process's network and system privileges.
  • Integrity and confidentiality breaches of source code repositories or associated build artifacts.

General mitigation guidance

Effective mitigation focuses on eliminating blocklist-based command filtering and minimizing the command surface exposed to untrusted input:

  • Prefer allowlist-based argument construction: restrict the Git commands and options to a fixed, hard-coded set and never pass arbitrary option strings directly derived from user input.
  • Use structured parameters instead of raw option strings: map high-level operations (e.g., "clone this repo at branch X") to predefined argument lists, validating each parameter (such as repository URL or branch name) against strict rules (e.g., safe character sets, length bounds, and expected formats).
  • Avoid dynamically building command lines: rely on APIs that accept arrays of arguments, and ensure those arrays are assembled only from validated, normalized values rather than concatenated strings.
  • Apply principle of least privilege to the environment running simple-git: run under non-privileged accounts, avoid unnecessary file system and network permissions, and use containerization or sandboxing where feasible to reduce blast radius.
  • Where dynamic options are truly necessary, perform semantic validation that mirrors Git expectations (e.g., explicit parsing of recognized options and rejection of any option packing or unknown flags), instead of regex-based substring matching.

How teams detect issues like this

The vulnerability can be surfaced and monitored through a combination of static and dynamic techniques:

  • Static analysis and code review:
  • Flag any call sites where simple-git APIs receive user-influenced strings as options, arguments, or repository URLs.
  • Identify patterns of dynamic command construction (string concatenation, template literals, passing through unvalidated query parameters or request bodies).
  • Review uses of the unsafe operations plugin for reliance on regex-based blocklists and absence of allowlisted command/option sets.
  • Policy and configuration enforcement:
  • Establish internal guidelines forbidding raw user input from being passed as CLI options to Git or other system binaries.
  • Introduce pre-merge checks or linters that detect risky patterns like simpleGit(...).raw(userInput) or similarly unguarded APIs.
  • Runtime and monitoring approaches:
  • Instrument logging of Git commands executed via simple-git, capturing arguments in a sanitized form, and alert on suspicious patterns (packed short options, unexpected flags, or out-of-policy parameters).
  • Use host or container-level security tooling (e.g., process monitoring, EDR) to detect anomalous child processes spawned from the Node.js runtime or unusual Git invocation patterns.

Sources

SourceLink
github.comgithub.com/steveukx/git-js/blob/789c13ebabcf18ebe0b3a0c88ebb4037dede42e3/simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts#L26
github.comgithub.com/steveukx/git-js/commit/1effd8e5012a5da05a9776512fac3e39b11f2d2d
github.comgithub.com/steveukx/git-js/releases/tag/simple-git%403.32.0
github.comgithub.com/steveukx/git-js/security/advisories/GHSA-jcxm-m3jx-f287
cve.orgcve.org/CVERecord?id=CVE-2022-25860
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-28291
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2457930
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-28291.json

Frequently asked

questions

It can be, if an application exposes APIs or workflows where remote users control Git options, repository parameters, or other values passed into simple-git. In such setups, a remote attacker may trigger command execution without local access, purely through crafted requests.

The attacker must be able to influence the data that simple-git uses to build Git command lines, such as user-supplied options, repository URLs, or certain configuration fields. They do not need direct shell access, only influence over the parameters that flow into simple-git.

Replace regex or blocklist-based filtering with allowlist-driven command construction: restrict Git operations to a small, well-understood set of commands and options, and validate each user-influenced parameter against strict, structured rules before including it in the argument list passed to Git.

Treat all command-line parameters derived from external sources as untrusted, avoid dynamic string-based command building, and favor higher-level abstractions that map validated inputs to predefined argument arrays. Complement this with secure defaults, least-privilege execution environments, and automated review checks for any code that wraps or invokes system-level commands.

Find out what's already
exploitable in your codebase.