//nefariousplan

CVE-2026-9277: shell-quote's Dot Was Not Every Character

vendor

patterns

cve

proof of concept

The fix is one line. s.op.replace(/(.)/g, '\\$1') becomes an allowlist check, and the replace that survives uses /[\s\S]/g instead of /(.)/g. Both regexes are written to mean "every character." In JavaScript, only one of them does, because . does not match line terminators (\n, \r, \u2028, \u2029), and a POSIX shell treats a literal newline as a command separator. Five years earlier, the same library shipped a patch to the same module that changed [A-z] to [A-Za-z], because [A-z] quietly included [\]^_ and a backtick. Two CVEs, five years apart, same shape: a JavaScript regex character class written to read as exhaustive that was not.

The whole object-token branch was one line

The vulnerable code is the entirety of quote()'s object-token handling in shell-quote 1.8.3, the line CVE-2026-9277 names:

if (s && typeof s === 'object') {
    return s.op.replace(/(.)/g, '\\$1');
}

Pass any object whose .op is a string, get back that string with a backslash prefixed to each character. Pass { op: '||' }, get back \|\|. Pass { op: ';' }, get back \;. The shell sees those backslash-escaped sequences as literal characters, and the control operator is neutralized. This is how quote(parse(cmd)) was supposed to round-trip a parsed operator token back into a string that would not re-execute as an operator.

The reporter sent { op: ';\nid' }. The replace ran. The . matched the ;. The . did not match the \n. The . matched the i. The . matched the d. The output was \; followed by a literal newline followed by \i\d. Concatenated into a shell command and handed to /bin/sh, the shell read past the escaped semicolon, hit the literal newline, treated the newline as a command separator, and ran what followed. \i\d collapses to id because a backslash in front of any non-special character is just that character.

const { quote } = require('shell-quote');
const s = quote([{ op: ';\nid' }]);
console.log(JSON.stringify(s));
// "\\;\nid"
require('child_process').execSync(s, { shell: '/bin/sh' });
// uid=1000(...)

The PoC fits in five lines because the bug is one regex character.

JavaScript's . does not mean "every character"

Read the regex /(.)/g aloud. "Capture any character, globally." That is how it reads in English, and that is how it reads in code review. The ECMAScript specification disagrees.

ECMAScript defines . as "any character except line terminators" when the s (dotAll) flag is not set. The line terminators are \n (LF), \r (CR), \u2028 (LINE SEPARATOR), and \u2029 (PARAGRAPH SEPARATOR). Without the s flag, all four pass /(.)/g.exec() as non-matches. This is documented on MDN. It is in the TC39 spec. Every JavaScript engineer who has ever tried to write a regex that spans multiple lines has run into it.

The shell-quote maintainer knows this, because the patched replace reads /[\s\S]/g, which is the canonical JavaScript idiom for "literally every character, including line terminators." This is a known footgun with a known workaround idiom. The footgun was on the trust boundary for five years.

The same module shipped the same shape in 2021

CVE-2021-42740 was the first shell-quote CVE. The patch:

