Severity:

HIGH RISK

(8.1)

Command Injection in shell-quote quote()

CVE-2026-9277

Deferred

Vulnerability type

Category:

Command Injection

CWE:

CWE-77, CWE-78

Impact:

Shell Command Injection / Remote Code Execution (dependent on caller)

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

shell-quote's quote() function accepted object tokens with operator fields (.op) that were not validated against the parser's control-operator model, allowing newline characters to pass through unescaped.

Because POSIX shells treat a literal newline as a command separator, attacker-controlled input reaching .op or related shapes could inject additional shell commands, leading to command execution under specific usage patterns.

Affected context

The vulnerability appears in JavaScript/Node.js environments that use the shell-quote library to safely construct shell command strings.

It becomes relevant when applications:

  • Use quote() with object tokens constructed from external or semi-trusted input, and
  • Rely on parse(cmd, envFn) with envFn returning object tokens whose .op or related fields are influenced by user-controlled values.

In these contexts, developers may assume shell-quote enforces a safe operator model and escapes all dangerous characters, including line terminators, which was not the case.

Exploit preconditions

  • Attack surface: Code paths that:
  • Call quote() with object tokens like { op: ... }, { op: 'glob', pattern }, or { comment } derived from user or environment input, or
  • Use parse(cmd, envFn) where envFn returns object tokens including attacker-influenced .op values.
  • Required access: Ability to supply or influence data that is transformed into these object tokens, either directly or through envFn logic.
  • Trigger point: The vulnerable behavior is triggered when quote() processes an object token whose .op (or related fields) contains a line terminator (e.g., \n, \r, U+2028, U+2029), which is passed into a shell command line.
  • Why exploitation is possible: The per-character backslash escaping used /(.)/g, which does not match line terminators in JavaScript regexes. As a result, newline characters in .op were not escaped, and POSIX shells interpret literal newlines as command separators, effectively allowing concatenation of a second command segment under attacker influence.

Why this happens

The core bug lies in inconsistent validation between parsing and quoting logic:

  • parse() implements a specific operator model and expects operators to come from a restricted set of tokens representing shell control operators.
  • quote() assumed that object tokens already adhere to this operator model and attempted to escape .op by backslash-escaping each character via a regex (/(.)/g).

In JavaScript, /(.)/g does not match line terminators, meaning newline and similar characters bypassed escaping.

Because object tokens could be constructed directly from external input or via envFn in parse(), unvalidated .op values could contain line terminators that were preserved in the resulting shell string.

This maps to:

  • CWE-77: Improper Neutralization of Special Elements used in a Command ('Command Injection'), where shell metacharacters (here, newlines acting as command separators) are not properly neutralized.
  • CWE-78: Improper Neutralization of Special Elements used in an OS Command, reflecting that attacker-controlled shell fragments can influence OS-level command execution when the resulting string is passed to a shell.

Potential impact

  • Application-level shell commands may be extended with attacker-controlled second commands separated by newlines.
  • Scripts that invoke system utilities via child_process and shell-quote could run unintended shell pipelines or sequences.
  • Environment-dependent data processing (e.g., building commands from env or configuration) can be subverted, resulting in execution of arbitrary shell commands within the privileges of the calling process.
  • Logging or debugging helpers that later route constructed commands into a shell may inadvertently enable command injection paths.

General mitigation guidance

Effective mitigation focuses on aligning token validation with the parser's operator model and minimizing trust in complex token shapes:

  • Validate object tokens passed to quote() against a strict schema, ensuring .op values are drawn from a known, fixed set of control operators and disallowing line terminators in any operator-like field.
  • Treat specialized object tokens such as { op: 'glob', pattern } or { comment } as strongly typed structures, validating both their shape and contents (including forbidding line terminators and other shell control characters where not explicitly required).
  • Prefer simple string tokens for untrusted input, letting shell-quote or similar libraries escape them as data rather than operators, and avoid allowing untrusted input to decide whether something is an operator, glob, or comment.
  • Reduce reliance on shells for command execution when possible by using APIs that pass arguments as arrays (e.g., execFile-like patterns), ensuring the shell is not involved in interpretation of constructed strings.
  • Apply least-privilege principles so that processes constructing and executing shell commands run with minimal permissions, limiting the blast radius if misquoting occurs.

