When completing a path containing `../` for `cd`, `pushd`, or `chdir`,
zsh's `_cd` runs `$(cd ${PREFIX%/*} ...)`,
which fires the `chpwd` hook in a subshell,
so `load-nvmrc` ran on each such completion, slowly in large directories.
`compstate` is set only inside completion widgets.
Checking `ZSH_SUBSHELL` instead would also skip deliberate subshells, like `( cd proj && npm test )`,
and checking it along with `WIDGET` would skip any widget's subshell, not just completion's.
Fixes#3606
Once the newest installed version is 1.0 or later, `stable` is that version, so list the installed versions once and take the newest, instead of `nvm_ls stable` listing them three times.
Only 0.x installs (where `stable` is the newest even minor), a user alias named `stable`, and `--lts` filters keep the existing path. A system node, which `nvm_ls` lists last, is skipped.
Part of #3416.
also: `nvm_get_os`: set `NVM_DIR` in the OpenHarmony chroots, and skip them without a glibc x86-64 layout
`sudo` resets the environment, and `nvm.sh` returns early when it cannot detect `NVM_DIR`,
so in the chroots `nvm_get_os` was undefined and every check got an empty result.
The chroot setup needs `ldd` and `/lib64/ld-linux-x86-64.so.2`, which macOS does not have.
Co-authored-by: hqzing <hqzing@outlook.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
The mirror now redirects to HTTPS,
and `ubuntu:22.04` has no CA certificates before its first `apt install`,
so on amd64 every source was ignored and installing packages failed:
Ign:2 https://ubuntu.cs.utah.edu/ubuntu jammy-updates InRelease
W: http://ubuntu.cs.utah.edu/ubuntu/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.
Use Ubuntu's default sources, as arm64 builds already did
(`ports.ubuntu.com`, which the `sed` did not rewrite);
Docker caches the package layers anyway.
The repo's security policy page resolves relative links from the repository root,
but viewing `.github/SECURITY.md` resolves them from `.github/`,
so no relative link works in both.
Co-authored-by: Aryan Chandavarkar <aryanmc2004@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
The duplicate-key check kept keys in a space-separated list,
so a key such as `a b` followed by a key `a` or `b` was reported as a duplicate,
unlike in the `nvmrc` package.
Keep the keys newline-separated, since a key cannot contain a newline.
The duplicate-key check used to splice each key into an extended regex,
so distinct keys whose characters are regex syntax collided
(`node.dist` matched `node-dist`, `a+b` matched `ab`),
a key with `(` or `[` printed a grep error,
and a repeated `[x` key was not caught.
e4fcf988 now compares keys literally with a `case` pattern;
cover those cases.
Signed-off-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com>
Rejecting only ASCII control characters in the LTS codename still lets through a UTF-8 C1 control
(like U+009B, a CSI) or a bidi override (like U+202E),
which some terminals act on.
A row is now kept only if its codename is `-`, empty, or alias-safe,
which is the same shape the LTS alias step already requires,
and every real codename has.
BusyBox `tr` mishandles `-c` with a character class,
so on Alpine the expected checksum printed as almost all `?`;
an octal range in the C locale works in BusyBox, GNU, and BSD `tr`,
and does not make BSD `tr` abort on invalid UTF-8.
`index.tab` and `SHASUMS256.txt` are untrusted mirror metadata.
An LTS codename (`$10`) carrying ESC/BEL bytes was printed by `nvm ls-remote`,
and a mismatched expected checksum was echoed as received.
Skip `index.tab` rows whose codename has a control character,
next to the existing version check,
and show non-printable bytes of the expected checksum as `?`.
`nvm_check_global_modules` ran `npm --version` and `npm list -g` in `$PWD`,
so the project `.npmrc` applied, eg its `logs-dir` on npm v8.11 through v10.5.
The "npm unavailable" test put its fake npm on a relative `PATH` entry, which no longer resolves from `/`.
These also ran npm in `$PWD`, applying the untrusted project `.npmrc`.
npm v7 through v8.2 apply it even with `-g`,
so its `registry` chose where `nvm install-latest-npm`, `--latest-npm`, `default-packages`, and `reinstall-packages` downloaded globally-installed packages from, and their install scripts then ran.
npm v8.11 through v10.5 honor its `logs-dir` and `cache` for `npm --version`,
so every non-silent `nvm use` created those directories and wrote a debug log there.
Use `nvm_npm`, or `nvm_cd_root` where `xargs` runs npm.
`npm link` still runs in each linked package's own directory.
`nvm debug` ran `npm config get prefix` in `$PWD`, so npm applied the untrusted project `.npmrc`.
Its `logs-dir` chose where npm wrote its debug log,
and npm 11 copies unknown keys into that log verbatim,
so `logs-dir=~/.bashrc.d` plus a `$(...)` key runs a command in the next shell on Fedora-style setups.
Its `userconfig` makes npm 11 echo the lines of any file into the log and into the `nvm debug` output.
`-g` is not enough: npm v7 through v8.2 load the project `.npmrc` even in global mode.
Add `nvm_npm`, which runs npm from `/`, and use it for both npm commands.
`$NVM_CD_FLAGS` is not used, since a zsh parent exports `-q` to bash and sh children.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ZF4UWQNS.
903e3493 moved `$NVM_AUTH_HEADER` out of the downloader's arguments,
but a mirror URL with `user:password@` in it was still one,
so any local user could read the password in `ps` or /proc/<pid>/cmdline
for every index.tab, SHASUMS, and tarball request.
curl now gets such a URL as `url = "..."` in the config it already reads with `--config -`,
with `"` and `\` escaped;
GNU Wget reads it with `--input-file=-`,
including in the same-origin redirect loop.
A URL with whitespace or a control character cannot be one config line, and stays an argument.
BusyBox wget has no way to take a URL other than as an argument; the README says so.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-MNDN98RD.
Every download went to the fixed `<archive>.unverified`,
and curl opens its `-o` file only on the first body byte,
so a curl left running by an earlier install of the same version
(past the install lock via `nvm cache clear`, a stale-lock takeover, or a removed lock)
survived the `rm -f`, then opened the same file
and could rewrite it after the checksum passed, while `tar` read it,
and leave it in the cache that `--offline` trusts.
Downloading into a `mktemp -d` directory in the same cache dir
keeps the rename atomic and the file's mode following the umask.
Leftover `.unverified*` paths from interrupted installs are still removed first.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-XUXR5LQ4.
The symlink check and the `tee` were two steps,
so anyone who can write `$PWD` could rename a symlink over `.nvmrc` in between,
and `nvm use --save`/`nvm install --save` would truncate any file the user can write.
Write the version in a private `mktemp -d` dir instead, and rename it into `$PWD/`:
a rename replaces a symlink rather than following it,
and moving into the directory (not onto `.nvmrc`) avoids landing inside a symlinked directory.
An existing `.nvmrc` must be a writable regular file, since a rename would also replace a read-only one.
`.nvmrc` is now a new file whose mode comes from the umask.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-EXZRTATX.
`nvm_process_nvmrc` tested `[ ! -L ]` and then opened the path again with `cat`,
so another local user who can write the directory
could rename a symlink over `.nvmrc` in between (timed by `cat`'s exec),
and the target's content was printed and passed to `find` and `sed` as a version,
where that user could read it from the process list (67268ebc's check, bypassed).
sh can't open without following symlinks,
so read the file once, from one open,
and when its content is not a version or an existing alias,
show it or pass it on only if one `lstat` (`find -prune -type f -links 1 -inum`)
finds a regular file at the path with the open file's inode and no other links.
Anything else is handled as a symlink.
A hard link to another user's file, where the OS allows one, is refused the same way.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-WJUJDPM2.
pdksh (OpenBSD's `/bin/sh`) and mksh have no `printf` builtin,
so every `nvm_echo` ran `/usr/bin/printf` with its text as an argument,
which every local user can read (`ps`, `/proc/<pid>/cmdline`).
That text includes a symlinked `.nvmrc`'s content while it is parsed,
so these shells still exposed it after 3a6403f9.
The zsh `load-nvmrc` and fish `load_nvm` examples passed `$(cat .nvmrc)` to `nvm version` and `nvm install`,
so a `.nvmrc` symlinked to any readable file put that file's content,
a whole one-line file with no `=` needed,
in the arguments of `find`, `sed`, and (for fish) `bass` and `bash`,
which every local user can read,
and tried to install it as a version.
Get the version from `nvm_process_nvmrc` instead, as the bash `cdnvm` example has since c314f1cb.
bass runs its arguments as bash code,
so the fish example also ran `.nvmrc` content like `v20$(touch x)`;
pass the path and version to bass in the environment instead.
Reported by Anthropic's OSS Scanner, alongside vulnerability ANT-2026-GG4I2LOU.
A symlinked `.nvmrc`'s content is never printed (67268ebc),
but it was still parsed with external commands that took part of it as arguments,
which every local user can read (`ps`, `/proc/<pid>/cmdline`):
the duplicate-key check passed each key (the text before a line's first `=`) to `grep -E`,
and `nvm_is_valid_version` passed prerelease-shaped text to `awk` before checking that its core is numeric.
So another local user who can place a `.nvmrc` symlink where the victim runs nvm
(or merely sources `nvm.sh`, with no default alias)
could read, for example, a WireGuard private key the victim's symlink target holds.
Compare keys with `case`, literally rather than as a regex,
and let the existing shell check validate a prerelease's core,
which makes `0.0.N-<prerelease>` valid.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GG4I2LOU.
add CLI option --min=<version>, fallback to env var "NVM_MIN" if set.
The latter two pick the newest match,
which is below the minimum only when every match is,
so they check the resolved version.
`ls-remote` prints its notice on stderr, so the list stays parseable.
Other minor changes:
- fix: disable color in nvm_print_versions tests
- trim leading space in mock output due to eslint errors
- ensure prefixed versions like v18 also work
- remove function ref duplication
- avoid inline initialization for ksh compatibility
- apply `--min=` before checking for an empty list; require a version
Co-authored-by: ryenus <ryenus@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Each branch now only records which system binary applies,
and the check runs in the block that lists the system version,
so the patterns that list it are named in one place.
`nvm_ls` lists the system version only for an empty pattern, `v`, or
`system`, but it checked for a system node/io.js for every pattern.
Each check runs `nvm deactivate` in a subshell, and a found system node
also runs `node -v`. So every partial-version lookup, like resolving a
`default` alias of `24` on shell startup, did that work and discarded it.
Refs #3425, #3416.
Signed-off-by: Wei-Lun Li <b84330808@gmail.com>
Check the downloader exit status before parsing index.tab, and report the failed mirror without exposing its credentials. Discard incomplete responses instead of treating them as successful version lists.
Fixes#673.
`--strip-components 1` (and OpenBSD's `-s` equivalent)
rewrites each name after the extracting tar has checked it,
so with tars that have no `openat2` jail
(upstream GNU tar, busybox tar without its traversal protection)
a member named `node-v…//home/user/.bashrc` was written to `/home/user/.bashrc`,
and a hard link to `node-v…//abs/path` linked that file into the install tree,
both silently and with a zero exit.
Extract the archive as-is into a sibling staging directory,
require exactly one top-level entry that is a real directory,
and rename it into place;
dotfiles in the archive are kept.
busybox tar does not contain hard link targets at all
(absolute, `..`, or through an earlier symlink member),
so refuse any extracted file with more than one link.
No node.js or io.js archive contains a hard link.
Previously, every download was refused only after it was fetched,
a verified cached archive was deleted as "broken",
and the source fallback then downloaded a second archive that was refused the same way,
with no message saying what to install.
The empty-computed-sum branch ended with a bare `return`,
whose status is that of the preceding `nvm_err`, which is 0.
Callers treat 0 as "verified",
so an artifact that could not be verified was installed anyway,
and was even moved into the verified cache slot,
violating nvm.sh's own invariant that only a verified archive may sit at ${TARBALL}
(a later `--offline` install would then use it without any verification).
Return 1 so the artifact is rejected, as intended by #1858.
Fixes#1858
Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
Co-authored-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
New Stuff
- select versions by category: `alpha`, `lts`, `non-lts`, `iojs`; exclude alphas by default
- `nvm alias`: store `--lts` and `--lts=<name>`
- record every node version's LTS status
- `nvm ls-remote`: annotate versions with the `node` alias and local aliases (#3920)
- add `nvm_has_italics`, to detect terminal italics support via terminfo
Bug Fixes
- `nvm`: treat a bare `--only` like an empty `--only=`
- `nvm_ls_remote`, `nvm_remote_version`: match dots between version components literally (#3982)
- `nvm_nvmrc_invalid_msg`: respect `--silent`
- `nvm_download`: pass `$NVM_AUTH_HEADER` to curl and GNU Wget in a config file, not as an argument
- `nvm_ls_remote_index_tab`, `nvm_remote_version`, `nvm_ls_cached`: pass the version pattern to grep with `-e`
- `nvm_die_on_prefix`: never let a project `.npmrc` choose which npmrc file `--delete-prefix` edits
- `nvm_download_artifact`: only put an archive in the cache once its checksum has passed
- `nvm_normalize_lts`, `nvm_ls_remote_index_tab`: keep untrusted text out of shell arithmetic and LTS aliases
- `nvm install`: keep nvm options after the version out of `./configure` (#3981)
- `nvm install`: apply `--alias`, `--default` and `--save` after every install (#3981)
- `nvm install`: don't leave `NVM_NO_PROGRESS` set in the caller's shell
- `nvm_get_default_packages`: ignore CRLF line endings (#3979)
- `install.sh`: ignore commented-out profile source lines (#3860)
- `nvm_print_implicit_alias`: keep `STABLE` bound, and `STABLE` and `UNSTABLE` independent of the caller (#3975)
- `nvm_ls`: treat a version dir with only hidden entries as empty (#3974)
- `ls`: list versions whose directory is a symlink (#3973)
- `nvm_die_on_prefix`: check a nonexistent prefix on Windows (#3972)
- `install.sh`: only write `$HOME` when `$NVM_DIR` is inside it (#3962)
- `nvm_is_version_or_alias`: reject uppercase LTS names in every locale
- `nvm_process_nvmrc`: don't show the content of a symlinked `.nvmrc`
- `nvm_write_nvmrc`: don't write through a symlinked `.nvmrc`
- `nvm_ls`: match `NVM_DIR` literally
- `nvm use`: do not pile up `PATH` entries in nested sessions (#3959)
- `nvm_filter_installed_versions`, `nvm_filter_lts_versions`, `nvm_record_lts_status`, `nvm_get_default_packages`: keep backslashes in `NVM_DIR` paths
- `nvm_strip_path`: preserve literal backslashes in `NVM_DIR` (#3958)
- `nvm_find_up`, `nvm_find_project_dir`: stop at a Windows drive root instead of looping forever (#3968)
- `nvm_ls_cached`: match dots in the version literally, and ignore a trailing dot (#3961)
- `install.sh`: `nvm_check_global_modules`: don't run a Windows npm under WSL (#3966)
- `nvm`: ignore option variables set by the caller
- `nvm reinstall-packages`: don't print `VERSION=''` in zsh
- `nvm_alias`, `nvm_ls_remote_index_tab`, `nvm use`: return the exit code of a failed check
- `nvm_print_versions`: don't mark `N/A` as installed
- `nvm_ls`: no blank line before `system` when nothing is installed
- `nvm_print_versions`: widen the version column for long versions
- `nvm_ls`: match a prerelease only up to a `.`
- `nvm_ls`: list every installed prerelease, in semver order
- `nvm uninstall`: only remove aliases that point at the uninstalled version
- `nvm_ls_cached`: only match whole version numbers
- `nvm debug`: don't let the shell read stdin when asked for its version
- `nvm_download`: with GNU Wget, follow only same-origin redirects when sending `$NVM_AUTH_HEADER`
- `nvm_download`: only send `$NVM_AUTH_HEADER` to URLs under a mirror it applies to
- `install.sh`: don't let a git repository in the current directory affect `git ls-remote`
- `nvm_remote_versions`: only consult io.js's version list for majors 1 through 3
- `nvm_remote_versions`: place io.js versions by major version, not at the literal `v4.0.0`
- `nvm.sh`: detect `NVM_DIR` without `$0`/`$_`; fall back to the default install location instead of the working directory
- `nvm_process_nvmrc_content`: reject control characters
- `nvm_download_artifact`, `nvm debug`: mask credentials in mirror URLs when printing them
- `nvm_install_binary`, `nvm_install_source`: only use a tarball that `nvm_download_artifact` put in the cache
- `nvm_download`, `nvm_get_latest`, `install.sh`: pass `-q` to curl first, so `.curlrc` is ignored again
- `nvm_is_version_installed`: fail when `nvm_version_path` fails
- `nvm use`, `nvm-exec`: stop option parsing at `--`
- `nvm install`: validate an inherited `NVM_MAKE_JOBS` like `-j`
- `nvm_is_natural_num`: reject anything but digits
- `nvm_remote_version`: match the requested version as a whole version component
- `install.sh`: a failed script-method download no longer clobbers the install or reports success
- `nvm_ls`: match the version pattern literally
- `bash_completion`: list alias and version names without expanding them
- `nvm_sanitize_auth_header`: strip newlines, so wrapped `base64` credentials work
- `nvm_cd`: bypass a user-defined `cd` function (#3836)
- `nvm use`: handle regex-special characters in `$NVM_DIR` (#3939)
- `install.sh`: start a new line before appending to a profile that does not end with one (#3952)
- Handle filesystem identity when checking path containment (#3921)
- `nvm alias`: do not drop output from background jobs on bash 3.2
- `nvm`: do not change or export the caller's `IFS`
- `nvm install`: do not remove the caller's `TMPDIR` after a failed download
- `nvm exec`/`nvm run`: do not treat filenames with digits as versions
Refactors
- `install.sh`: check profile lines through one comment-aware helper (#3976)
Robustness
- `nvm_nvmrc_invalid_msg`: only show an excerpt of the parsed content
- `install.sh`, `nvm uninstall`: pass the version to grep with `-e`
Performance
- `nvm_print_implicit_alias`: classify implicit aliases in one awk pass (#3980)
- `nvm_is_installed_exact_version`: also take the fast path for an exact prerelease
- `nvm_version_greater`, `nvm_version_greater_than_or_equal_to`: avoid `awk` where possible (#3949)
- `nvm_is_valid_version`, `nvm_validate_implicit_alias`: avoid forks (#3949)
- `nvm_echo`: use the `printf` shell builtin under zsh (#3949)
- `nvm_get_os`: read `/etc/os-release` instead of forking `uname -a` (#3949)
- `nvm_npmrc_bad_news_bears`: scan npmrc files without forking `grep` (#3949)
- `nvm_die_on_prefix`: detect the OS only when it is needed (#3949)
- `nvm_version`: resolve an exact, installed version without `nvm_ls` (#3949)
- `nvm_is_version_installed`: check the modern layout's path before the full lookup (#3949)
- `nvm_resolve_local_alias`: skip `nvm_version` for an exact, installed version (#3937)
- `nvm use`: skip re-resolving an exact, installed version (#3937)
Docs
- [readme] `cdnvm`: let nvm parse `.nvmrc`, so a symlinked `.nvmrc`'s content is not printed
- [readme] Fix a Docker warning from using Docker installation instructions (#3927)
- [readme] explain the misleading `npm install` error from `npm run test/fast` (#3944)
Misc
- [meta] `Makefile`: default `NVM_DIR` to the checkout when it is not set
- [meta] `release-notes.sh`: replace control characters in commit subjects
Tests
- make fast tests pass as root, without `sudo`, and without a terminal
- [actions] TOC: use `node/install` instead of `setup-node`
- pin `--lts` and `node` installs to end-of-life lines, so a new node release can't break them
- `bash_completion`: don't let zsh's `compinit` wait for an answer
- [actions] `tests-alpine`: time out jobs well before GitHub's 6-hour limit
- `nvm_download`: point the httpbin Authorization check at a configured mirror
- `nvm_get_arch_unofficial`: set `NVM_DIR` when sourcing `nvm.sh` in the chroots
- `nvm install v1 works`: get the version from `nvm_remote_version`, not the `ls-remote` display
- [actions] cache container images, verified against digests looked up live
- [actions] pull container images through Google's Docker Hub mirror
- [actions] never let an apt install wait on a prompt
- [actions] retry apt package installs through Ubuntu mirror outages
- add unit coverage for `nvm_version_greater_than_or_equal_to` (#3942)
- add unit tests for `nvm_version_greater_than_or_equal_to` (#3941)
- `nvm install --reinstall-packages-from`: mock the remote version instead of fetching it
- [actions] run the fast suite on macOS and WSL too
- make the fast suite pass on macOS
- [actions] rename `windows-npm` workflow to `windows-nvm`, since it tests `nvm install`
Six fast tests failed outside of CI's setup,
which runs them as a non-root user with `sudo` and a terminal.
`nvm_download_artifact error propagation` expected `mkdir -p` under `/nonexistent` to fail,
which root can create; it now uses a path under a regular file, which nobody can create.
`nvm_get_arch_unofficial` now only uses `sudo` when it is not already root,
and skips the chroot checks when it can do neither.
`nvm_write_nvmrc`'s permissions check and the `nvm uninstall` permissions test are skipped as root,
since root ignores file permissions.
`nvm_stdout_is_terminal`'s `/dev/tty` checks are skipped when there is no controlling terminal,
as in `docker run` without `-t`.
`nvm_process_nvmrc` now fails with a clear message when the `test/fixtures/nvmrc` submodule is not checked out,
instead of on an unexpanded glob.
This is not a vulnerability fix.
The bash `cdnvm` example read `.nvmrc` raw and passed its content to `nvm ls`, `nvm install`, and `nvm use`, so a `.nvmrc` symlinked to any readable file had that file's content printed in a "not found" error, bypassing the protection that `nvm_process_nvmrc` gives `nvm use`.
It now gets the version from `nvm_process_nvmrc`, which refuses a symlinked `.nvmrc` that does not contain a version or alias without showing its content, and also strips comments, which the raw read passed along.
Every command that accepts `--only=<categories>` only recognized it with an `=`, so a bare `--only` got whatever an unknown argument gets, and no command said what was wrong with it.
`nvm ls`, `nvm ls-remote`, `nvm exec`, `nvm alias`, and `nvm version-remote` rejected it as an unsupported option; `nvm uninstall` and `nvm reinstall-packages` printed their usage; `nvm use`, `nvm which`, `nvm run`, and `nvm version` took it, or the version after it, as the version to look for; and `nvm install --only 20` printed grep's usage, while `nvm install 20 --only` ignored it.
A bare `--only` is now parsed as `--only=` with an empty value, so every command gives the same error for both: `--only` needs a comma-separated list of categories.
Aliases already reject such a value when they are created, so stored alias targets need no change.
The version pattern went to grep with its dots unescaped,
so each one matched any character:
`20.1` also matched `v2041.0.0`,
and `20.1.1` matched `v20.111.1`,
so `nvm_remote_version 20.1.1` resolved to `v20.111.1`.
Escape each dot that is followed by a digit,
keeping any other regex syntax in the pattern, like `v[68]`.
The invalid `.nvmrc` message printed all of the file's parsed content, so a large file that is not really an `.nvmrc` was printed in full. It now shows at most the first 10 lines, each cut to 100 characters, and marks anything left out with `[...]`; a real `.nvmrc` is well within those limits.
This is hardening, not a vulnerability fix: since 67268ebc (the fix for ANT-2026-G9REVGKT), the content of a symlinked `.nvmrc` is never shown, so this message only ever shows the content of a regular `.nvmrc`.
Found by Anthropic's OSS Scanner while analyzing ANT-2026-G9REVGKT.
The invalid `.nvmrc` message, which includes the file's parsed content, was printed even when `NVM_SILENT` was set (eg, by `nvm use --silent`), unlike nvm's other `.nvmrc` messages. It is now suppressed there too; the exit status still reports the invalid file.
This is hardening, not a vulnerability fix: since 67268ebc (the fix for ANT-2026-G9REVGKT), the content of a symlinked `.nvmrc` is never shown, so this message only ever shows the content of a regular `.nvmrc`.
Found by Anthropic's OSS Scanner while analyzing ANT-2026-G9REVGKT.
The header was passed as a `--header` argument, so it was readable by anyone who could see the downloader's command line.
curl now reads it as `header = "…"` from a config on stdin (`--config -`); the sanitized value can contain neither `"` nor `\` nor a line break, so it cannot escape the quoted string or add another option.
GNU Wget only reads a config file that is a regular file, so a subshell writes the header to a `mktemp` file in `$TMPDIR` (mode 0600), after a copy of the user's `$WGETRC` or `~/.wgetrc`, which that file replaces, and points `WGETRC` at it;
traps on EXIT, HUP, INT, and TERM remove it, and `WGETRC` never reaches the user's shell.
BusyBox wget reads no config file and has no option for one, so it still gets the header as an argument; the README recommends curl on shared machines.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-540RL2U6.
The requested version pattern was passed to grep as a bare argument,
so a pattern starting with `-` was parsed as grep options instead.
That pattern can come from a `.nvmrc` in a repository the user cloned,
or, for implicit aliases like `node` and `stable`,
from the version column of the mirror's index.tab.
A pattern like `-Rohenpm_[A-Za-z0-9]*` made GNU grep ignore the version list on stdin and search the current directory recursively,
following symlinks, so a string from a local file
(such as an npm token in a `.npmrc`) was taken as the "version", printed,
and requested from the mirror in the download URLs;
since the version list was never read, this also worked with `--offline`.
Pass the pattern after `-e` in `nvm_ls_remote_index_tab`
(which also covers `nvm_ls_remote`, `nvm_ls_remote_iojs`, and `nvm_remote_versions`),
in the post-check in `nvm_remote_version`, and in `nvm_ls_cached`,
so a leading `-` is just part of a pattern that matches no version.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-EN9DM7WC.
`nvm use --delete-prefix`, which nvm itself recommends when it finds a `prefix` or `globalconfig` setting, ran `npm config delete` from the current directory.
For a project `.npmrc`, it ran a bare `npm config delete prefix`/`globalconfig`, so npm loaded that untrusted file first, and its `userconfig`, `globalconfig`, or `location=global` keys picked which file npm rewrote, deleted, or chmodded to 0666 - eg, `~/.bashrc` or `~/.aws/credentials`.
The builtin and user branches pinned `--userconfig`, but still loaded the project file, so a project `location=global` plus an indented ` globalconfig=` (which nvm's check does not match) redirected those writes the same way.
`npm config delete` never edits the project file anyway, so that branch could not do what it claimed.
For the project npmrc, no longer run npm at all: with `--delete-prefix`, warn that project npmrc files are not modified and must be edited by hand, and continue, as before.
For the builtin, global, and user npmrc files, pass `--prefix` set to the version directory, so npm does not walk up from the current directory to load the project npmrc, and its global config resolves to that version's `etc/npmrc`.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-WYRTKBQ5.
`nvm install --offline` installs whatever archive sits at the cache path without checking it again, which is only safe if everything nvm writes there has been verified.
When a download failed its checksum, `nvm_download_artifact` removed only the empty `files` directory and left the rejected archive in `$NVM_DIR/.cache`, so a later `nvm install --offline` would install the very tarball the online install had just refused.
An interrupted download was also left at the final cache name.
Download to a temporary `.unverified` name instead, run the 404 and checksum checks on that file, and move it to the cache path only once the checksum has passed.
Every failure path, including a checksum mismatch or a missing expected checksum, now removes the temporary file and the version's cache directory, so `--offline` no longer finds the version at all.
The README's offline section now says that only verified downloads are cached and that `--offline` trusts the cache as-is.
Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-7NCT51FE.
`nvm_normalize_lts` matched `lts/-N` with a glob that only pins the first digit after `lts/-`, then evaluated the rest inside `$((N+1))`.
bash and zsh evaluate a variable's contents as an arithmetic expression there, including command substitutions in array subscripts, so a name like `lts/-10*path[$(cmd)1]` ran `cmd`.
Such a name reaches this function from `nvm alias`, `nvm use`, `nvm install`, and `.nvmrc`, and also from LTS alias files written from a mirror's `index.tab`, which are resolved whenever `lts/*` or that codename is used.
The version column of a mirror's `index.tab` was used verbatim: printed by `nvm ls-remote` and `nvm version-remote`, matched against patterns, and stored as the target of `lts/*` codename aliases.
A hostile or compromised mirror could thus persist such a payload into `$NVM_DIR/alias/lts/`, where it is replayed later by `nvm alias` and alias resolution without the mirror being involved, and could put terminal escape sequences on the user's screen.
`nvm_normalize_lts` now takes everything after `lts/-` with parameter expansion and passes the name through unchanged unless it is all digits, before any arithmetic happens.
`lts/-1` through `lts/-N`, and the error when there are not that many LTS lines, behave as before; malformed offsets like `lts/-1x` or `lts/-10+1` are now returned unchanged in every shell, instead of erroring in dash or being evaluated in bash and zsh.
This also drops the `$?` check after the arithmetic, which could never fire.
`nvm_ls_remote_index_tab` now skips the header and keeps only rows whose version is `vX.Y.Z`, optionally followed by a `-` prerelease suffix of letters, digits, `.` and `-`, before anything is printed, stored, or matched.
The check runs on the raw column, before the `iojs-` prefix is added.
Every row of the current nodejs.org, nodejs.org nightly, and iojs.org index files passes, including `rc`, `nightly`, and `v8-canary` versions.
Discovered by Anthropic's OSS Scanner, as vulnerabilities ANT-2026-0GXXE91V and ANT-2026-31ZIEY85.
Options after the version went to `./configure` for a source install and were ignored for a binary install.
`--latest-npm`, `--default`, `--alias`, `--save` and `--no-progress` now also work after the version,
like `--reinstall-packages-from` already does.
`-s`, `-b`, `-j`, `--offline` and `--lts` are checked,
or used to find the version, before it is resolved:
after the version they now fail right away with a message to put them first,
and so do `---` typos.
Fixes#2066.
`nvm_install_binary` set the alias from its caller's variables,
so a source install or an `$NVM_INSTALL_THIRD_PARTY_HOOK` install never got it,
and no fresh install wrote `.nvmrc`.
Apply both at the end of `nvm install`, after the install is validated.
`--lts` without a version, or `lts/*`, leaves no provided version,
and `nvm alias` treats an empty target as `nvm unalias`:
`nvm install --lts --default` on an installed version removed the default alias.
In that case point the alias at `lts/<name>`, as the default alias already is.
`nvm install` passed the progress setting to `nvm_install_binary` and `nvm_install_source` as a prefix assignment,
which bash 3.2 in POSIX mode (macOS's `sh`) keeps after a function call returns,
so one install left `NVM_NO_PROGRESS=0` set,
and every later `nvm install --no-progress` was ignored.
Set it as a local instead.
To resolve `stable` and `unstable`,
`nvm_print_implicit_alias` started an awk process per installed minor version,
plus another per pre-1.0 one to check its parity.
Classify the whole list in a single awk pass instead,
and skip it when there is nothing to classify.
The results are unchanged.
Refs #3416. Refs #3811.
A `default-packages` file saved with Windows line endings left a carriage return on every package name,
and turned each blank line into a lone `\r` entry, so `npm install -g` was given `rimraf\r` and failed.
Strip a trailing `\r` from each line before parsing it,
like `.nvmrc` parsing already tolerates.
Assisted-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Wei-Lun Li <b84330808@gmail.com>
`nvm_do_install` checked for its `nvm.sh` and `bash_completion` source lines
with two separate regexes that each had to skip commented-out lines.
Move that into `nvm_profile_has_line`,
which strips whole-line comments before matching,
and test the `bash_completion` line and an already set up profile too.
`nvm_do_install` decided whether the profile already loads nvm, and its bash completion,
by grepping for `/nvm.sh` and `$NVM_DIR/bash_completion` anywhere in it,
so a commented-out line, the usual way to disable nvm, counted as present,
and reinstalling left the shell with no nvm.
Only count a line whose first non-blank character isn't `#`.
Fixes#1889.
Signed-off-by: Vaibhav Cheruvu <vaibhavsharma.c@gmail.com>
Co-authored-by: Vaibhav Cheruvu <vaibhavsharma.c@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>