-    return String(s).replace(/([A-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, '$1\\$2');
+    return String(s).replace(/([A-Za-z]:)?([#!"$&'()*,:;<=>?@\[\\\]^`{|}])/g, '$1\\$2');

Read the character class [A-z] aloud. "Any letter." That is how it reads in English, and that is how it reads to a developer who has not opened an ASCII table. [A-z] is the range from ASCII 65 (A) to ASCII 122 (z), and that range includes the six characters between Z (90) and a (97): [, \, ], ^, _, and a backtick. The capture group was intended to match a Windows drive-letter prefix like C:. It also matched a literal backslash followed by a colon. Inputs containing those characters slid through quoting because the regex grouped them into the drive-letter capture, where the outer replacement template put them in $1 and never escaped them.

Both regex character classes in shell-quote's escape line have now had a CVE. CVE-2021-42740 was a character range that included characters it was not meant to include. CVE-2026-9277 is a character class that excluded characters it was meant to include. Both regexes were written to read as exhaustive ("any letter," "any character"), and both had a quiet gap, and in both cases the quiet gap was a character POSIX sh treats as syntactic.

The gate's grammar was narrower than the sink's

This is gate-narrower-than-sink. The "gate" is the escape regex, a JavaScript character class describing which characters need a backslash. The "sink" is the POSIX shell, which has its own set of characters it treats as syntactic. The library's correctness depends on those two grammars agreeing. They did not.

POSIX sh treats the newline character as a <newline> token, defined by the spec as equivalent to ; for separating commands. JavaScript's . (without s) treats the newline character as outside the alphabet of "any character." The shell will execute what follows a literal newline. The regex will not put a backslash in front of it. The difference between the two grammars is the entire vulnerability.

The 2021 CVE was the same shape with different actors. POSIX sh treats \ as the escape character. JavaScript's [A-z] includes \ in the drive-letter capture group, so the replacement template re-emits the backslash through $1 without escaping it. The shell interprets the bare backslash as escape. The regex did not flag it. The two grammars disagreed, and the bytes the regex approved were not the bytes the shell received.

Escape was the wrong category of defense

The deeper structural issue is not the regex. It is that the per-character escape existed at all on the object-token branch. The .op field is not free-form text. It is a control operator. The set of legal values is sixteen strings: ||, &&, ;;, |&, <(, <<<, >>, >&, <&, &, ;, (, ), |, <, >. The set is hardcoded in parse.js as the CONTROL regex and is the only set of op values parse ever emits. Any other value is, by the library's own grammar, not a valid token.

The pre-patch code did not assert membership in that set. It accepted any string and tried to neutralize the string by escaping each character. That is the wrong category of defense for a closed enumeration. The right defense is allowlist validation, which is what 1.8.4 adds in front of the surviving (and now correct) replace:

if (typeof s.op === 'string') {
    if (OPS.indexOf(s.op) < 0) {
        throw new TypeError('invalid `op` value: ' + JSON.stringify(s.op));
    }
    return s.op.replace(/[\s\S]/g, '\\$&');
}

Once the allowlist is in place, the replace is decoration. The allowed values are sixteen short strings, all printable ASCII, all already enumerated. The patch keeps the replace anyway, so the file now ships two locks in series: validate the shape, then escape. Either lock alone is sufficient. The pre-patch code had neither.

Two unrelated bugs were hiding behind the same line

The pre-patch object-token branch was one line. That one line was supposed to handle three distinct token shapes that parse emits: { op: <control-operator> }, { op: 'glob', pattern }, and { comment }. Two of those three never worked.

Pass { op: 'glob', pattern: '*.txt' } to the pre-patch quote and the function returns \g\l\o\b. The pattern field is discarded. The shell receives an escaped literal glob, which it accepts as the bareword glob. The output is a string, but it is not the string the caller meant, and quote(parse(cmd)) does not round-trip.

Pass { comment: 'a note' } to the pre-patch quote and the function throws on s.op.replace, because s.op is undefined. The patch's commit message says so in plain text: "Previously quote crashed on { comment } tokens that parse emits."

Both of those bugs are documented in the same commit as the CVE. Both have existed since parse started emitting those token shapes. Neither was reported in the five years between the 2021 fix and this one. The library's primary documented use case, quote(parse(cmd)), silently returned wrong output for any input containing a glob and threw on any input containing a comment, and nobody noticed.

shell-quote is the design-debt driver

shell-quote is downloaded around fifty million times a week from npm. It is the default shell-escape primitive in the Node.js ecosystem. It exists to be a trust boundary between JavaScript caller and POSIX shell. Its core implementation is a small set of String.prototype.replace calls with regex character classes.

The 2021 CVE was a gap in one character class. CVE-2026-9277 is a gap in another character class in the same module. Both patches refined the character class. Neither patch changed the strategy. Both regexes are still on the trust boundary in 1.8.4. The next CVE in this library, if there is one, will be a different regex character class in the same module with a different quiet gap, and the patch will add a fifth or sixth special case to the existing structure.

This is design-debt-driver exactly. Every regex character class in shell-quote's escape line is a claim about which characters POSIX sh treats as syntactic. Every claim has a chance of being wrong. JavaScript's character-class semantics (. excludes line terminators, [A-z] includes the punctuation between Z and a) are documented and well-known. They read as exhaustive in code review. They do not behave as exhaustive at runtime. The library has now been bitten by both directions of the same mistake.

Every downstream that imports shell-quote to escape user-supplied input before handing it to a shell is trusting a regex character class. The patch closes this CVE for that consumer. It does not close the design that puts a regex character class on the trust boundary in the first place.

PoC: ljharb/shell-quote GHSA-w7jw-789q-3m8p

The patch closes this CVE. It does not close the design that puts a regex character class on the trust boundary.