Description
shell-quote's `quote()` function did not validate object-token inputs against the operator model used by `parse()`. The `.op` field was backslash-escaped character by character using `/(.)/g`, which in JavaScript does not match line terminators (\n, \r, U+2028, U+2029). A line terminator in `.op` therefore passed through unescaped into the output; POSIX shells treat a literal newline as a command separator, so any content after it would execute as a second command. The vulnerable code path is reachable in two ways: (1) direct construction of `{ op: '...\n...' }` from external input, and (2) via `parse(cmd, envFn)` when `envFn` returns object tokens whose `.op` is attacker-influenced. Both are documented API surface. Fixed by replacing the per-character escape with strict shape validation: `.op` must match the parser's control-operator allowlist; `{ op: 'glob', pattern }` validates `pattern` and forbids line terminators; `{ comment }` validates `comment` and forbids line terminators; any other object shape throws `TypeError`.
Problem types
CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
CWE-77 Improper Neutralization of Special Elements used in a Command ('Command Injection')
Product status
1.1.0 (semver) before 1.8.4
Credits
Akshat Sinha (@akshatgit)
Jordan Harband (@ljharb)
References
github.com/...-quote/security/advisories/GHSA-w7jw-789q-3m8p
www.openwall.com/lists/oss-security/2026/05/23/2
github.com/...-quote/security/advisories/GHSA-w7jw-789q-3m8p (GHSA-w7jw-789q-3m8p)
github.com/ljharb/shell-quote/commit/1518179 (Fix commit)
github.com/ljharb/shell-quote
www.npmjs.com/package/shell-quote