Summary
nvm (Node Version Manager) through 0.40.4 is vulnerable to OS command injection when it consumes untrusted version strings from a configured Node.js/io.js mirror.
If an attacker can control or tamper with the mirror contents, they can craft version entries that cause arbitrary commands to be executed with the privileges of the user running nvm.
Affected context
This vulnerability appears in environments where nvm is configured to use a Node.js/io.js mirror whose index.tab file is not fully trusted.
It is relevant whenever commands like nvm install or related operations parse version listings from a mirror and construct shell or awk commands from those values.
Typical exposure scenarios include custom or third-party mirrors, non-TLS mirrors vulnerable to man-in-the-middle attacks, or any situation where mirror content may be influenced by an attacker.
Exploit preconditions
- Attack surface: nvm clients that fetch version listings (
index.tab) from a configured mirror. - Required access: Ability to control or modify the mirror response (e.g., operating a malicious mirror, supplying content to a CI environment using a non-default mirror, or intercepting traffic to a non-TLS mirror).
- Trigger point: Running nvm commands that read and act on version entries, such as
nvm install, which triggersnvm_download()andnvm_get_checksum(). - Why exploitation is possible: Version fields from
index.tabare treated as trusted and interpolated directly into shell commands executed viaevaland into awk programs, allowing shell/awk features like command substitution andsystem()to run attacker-controlled commands.
Why this happens
The core bug is the unsafe incorporation of untrusted data into shell and awk command strings.
nvm reads version identifiers from a mirror's index.tab and uses them directly to build command lines in two places:
nvm_download()constructs acurl/wgetshell command and executes it viaeval, causing any shell metacharacters or command substitutions in the version string to be interpreted by the shell.nvm_get_checksum()interpolates the derived download slug into an awk program, enabling crafted inputs to invoke arbitrary commands via awk'ssystem()function.
This pattern maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, where inputs that should be treated as data are instead parsed as part of executable command syntax.
Potential impact
- Execution of arbitrary OS commands with the privileges of the user running nvm.
- Compromise of developer workstations or CI agents that rely on nvm for Node.js installation.
- Unauthorized modification of source code, build artifacts, or configuration files accessible to the compromised account.
- Theft of credentials, tokens, or other sensitive information present in the environment.
- Establishment of persistent backdoors or lateral movement starting from compromised developer or CI environments.
General mitigation guidance
Effective mitigation focuses on eliminating command injection vectors and constraining the trust boundary around mirror-supplied data:
- Avoid building shell command lines via string concatenation and
eval; instead, pass parameters as literal argv elements to system utilities. - Treat mirror-provided version values as untrusted input and validate them strictly against the expected Node.js/io.js version grammar before use.
- When invoking interpreters like awk, pass untrusted values as data (e.g., via
-vor stdin) rather than interpolating them into the program source. - Prefer the default, TLS-protected official Node.js mirror and avoid non-TLS or unverified third-party mirrors whenever possible.
- Run nvm and related tooling under accounts with least-privilege access, limiting the potential damage of a successful command injection.
How teams detect issues like this
Detection typically involves a mix of code-level and operational checks:
- Static analysis and code review: Look for shell invocations that use
eval, string-interpolated commands, or unquoted variable expansion, especially where values originate from remote resources (like mirrors or index files). - Input handling review: Verify that all version strings are validated against a strict grammar before being used in command construction, and that no untrusted input is embedded directly into interpreter programs (e.g., awk, sed).
- Policy and tooling: Enforce repository policies that discourage use of
evaland demand argument-based invocation of system tools; automated linters or shell analyzers can flag dangerous patterns in shell scripts. - Runtime monitoring: On high-value developer and CI systems, monitor for anomalous process trees originating from nvm commands or awk processes executing unexpected subcommands.

