/

CVE-2026-118905

Severity:

HIGH RISK

(7.0)

Command Injection (CWE-78) in nvm Version Selection

CVE-2026-118905

Awaiting Analysis

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78, CWE-94

Impact:

Command Execution and File Read/Write

Severity:

HIGH RISK

(7.0)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Node Version Manager can interpret attacker-influenced version patterns as commands when constructing a sed filtering expression. If a malicious version value reaches affected nvm commands or automatic version-switching hooks while a Node.js version is installed, an attacker may achieve command execution or file access with the privileges of the invoking user.

Node Version Manager can interpret attacker-influenced version patterns as commands when constructing a sed filtering expression. If a malicious version value reaches affected nvm commands or automatic version-switching hooks while a Node.js version is installed, an attacker may achieve command execution or file access with the privileges of the invoking user.

Affected context

The vulnerability occurs in nvm versions 0.31.2 through 0.40.5 when version-selection functions pass insufficiently escaped input into a sed address. It may affect commands such as nvm use, nvm which, nvm ls, nvm version, nvm run, and nvm exec, as well as nvm-exec when its version value is attacker controlled. Automatic directory-switching hooks and scripts that pass raw .nvmrc content can increase exposure.

The vulnerability occurs in nvm versions 0.31.2 through 0.40.5 when version-selection functions pass insufficiently escaped input into a sed address. It may affect commands such as nvm use, nvm which, nvm ls, nvm version, nvm run, and nvm exec, as well as nvm-exec when its version value is attacker controlled. Automatic directory-switching hooks and scripts that pass raw .nvmrc content can increase exposure.

Exploit preconditions

  • Attack surface: Local shell execution through nvm commands, scripts, or directory-change hooks
  • Required access: Ability to provide or influence a version string, .nvmrc content, or NODE_VERSION
  • Trigger point: nvm constructs and executes the sed-based installed-version filter
  • Environmental condition: At least one Node.js version must be installed
  • Why exploitation is possible: The supplied pattern is embedded in a sed address without fully escaping syntax-significant characters, allowing input to alter the interpreted sed program
  • Attack surface: Local shell execution through nvm commands, scripts, or directory-change hooks
  • Required access: Ability to provide or influence a version string, .nvmrc content, or NODE_VERSION
  • Trigger point: nvm constructs and executes the sed-based installed-version filter
  • Environmental condition: At least one Node.js version must be installed
  • Why exploitation is possible: The supplied pattern is embedded in a sed address without fully escaping syntax-significant characters, allowing input to alter the interpreted sed program

Why this happens

The underlying bug is command injection caused by embedding insufficiently sanitized user-controlled text into a sed program. A version pattern containing sed syntax can terminate the intended address and cause the remaining text to be interpreted as sed commands rather than data. On implementations supporting command execution, this can invoke a shell command; other sed implementations may permit file reads or writes. This primarily maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, with a related CWE-94: Improper Control of Generation of Code concern because data changes the behavior of an interpreted program.

The underlying bug is command injection caused by embedding insufficiently sanitized user-controlled text into a sed program. A version pattern containing sed syntax can terminate the intended address and cause the remaining text to be interpreted as sed commands rather than data. On implementations supporting command execution, this can invoke a shell command; other sed implementations may permit file reads or writes. This primarily maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, with a related CWE-94: Improper Control of Generation of Code concern because data changes the behavior of an interpreted program.

Potential impact

  • An attacker may execute commands as the user running nvm
  • Local files may be read, modified, created, or overwritten
  • Shell credentials, source code, and environment secrets could be exposed
  • Developer workstations or build environments could be compromised
  • Malicious changes could affect downstream development or release workflows
  • An attacker may execute commands as the user running nvm
  • Local files may be read, modified, created, or overwritten
  • Shell credentials, source code, and environment secrets could be exposed
  • Developer workstations or build environments could be compromised
  • Malicious changes could affect downstream development or release workflows

