CVE-2026-118905

nvm_ls lets an untrusted version string inject sed commands, executing arbitrary commands with GNU sed

Published Oct 29, 2026 CVSS 4.0 · 7.1 High EPSS < 1% KEV · Not listed
Description
Node Version Manager (nvm) is a POSIX-compliant shell function for managing multiple node.js versions. In versions 0.31.2 through 0.40.5, `nvm_ls` filters installed versions with a sed program that embeds the requested version pattern in a `\#...#` address, escaping `.` (and, since 0.40.4, `#`) but not backslash. A version string containing `#` (or `\#`) therefore closes the address early, and the rest of it is parsed as sed commands: with GNU sed, the `e` command runs a shell command as the user; with BSD sed, the `w` and `r` commands write and read files. This is reachable whenever an attacker-influenced version string is passed to `nvm use`, `nvm which`, `nvm ls`, `nvm version`, `nvm run`, or `nvm exec`, or to `nvm-exec` via `NODE_VERSION`, and at least one version is installed. nvm's own `.nvmrc` parser strips comments, so a bare `nvm use` is not affected; however, the bash `cdnvm` and zsh `load-nvmrc` auto-switch hooks documented in the README read `.nvmrc` as-is and pass it to `nvm ls` and `nvm version`, so a user with one of those hooks installed runs the attacker's command just by changing into a directory under a malicious `.nvmrc`; scripts that run `nvm use "$(cat .nvmrc)"` are affected the same way. Version 0.40.6 passes any version pattern containing `#` or a newline through the `.nvmrc` content parser first, so no `#` reaches the sed program.

Analysis

AI-generated

Technical impact

The vulnerability arises from the way nvm_ls builds a sed expression to filter installed Node.js versions. It embeds the requested version pattern directly into a sed address, escaping only certain characters while leaving backslashes unescaped. An attacker‑controlled version string that contains a hash or escaped hash terminates the address early, allowing the remainder of the string to be interpreted as sed commands. On systems using GNU sed, the e subcommand executes the supplied string as a shell command with the current user’s privileges. On BSD sed, the w and r commands can abuse file access. Because nvm_ls is invoked by many public commands (nvm use, nvm which, nvm run, etc.) and is also called by auto‑switch hooks that read .nvmrc files, the flaw lets an attacker trigger arbitrary command execution whenever they can influence a version string.

Affected Systems

Affected supply is Node Version Manager (nvm) maintained by nvm-sh. Vulnerable releases are 0.31.2 through 0.40.5, inclusive. Functions impacted are nvm use, which, nvm ls, nvm version, nvm run, nvm exec, and the nvm-exec wrapper via the NODE_VERSION environment variable. The problem also affects users who have the bash cdnvm or zsh load‑nvmrc auto‑switch hooks, which feed directory‑level .nvmrc files directly into nvm ls and nvm version. Version 0.40.6 and later neutralise the vulnerability by stripping # characters and newlines before the string reaches the sed program.

Risk and Exploitability

The technical rating is CVSS 7.1, a high‑moderate severity indicating significant damage potential. The EPSS score is currently unavailable, so the immediate risk cannot be quantified, but the flaw is exploitable from any directory where a malicious .nvmrc file can be placed or from the command line when a user supplies a crafted version argument. Because the attack uses local privileges, the effect is confined to the current user, yet an attacker who gains the ability to create or edit .nvmrc files or supply command‑line arguments can gain shell access or modify system state. The vulnerability is not listed in the CISA KEV catalogue, but the known exploitability through sed’s e command is well understood.

Remediation

Vendor Solution

Upgrade to nvm 0.40.6 or later.


Vendor Workaround

Until upgrading, do not pass untrusted version strings to nvm, and use nvm's own `.nvmrc` handling (a bare `nvm use`) instead of reading `.nvmrc` yourself, including in shell auto-switch hooks.


OpenCVE Recommended Actions

  • Upgrade nvm to version 0.40.6 or later
  • Do not pass untrusted version strings to nvm; use bare nvm use instead of reading .nvmrc yourself, and disable or modify auto‑switch hooks that invoke nvm ls or nvm version
  • If upgrading is not immediately possible, remove or safeguard the bash cdnvm and zsh load‑nvmrc auto‑switch hooks and ensure that any .nvmrc content is filtered before calling nvm functions

Generated by OpenCVE AI on October 29, 2026 at 06:20 UTC.

Tracking

Sign in to view the affected projects.

Advisories

No advisories available
History
Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', 'Technical Impact': 'total'}, 'version': '2.0.3'}

Type Values Removed Values Added
First Time appeared Nvm-sh
Nvm-sh nvm
Vendors & Products Nvm-sh
Nvm-sh nvm
Type Values Removed Values Added
Description Node Version Manager (nvm) is a POSIX-compliant shell function for managing multiple node.js versions. In versions 0.31.2 through 0.40.5, `nvm_ls` filters installed versions with a sed program that embeds the requested version pattern in a `\#...#` address, escaping `.` (and, since 0.40.4, `#`) but not backslash. A version string containing `#` (or `\#`) therefore closes the address early, and the rest of it is parsed as sed commands: with GNU sed, the `e` command runs a shell command as the user; with BSD sed, the `w` and `r` commands write and read files. This is reachable whenever an attacker-influenced version string is passed to `nvm use`, `nvm which`, `nvm ls`, `nvm version`, `nvm run`, or `nvm exec`, or to `nvm-exec` via `NODE_VERSION`, and at least one version is installed. nvm's own `.nvmrc` parser strips comments, so a bare `nvm use` is not affected; however, the bash `cdnvm` and zsh `load-nvmrc` auto-switch hooks documented in the README read `.nvmrc` as-is and pass it to `nvm ls` and `nvm version`, so a user with one of those hooks installed runs the attacker's command just by changing into a directory under a malicious `.nvmrc`; scripts that run `nvm use "$(cat .nvmrc)"` are affected the same way. Version 0.40.6 passes any version pattern containing `#` or a newline through the `.nvmrc` content parser first, so no `#` reaches the sed program.
Title nvm_ls lets an untrusted version string inject sed commands, executing arbitrary commands with GNU sed
Weaknesses CWE-78
CWE-94
References
Metrics cvssV3_1

{'score': 7, 'vector': 'CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H'}

cvssV4_0

{'score': 7.1, 'vector': 'CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N'}

Weaknesses
  • CWE-78

    Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

  • CWE-94

    Improper Control of Generation of Code ('Code Injection')

Sources

Status
PUBLISHED
Assigner
harborist
Published
Updated
Nov 5, 2026, 8:46 PM
Reserved
Oct 29, 2026, 5:21 AM
Status
Awaiting Analysis
Published
Oct 29, 2026, 6:17 AM
Modified
Nov 5, 2026, 9:18 PM
Severity
Moderate
Public date
Oct 29, 2026, 5:22 AM