Summary
A command injection vulnerability in Deno's node:child_process polyfill affects spawn and spawnSync when used with shell: true, due to incorrect quoting of shell arguments containing $VAR patterns.
If an attacker can control arguments passed into these APIs, they may execute arbitrary OS commands and bypass Deno's permission system in affected versions.
Affected context
This issue arises in Deno applications that:
- Use the
node:child_processpolyfill (spawn/spawnSync) withshell: true - Pass user-influenced or otherwise untrusted strings as command arguments
- Rely on Deno's permission system to constrain OS-level operations
The vulnerable behavior occurs during shell command construction in transformDenoShellCommand, where arguments containing $VAR patterns are quoted incorrectly for POSIX shells.
Exploit preconditions
- Attack surface: Application code that invokes
child_process.spawnorchild_process.spawnSyncwithshell: true. - Required access: Ability to control or significantly influence one or more arguments passed to these functions (e.g., HTTP request parameters, CLI flags, environment-controlled inputs).
- Trigger point: Execution of
spawn/spawnSyncin shell mode, where the constructed shell command is interpreted byshor a compatible shell. - Why exploitation is possible: The argument sanitization logic wraps
$VAR-containing arguments in double quotes instead of single quotes. In POSIXsh, double quotes still allow backtick command substitution, so malicious payloads using backticks can be executed despite the intended sanitization, enabling shell-level command injection and a path out of Deno's permission sandbox.
Why this happens
The root cause is a subtle quoting and prioritization bug in the shell command transformation logic (transformDenoShellCommand) used by the node:child_process polyfill.
A two-stage sanitization process attempts to neutralize special characters by quoting arguments, but when an argument contains a $VAR-like pattern, the code prefers double quotes over single quotes.
This behavior maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), because the sanitization does not fully neutralize shell metacharacters (notably backticks) under all conditions.
As a result, untrusted input is embedded into a shell command in a way that allows the shell to interpret portions of it as executable code.
Potential impact
- Arbitrary OS command execution under the privileges of the Deno process
- Bypassing or weakening of Deno's permission model and sandbox assumptions
- Access to local files, network resources, or system utilities that the application is expected to be restricted from
- Lateral movement within the host environment or container
- Data exfiltration, tampering, or destruction on systems where the runtime is deployed
General mitigation guidance
Effective mitigation centers on eliminating untrusted input from shell command construction and avoiding shell-based execution paths:
- Prefer non-shell execution: use APIs or libraries that invoke binaries directly without
shell: true, and pass arguments as arrays rather than concatenated command strings. - Avoid
shell: truefor user-controlled operations; treat it as an exceptional case reserved for fully trusted inputs. - Apply strict input validation and allowlists for any values that must flow into shell commands (e.g., enumerated options, filenames matching constrained patterns).
- Design code so that runtime-permission checks are complemented by application-level validation and do not assume the shell will safely interpret user data.
- Encapsulate command execution behind narrowly scoped helper functions that enforce safe patterns, instead of scattering shell invocations throughout the codebase.
How teams detect issues like this
Detection typically involves both static and review-based approaches:
- Static analysis: Flag uses of
child_process.spawn/spawnSyncwithshell: true, especially where arguments trace back to HTTP request data, environment variables, command-line arguments, or other untrusted sources. - Code review patterns: During review, look for any shell command construction that uses string concatenation, template literals, or interpolation of untrusted values, and verify the quoting and escaping rules being relied upon.
- Security linting rules: Configure linters or custom rules to warn on
shell: trueusage, and require justification or a security review for any exceptions. - Runtime monitoring: Where feasible, monitor executed command patterns (e.g., via audit logs) for anomalous or user-dependent commands that may indicate injection opportunities or exploitation.