General mitigation guidance

Mitigation generally focuses on keeping version values as data and preventing them from becoming executable sed syntax.

Defensive patterns include:

  • Use a parser or filtering approach that does not construct commands from untrusted version patterns
  • Apply complete, context-aware escaping or strict allowlist validation before invoking text-processing tools
  • Treat .nvmrc, NODE_VERSION, and environment-derived version values as untrusted input
  • Ensure automatic version-switching hooks validate file content before passing it to nvm
  • Prefer safe-by-default parsing that rejects unexpected characters and formats
  • Limit shell, filesystem, and build permissions available to developer automation
  • Keep sensitive credentials and writable production paths outside processes that handle untrusted project files

Mitigation generally focuses on keeping version values as data and preventing them from becoming executable sed syntax.

Defensive patterns include:

  • Use a parser or filtering approach that does not construct commands from untrusted version patterns
  • Apply complete, context-aware escaping or strict allowlist validation before invoking text-processing tools
  • Treat .nvmrc, NODE_VERSION, and environment-derived version values as untrusted input
  • Ensure automatic version-switching hooks validate file content before passing it to nvm
  • Prefer safe-by-default parsing that rejects unexpected characters and formats
  • Limit shell, filesystem, and build permissions available to developer automation
  • Keep sensitive credentials and writable production paths outside processes that handle untrusted project files

How teams detect issues like this

Detection can include static analysis for shell commands that interpolate variables into sed expressions, especially address ranges or scripts assembled through string concatenation. Code review should examine nvm wrappers, .nvmrc loaders, environment-variable handling, and directory-change hooks for raw version values reaching shell or text-processing utilities. Policy checks can require allowlisted version formats, safe argument construction, and review of shell code that invokes interpreters or file-access commands. Automated shell security scanners and repository review tools may help identify these patterns.

Detection can include static analysis for shell commands that interpolate variables into sed expressions, especially address ranges or scripts assembled through string concatenation. Code review should examine nvm wrappers, .nvmrc loaders, environment-variable handling, and directory-change hooks for raw version values reaching shell or text-processing utilities. Policy checks can require allowlisted version formats, safe argument construction, and review of shell code that invokes interpreters or file-access commands. Automated shell security scanners and repository review tools may help identify these patterns.

Sources

SourceLink
github.comgithub.com/nvm-sh/nvm/commit/82315e2b189528a006da6701eac30e8c364ffd22
github.comgithub.com/nvm-sh/nvm/pull/3854
github.comgithub.com/nvm-sh/nvm/releases/tag/v0.40.6
github.comgithub.com/nvm-sh/nvm/security/advisories/GHSA-vgqf-vc3m-4wv3

Frequently asked

questions

It is primarily a local attack-surface issue. Exploitation generally depends on an attacker placing or influencing project files, environment variables, or other inputs that a user or automation later passes to nvm.

The attacker needs a way to control a version string, .nvmrc content, or NODE_VERSION, and the affected command or hook must be executed in an environment with an installed Node.js version.

Treat version values strictly as data: validate them against an expected format and avoid constructing executable sed programs or other interpreted commands from them.

Review shell interpolation, enforce safe parsing at trust boundaries, restrict automatic project hooks, and use static analysis and policy checks for command construction involving untrusted input.

It is primarily a local attack-surface issue. Exploitation generally depends on an attacker placing or influencing project files, environment variables, or other inputs that a user or automation later passes to nvm.

The attacker needs a way to control a version string, .nvmrc content, or NODE_VERSION, and the affected command or hook must be executed in an environment with an installed Node.js version.

Treat version values strictly as data: validate them against an expected format and avoid constructing executable sed programs or other interpreted commands from them.

Review shell interpolation, enforce safe parsing at trust boundaries, restrict automatic project hooks, and use static analysis and policy checks for command construction involving untrusted input.

Find out what's already
exploitable in your codebase.