How teams detect issues like this

To detect similar issues, organizations can:

  • Use static analysis or linters to flag:
  • Calls to quote() with object literals or dynamic object tokens derived from untrusted input.
  • Custom envFn functions passed to parse() that construct object tokens from request parameters, environment variables, or configuration without explicit validation.
  • Incorporate code review checklists that require:
  • Verification that any use of operator-like fields (.op) is limited to known constants.
  • Inspection of any custom tokenization or wrapping logic mixing untrusted data with shell control operators.
  • Configure security testing (SAST/DAST) to:
  • Exercise command-building code paths with inputs containing newlines and other control characters, observing whether resulting commands are split into multiple segments.
  • Use automated dependency and configuration scanning tools to:
  • Highlight modules or internal wrappers that implement custom "shell quoting" logic, prompting focused security review on their handling of line terminators and operators.

Sources

SourceLink
github.comgithub.com/ljharb/shell-quote
github.comgithub.com/ljharb/shell-quote/commit/1518179
github.comgithub.com/ljharb/shell-quote/security/advisories/GHSA-w7jw-789q-3m8p
npmjs.comnpmjs.com/package/shell-quote
openwall.comopenwall.com/lists/oss-security/2026/05/23/2
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26072
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26077
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26079
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26080
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26090
access.redhat.comaccess.redhat.com/errata/RHSA-2026:26225
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28010
access.redhat.comaccess.redhat.com/errata/RHSA-2026:28571
access.redhat.comaccess.redhat.com/errata/RHSA-2026:29197
access.redhat.comaccess.redhat.com/errata/RHSA-2026:29795
access.redhat.comaccess.redhat.com/errata/RHSA-2026:29834
access.redhat.comaccess.redhat.com/errata/RHSA-2026:30076
access.redhat.comaccess.redhat.com/errata/RHSA-2026:33574
access.redhat.comaccess.redhat.com/errata/RHSA-2026:33683
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34342
access.redhat.comaccess.redhat.com/errata/RHSA-2026:34791
access.redhat.comaccess.redhat.com/errata/RHSA-2026:36754
access.redhat.comaccess.redhat.com/errata/RHSA-2026:40765
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41066
access.redhat.comaccess.redhat.com/errata/RHSA-2026:41928
access.redhat.comaccess.redhat.com/errata/RHSA-2026:42796
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44237
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44263
access.redhat.comaccess.redhat.com/errata/RHSA-2026:44267
access.redhat.comaccess.redhat.com/errata/RHSA-2026:48699
access.redhat.comaccess.redhat.com/errata/RHSA-2026:50850
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-9277
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2480741
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-9277.json

Frequently asked

questions

Exploitability depends on how the application uses shell-quote. If applications only pass simple strings to quote(), exposure is lower. The risk increases when object tokens are constructed from controllable input or envFn returns attacker-influenced tokens that are later executed by a shell.

An attacker needs the ability to control data that becomes part of .op or related fields in object tokens passed to quote(), or input processed by parse(cmd, envFn) where envFn constructs such tokens. This may come from HTTP parameters, environment variables, configuration files, or other external sources, depending on the application design.

The safest pattern is to enforce strict shape and value validation on all object tokens, aligning them with an explicit allowlist of operators and disallowing line terminators in operator, glob, and comment fields. Additionally, ensure that untrusted input is always treated as data (plain arguments) rather than control operators.

Future code should avoid mixing untrusted input with operator semantics, use typed abstractions for control tokens, and rely on APIs that separate command and arguments instead of building shell command strings. Security reviews and automated checks should explicitly verify that token validators and parsers share the same model for operators and that all control characters, including line terminators, are either disallowed or carefully handled.

Find out what's already
exploitable in your codebase.