mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-08-25 00:00:22 +08:00
Compare commits
10
Commits
c7d5d7748b
...
b17550a0b9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b17550a0b9 | ||
|
|
52047edfb1 | ||
|
|
b6cf55f6ad | ||
|
|
9275c5badd | ||
|
|
882ed79ece | ||
|
|
d83da5d75b | ||
|
|
438009f54e | ||
|
|
f1e7a84cb5 | ||
|
|
86c937436d | ||
|
|
ce157c1171 |
@@ -107,3 +107,35 @@ Additionally, the maintainer of a third-party dependency might introduce a vulne
|
||||
**Recommendation**: Third-party libraries should be kept up-to-date, applying patches to address publicly known vulnerabilities in a timely fashion.
|
||||
Monitoring and logging capabilities should also be in place to detect and respond to potential attacks.
|
||||
SLSA compliance may also be considered for further supply chain security hardening.
|
||||
|
||||
## Trust boundary: mirror payloads vs. mirror metadata
|
||||
|
||||
`nvm` fetches two very different kinds of data from a Node.js/io.js mirror (`nodejs.org`/`iojs.org` by default, or whatever `$NVM_NODEJS_ORG_MIRROR` and `$NVM_IOJS_ORG_MIRROR` point at), and they sit on opposite sides of a trust boundary:
|
||||
|
||||
- **Payloads** — the Node.js/io.js binaries and source tarballs that `nvm install` downloads, unpacks, compiles (for source installs), and runs.
|
||||
- **Metadata** — everything `nvm` parses *about* those payloads rather than executing: the `index.tab` version list (including each release's LTS codename), and the `SHASUMS`/`SHASUMS256` checksum files.
|
||||
|
||||
Conflating the two leads to mis-scoped reports, so the project draws the line explicitly.
|
||||
|
||||
### Payloads are trusted, by construction
|
||||
|
||||
The entire purpose of `nvm` is to download a mirror's build of Node.js and run it.
|
||||
A mirror that serves a backdoored binary has arbitrary code execution the moment you `nvm install` and invoke `node`, and no validation inside `nvm` can prevent that - you have chosen to execute that code.
|
||||
Installing from source (`nvm install -s`) is if anything more direct: the mirror-supplied source tarball is unpacked and its `configure`/`make` build runs arbitrary code on your machine *at install time*, before `node` is ever invoked.
|
||||
Checksum verification protects **integrity** (a corrupted or truncated download, or a network intermediary that cannot also forge the same-origin `SHASUMS`), not **authenticity** against the mirror itself, since the checksums come from the same origin as the payload.
|
||||
Selecting a mirror is therefore equivalent to selecting whom you trust for arbitrary code execution in your account.
|
||||
A malicious payload from the configured mirror is consequently **out of scope**: no privilege boundary is crossed, so there is no privilege to escalate.
|
||||
|
||||
### Metadata is not trusted
|
||||
|
||||
Parsing a version list is a pure data operation.
|
||||
A user who runs `nvm ls-remote` to browse available versions - and installs nothing - has not opted into running any code from the mirror.
|
||||
Metadata can also be attacker-controlled with no mirror misconfiguration at all, via a compromised mirror/CDN or a man-in-the-middle of the channel (see *Threat ID 3*), so it is treated as hostile input.
|
||||
The invariant `nvm` maintains is:
|
||||
|
||||
> Mirror-supplied metadata must never reach a shell/command evaluator, an `awk`/`sed` program body, or an unvalidated filesystem path (see *Threat ID 2*).
|
||||
|
||||
This is why version strings from `index.tab` are passed to the downloader as literal `argv` elements rather than re-parsed by the shell ([CVE-2026-10796](https://github.com/advisories/GHSA-3c52-35h2-gfmm), [CVE-2026-1665](https://github.com/advisories/GHSA-4fc5-r4vr-8rp7)); why checksum comparisons pass the mirror's values as `awk -v` **data** and never as program text; and why LTS codenames are constrained to safe alias filenames before naming a file under `$NVM_DIR/alias/lts`, so a hostile codename such as `../../../.bashrc` cannot traverse out of the alias directory.
|
||||
|
||||
The point is not that metadata is "more dangerous" than a payload — a trusted payload can obviously do anything.
|
||||
It is that metadata carries **no** implied grant of code execution, so any code-execution or arbitrary-write primitive reachable purely by parsing it is a defect worth removing on its own merits, independent of how much the payload channel is trusted.
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
name: 'Tests: alpine'
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
fast:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# Native runners per arch (no QEMU): arm64 uses the ubuntu-24.04-arm image.
|
||||
name: 'fast ${{ matrix.arch }} (alpine ${{ matrix.alpine }}, ${{ matrix.shell }})'
|
||||
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
alpine:
|
||||
- '3.15'
|
||||
- '3.19'
|
||||
- '3'
|
||||
arch:
|
||||
- x64
|
||||
- arm64
|
||||
shell:
|
||||
- sh
|
||||
- bash
|
||||
- dash
|
||||
- zsh
|
||||
# - ksh (#574)
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v2
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
raw.githubusercontent.com:443
|
||||
nodejs.org:443
|
||||
iojs.org:443
|
||||
unofficial-builds.nodejs.org:443
|
||||
dl-cdn.alpinelinux.org:443
|
||||
dl-cdn.alpinelinux.org:80
|
||||
registry-1.docker.io:443
|
||||
auth.docker.io:443
|
||||
production.cloudflare.docker.com:443
|
||||
production.cloudfront.docker.com:443
|
||||
- uses: actions/checkout@v6
|
||||
id: checkout
|
||||
continue-on-error: true
|
||||
with:
|
||||
submodules: true
|
||||
- name: 'nvmrc submodule fallback (forks without their own nvmrc)'
|
||||
if: steps.checkout.outcome == 'failure'
|
||||
shell: bash
|
||||
run: |
|
||||
git submodule set-url test/fixtures/nvmrc https://github.com/nvm-sh/nvmrc.git
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
- uses: ljharb/actions/node/install@main
|
||||
name: 'npm install (on host; node_modules is mounted into the container)'
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
skip-ls-check: true
|
||||
- run: npm ls urchin
|
||||
- name: 'Run fast tests on Alpine ${{ matrix.alpine }} (${{ matrix.arch }})'
|
||||
run: |
|
||||
for i in 1 2 3 4 5; do
|
||||
docker pull alpine:${{ matrix.alpine }} && break
|
||||
echo "docker pull failed, attempt $i/5"; sleep $((i * 5))
|
||||
done
|
||||
docker run --rm \
|
||||
-v "${{ github.workspace }}:/workspace" \
|
||||
-w /workspace \
|
||||
-e "TEST_SHELL=${{ matrix.shell }}" \
|
||||
-e "TERM=xterm-256color" \
|
||||
-e "GITHUB_ACTIONS=true" \
|
||||
alpine:${{ matrix.alpine }} \
|
||||
sh -c '
|
||||
set -ex
|
||||
cat /etc/alpine-release; uname -m
|
||||
for i in 1 2 3 4 5; do
|
||||
apk add --no-cache \
|
||||
make bash zsh dash \
|
||||
grep sed gawk coreutils util-linux findutils ncurses \
|
||||
curl wget ca-certificates openssl tar xz gzip git \
|
||||
sudo su-exec libstdc++ libgcc && break
|
||||
echo "apk add failed, attempt $i/5"; sleep $((i * 5))
|
||||
done
|
||||
# Mirror the ubuntu runner: run the suite as a non-root user with
|
||||
# passwordless sudo and a PTY so the permission/terminal tests
|
||||
# behave the same. The user takes the mounted checkout uid so
|
||||
# files stay host-owned (no chown; post-checkout cleanup works).
|
||||
# No node is installed, so no active version skews the output.
|
||||
HOST_UID="$(stat -c %u /workspace)"
|
||||
adduser -D -u "$HOST_UID" tester 2>/dev/null || adduser -D tester
|
||||
echo "tester ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/tester
|
||||
chmod 0440 /etc/sudoers.d/tester
|
||||
export NVM_DIR=/workspace HOME=/home/tester
|
||||
unset NVM_BIN NVM_INC NVM_CD_FLAGS
|
||||
su-exec tester script -q -e -c "make TEST_SUITE=fast SHELL=$TEST_SHELL URCHIN=/workspace/node_modules/.bin/urchin test-$TEST_SHELL" /dev/null
|
||||
'
|
||||
|
||||
musl-binary:
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
# Regression lock, same-era diagonal only: modern musl node needs a newer
|
||||
# libstdc++ than old Alpine ships, and arm64-musl exists only from
|
||||
# v20.20.1/v22.21.1/v24.9.0 (built on modern Alpine), so arm64 pins modern Alpine.
|
||||
name: 'musl-binary ${{ matrix.arch }} (alpine ${{ matrix.alpine }}, node ${{ matrix.node }})'
|
||||
runs-on: ${{ matrix.arch == 'arm64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }}
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- { arch: x64, alpine: '3.10', node: v8.17.0 }
|
||||
- { arch: x64, alpine: '3.10', node: v10.24.1 }
|
||||
- { arch: x64, alpine: '3.12', node: v12.22.12 }
|
||||
- { arch: x64, alpine: '3.15', node: v14.21.3 }
|
||||
- { arch: x64, alpine: '3.16', node: v16.20.2 }
|
||||
- { arch: x64, alpine: '3.18', node: v18.20.4 }
|
||||
- { arch: x64, alpine: '3.20', node: v20.18.1 }
|
||||
- { arch: x64, alpine: '3', node: v22.12.0 }
|
||||
- { arch: arm64, alpine: '3.20', node: v20.20.1 }
|
||||
- { arch: arm64, alpine: '3', node: v22.21.1 }
|
||||
- { arch: arm64, alpine: '3', node: v24.9.0 }
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
uses: step-security/harden-runner@v2
|
||||
with:
|
||||
allowed-endpoints:
|
||||
github.com:443
|
||||
registry.npmjs.org:443
|
||||
unofficial-builds.nodejs.org:443
|
||||
dl-cdn.alpinelinux.org:443
|
||||
dl-cdn.alpinelinux.org:80
|
||||
registry-1.docker.io:443
|
||||
auth.docker.io:443
|
||||
production.cloudflare.docker.com:443
|
||||
production.cloudfront.docker.com:443
|
||||
- uses: actions/checkout@v6
|
||||
with:
|
||||
submodules: false
|
||||
- name: 'Install node ${{ matrix.node }} from a musl binary on Alpine ${{ matrix.alpine }}'
|
||||
run: |
|
||||
for i in 1 2 3 4 5; do
|
||||
docker pull alpine:${{ matrix.alpine }} && break
|
||||
echo "docker pull failed, attempt $i/5"; sleep $((i * 5))
|
||||
done
|
||||
docker run --rm \
|
||||
-v "${{ github.workspace }}:/workspace" \
|
||||
-w /workspace \
|
||||
-e "NODE_VERSION=${{ matrix.node }}" \
|
||||
-e "TERM=xterm-256color" \
|
||||
alpine:${{ matrix.alpine }} \
|
||||
sh -c '
|
||||
set -ex
|
||||
cat /etc/alpine-release; uname -m
|
||||
# libstdc++/libgcc are load-bearing: the unofficial musl node
|
||||
# binary dynamically links them. No build toolchain: -b forbids
|
||||
# the source fallback, so a missing binary is a hard failure.
|
||||
for i in 1 2 3 4 5; do
|
||||
apk add --no-cache \
|
||||
bash ca-certificates curl wget tar xz gzip \
|
||||
grep sed coreutils libstdc++ libgcc && break
|
||||
echo "apk add failed, attempt $i/5"; sleep $((i * 5))
|
||||
done
|
||||
export NVM_DIR=/workspace
|
||||
unset NVM_BIN NVM_INC NVM_CD_FLAGS
|
||||
# The default nodejs.org mirror serves no -musl artifacts; this one does.
|
||||
export NVM_NODEJS_ORG_MIRROR=https://unofficial-builds.nodejs.org/download/release
|
||||
. /workspace/nvm.sh --no-use
|
||||
nvm install -b --skip-default-packages "$NODE_VERSION"
|
||||
nvm use "$NODE_VERSION"
|
||||
[ "$(node -v)" = "$NODE_VERSION" ] || { echo "version mismatch: $(node -v)"; exit 1; }
|
||||
node -e "process.exit(0)"
|
||||
ldd "$(command -v node)" | grep -qi musl
|
||||
'
|
||||
|
||||
all:
|
||||
permissions:
|
||||
contents: none
|
||||
name: 'all alpine tests'
|
||||
needs: [fast, musl-binary]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: true
|
||||
@@ -6,7 +6,7 @@
|
||||
</a>
|
||||
|
||||
|
||||
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
|
||||
# Node Version Manager [][3] [][4] [](https://bestpractices.dev/projects/684)
|
||||
|
||||
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
@@ -106,10 +106,10 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
|
||||
|
||||
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
```
|
||||
```sh
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
```
|
||||
|
||||
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bashrc`, `~/.bash_profile`, `~/.zshrc`, or `~/.profile`). If you find the install script is updating the wrong profile file, set the `$PROFILE` env var to the profile file’s path, and then rerun the installation script.
|
||||
@@ -136,7 +136,7 @@ Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not conta
|
||||
|
||||
- The installer can use `git`, `curl`, or `wget` to download `nvm`, whichever is available.
|
||||
|
||||
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash'`
|
||||
- You can instruct the installer to not edit your shell config (for example if you already get completions via a [zsh nvm plugin](https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/nvm)) by setting `PROFILE=/dev/null` before running the `install.sh` script. Here's an example one-line command to do that: `PROFILE=/dev/null bash -c 'curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash'`
|
||||
|
||||
#### Installing in Docker
|
||||
|
||||
@@ -152,7 +152,7 @@ RUN touch "${BASH_ENV}"
|
||||
RUN echo '. "${BASH_ENV}"' >> ~/.bashrc
|
||||
|
||||
# Download and install nvm
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | PROFILE="${BASH_ENV}" bash
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | PROFILE="${BASH_ENV}" bash
|
||||
RUN echo node > .nvmrc
|
||||
RUN nvm install
|
||||
```
|
||||
@@ -170,7 +170,7 @@ ARG NODE_VERSION=20
|
||||
RUN apt update && apt install curl -y
|
||||
|
||||
# install nvm
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
|
||||
# set env
|
||||
ENV NVM_DIR=/root/.nvm
|
||||
@@ -196,7 +196,7 @@ After creation of the image you can start container interactively and run comman
|
||||
docker run --rm -it nvmimage
|
||||
|
||||
root@0a6b5a237c14:/# nvm -v
|
||||
0.40.5
|
||||
0.40.6
|
||||
|
||||
root@0a6b5a237c14:/# node -v
|
||||
v19.9.0
|
||||
@@ -259,7 +259,7 @@ You can use a task:
|
||||
```yaml
|
||||
- name: Install nvm
|
||||
ansible.builtin.shell: >
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
args:
|
||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||
```
|
||||
@@ -321,7 +321,7 @@ If you have `git` installed (requires git v1.7.10+):
|
||||
|
||||
1. clone this repo in the root of your user profile
|
||||
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
|
||||
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.5`
|
||||
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.40.6`
|
||||
1. activate `nvm` by sourcing it from your shell: `. ./nvm.sh`
|
||||
|
||||
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
|
||||
@@ -958,13 +958,13 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
|
||||
### Alpine Linux 3.13+
|
||||
```sh
|
||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python3 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
```
|
||||
|
||||
### Alpine Linux 3.5 - 3.12
|
||||
```sh
|
||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
```
|
||||
|
||||
_Note: Alpine 3.5 can only install NodeJS versions up to v6.9.5, Alpine 3.6 can only install versions up to v6.10.3, Alpine 3.7 installs versions up to v8.9.3, Alpine 3.8 installs versions up to v8.14.0, Alpine 3.9 installs versions up to v10.19.0, Alpine 3.10 installs versions up to v10.24.1, Alpine 3.11 installs versions up to v12.22.6, Alpine 3.12 installs versions up to v12.22.12, Alpine 3.13 & 3.14 install versions up to v14.20.0, Alpine 3.15 & 3.16 install versions up to v16.16.0 (**These are all versions on the main branch**). Alpine 3.5 - 3.12 required the package `python2` to build NodeJS, as they are older versions to build. Alpine 3.13+ requires `python3` to successfully build newer NodeJS versions, but you can use `python2` with Alpine 3.13+ if you need to build versions of node supported in Alpine 3.5 - 3.15, you just need to specify what version of NodeJS you need to install in the package install script._
|
||||
@@ -1064,9 +1064,9 @@ You have to make sure that the user directory name in `$HOME` and the user direc
|
||||
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
|
||||
|
||||
[1]: https://github.com/nvm-sh/nvm.git
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.5/install.sh
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.40.6/install.sh
|
||||
[3]: https://github.com/nvm-sh/nvm/actions/workflows/tests-fast.yml
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.5
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.40.6
|
||||
[Urchin]: https://git.sdf.org/tlevine/urchin
|
||||
[Fish]: https://fishshell.com
|
||||
|
||||
@@ -1124,7 +1124,7 @@ Here's what you will need to do:
|
||||
If one of these broken versions is installed on your system, the above step will likely still succeed even if you didn't include the `--shared-zlib` flag.
|
||||
However, later, when you attempt to `npm install` something using your old version of node.js, you will see `incorrect data check` errors.
|
||||
If you want to avoid the possible hassle of dealing with this, include that flag.
|
||||
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.576)
|
||||
For more details, see [this issue](https://github.com/nodejs/node/issues/39313) and [this comment](https://github.com/nodejs/node/issues/39313#issuecomment-90.40.676)
|
||||
|
||||
- Exit back to your native shell.
|
||||
|
||||
@@ -1151,7 +1151,7 @@ Now you should be able to use node as usual.
|
||||
If you've encountered this error on WSL-2:
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.5/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.6/install.sh | bash
|
||||
% Total % Received % Xferd Average Speed Time Time Time Current
|
||||
Dload Upload Total Spent Left Speed
|
||||
0 0 0 0 0 0 0 0 --:--:-- 0:00:09 --:--:-- 0curl: (6) Could not resolve host: raw.githubusercontent.com
|
||||
@@ -1186,7 +1186,7 @@ Currently, the sole maintainer is [@ljharb](https://github.com/ljharb) - more ma
|
||||
|
||||
## Project Support
|
||||
|
||||
Only the latest version (v0.40.5 at this time) is supported.
|
||||
Only the latest version (v0.40.6 at this time) is supported.
|
||||
|
||||
## Enterprise Support
|
||||
|
||||
|
||||
+26
-12
@@ -45,7 +45,7 @@ nvm_install_dir() {
|
||||
}
|
||||
|
||||
nvm_latest_version() {
|
||||
nvm_echo "v0.40.5"
|
||||
nvm_echo "v0.40.6"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
@@ -121,17 +121,31 @@ nvm_download() {
|
||||
command curl --fail --compressed -q "$@"
|
||||
elif nvm_has_executable "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
-e 's/--compressed //' \
|
||||
-e 's/--fail //' \
|
||||
-e 's/-L //' \
|
||||
-e 's/-I /--server-response /' \
|
||||
-e 's/-s /-q /' \
|
||||
-e 's/-sS /-nv /' \
|
||||
-e 's/-o /-O /' \
|
||||
-e 's/-C - /-c /')
|
||||
# shellcheck disable=SC2086
|
||||
eval command wget $ARGS
|
||||
local NVM_DOWNLOAD_WGET_COUNT
|
||||
NVM_DOWNLOAD_WGET_COUNT=$#
|
||||
local NVM_DOWNLOAD_WGET_SKIP
|
||||
NVM_DOWNLOAD_WGET_SKIP=0
|
||||
local NVM_DOWNLOAD_WGET_ARG
|
||||
for NVM_DOWNLOAD_WGET_ARG in "$@"; do
|
||||
if [ "${NVM_DOWNLOAD_WGET_SKIP}" = '1' ]; then
|
||||
NVM_DOWNLOAD_WGET_SKIP=0
|
||||
continue
|
||||
fi
|
||||
case "${NVM_DOWNLOAD_WGET_ARG}" in
|
||||
'--progress-bar') set -- "$@" '--progress=bar' ;;
|
||||
'--compressed') : ;;
|
||||
'--fail') : ;;
|
||||
'-L') : ;;
|
||||
'-I') set -- "$@" '--server-response' ;;
|
||||
'-s') set -- "$@" '-q' ;;
|
||||
'-sS') set -- "$@" '-nv' ;;
|
||||
'-o') set -- "$@" '-O' ;;
|
||||
'-C') NVM_DOWNLOAD_WGET_SKIP=1; set -- "$@" '-c' ;;
|
||||
*) set -- "$@" "${NVM_DOWNLOAD_WGET_ARG}" ;;
|
||||
esac
|
||||
done
|
||||
shift "${NVM_DOWNLOAD_WGET_COUNT}"
|
||||
command wget "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
{ # this ensures the entire script is downloaded #
|
||||
|
||||
# shellcheck disable=SC3028
|
||||
NVM_SCRIPT_SOURCE="$_"
|
||||
NVM_SCRIPT_SOURCE="${_:-}"
|
||||
|
||||
nvm_is_zsh() {
|
||||
[ -n "${ZSH_VERSION-}" ]
|
||||
@@ -1283,6 +1283,13 @@ nvm_make_alias() {
|
||||
nvm_err "an alias target version is required"
|
||||
return 2
|
||||
fi
|
||||
# slashes are legal (eg `lts/iron`), but a `..` component would escape the alias dir
|
||||
case "/${ALIAS}/" in
|
||||
*/../*)
|
||||
nvm_err "invalid alias name: ${ALIAS}"
|
||||
return 3
|
||||
;;
|
||||
esac
|
||||
nvm_echo "${VERSION}" | tee "$(nvm_alias_path)/${ALIAS}" >/dev/null
|
||||
}
|
||||
|
||||
@@ -1797,6 +1804,7 @@ nvm_ls_remote_index_tab() {
|
||||
command mkdir -p "$(nvm_alias_path)/lts"
|
||||
{ command awk '{
|
||||
if ($10 ~ /^\-?$/) { next }
|
||||
if (tolower($10) !~ /^[a-z0-9][a-z0-9._-]*$/) { next }
|
||||
if ($10 && !a[tolower($10)]++) {
|
||||
if (alias) { print alias, version }
|
||||
alias_name = "lts/" tolower($10)
|
||||
@@ -2251,10 +2259,12 @@ nvm_get_arch() {
|
||||
HOST_ARCH=armv7l
|
||||
fi
|
||||
|
||||
if [ -f "/etc/alpine-release" ]; then
|
||||
# Alpine Linux uses musl libc; only x64-musl binaries are available
|
||||
if [ -f "/etc/alpine-release" ] && [ "_${NVM_OS}" = "_linux" ]; then
|
||||
# Alpine Linux uses musl libc; map to musl variants where available
|
||||
# See https://unofficial-builds.nodejs.org/download/release/
|
||||
case "${NVM_ARCH}" in
|
||||
x64) NVM_ARCH=x64-musl ;;
|
||||
arm64) NVM_ARCH=arm64-musl ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
@@ -4727,7 +4737,7 @@ nvm() {
|
||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||
;;
|
||||
"--version" | "-v")
|
||||
nvm_echo '0.40.5'
|
||||
nvm_echo '0.40.6'
|
||||
;;
|
||||
"unload")
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.40.5",
|
||||
"version": "0.40.6",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
||||
@@ -90,8 +90,13 @@ run_test amd64 smartos x64 no_pkg_info
|
||||
run_test x86 osx x86
|
||||
run_test amd64 osx x64
|
||||
|
||||
# These smartos cases have no arch-specific uname mock, so nvm_get_os falls
|
||||
# through to the real host; on Alpine that host is linux and picks up the musl
|
||||
# suffix, which these non-musl assertions do not expect. Skip them there.
|
||||
if [ ! -f "/etc/alpine-release" ]; then
|
||||
run_test arm64 smartos x64
|
||||
run_test armv8l smartos x64
|
||||
fi
|
||||
|
||||
run_test loongarch64 linux loong64
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ die () { cleanup; echo "$@" ; exit 1; }
|
||||
MOCKS_DIR="$(pwd)/../../mocks"
|
||||
export PATH=".:${PATH}"
|
||||
|
||||
# On Alpine (where /etc/alpine-release exists), x64 should get -musl suffix
|
||||
# and arm64 should NOT get -musl suffix.
|
||||
# On Alpine (where /etc/alpine-release exists), both x64 and arm64 should get
|
||||
# the -musl suffix, since unofficial-builds publishes musl binaries for both.
|
||||
# On non-Alpine, neither should get -musl.
|
||||
|
||||
if [ -f "/etc/alpine-release" ]; then
|
||||
@@ -26,11 +26,11 @@ if [ -f "/etc/alpine-release" ]; then
|
||||
rm -f ./uname
|
||||
[ "_${OUTPUT}" = "_x64-musl" ] || die "x64 on Alpine should be x64-musl, got ${OUTPUT}"
|
||||
|
||||
# aarch64 on Alpine should produce arm64, NOT arm64-musl
|
||||
# aarch64 on Alpine should produce arm64-musl
|
||||
ln -sf "${MOCKS_DIR}/uname_linux_aarch64" ./uname
|
||||
OUTPUT="$(nvm_get_arch)"
|
||||
rm -f ./uname
|
||||
[ "_${OUTPUT}" = "_arm64" ] || die "aarch64 on Alpine should be arm64 (no musl suffix), got ${OUTPUT}"
|
||||
[ "_${OUTPUT}" = "_arm64-musl" ] || die "aarch64 on Alpine should be arm64-musl, got ${OUTPUT}"
|
||||
else
|
||||
# x64 on non-Alpine should produce x64 (no musl suffix)
|
||||
ln -sf "${MOCKS_DIR}/uname_linux_x86_64" ./uname
|
||||
|
||||
@@ -57,6 +57,13 @@ setup_chroot() {
|
||||
sudo mknod "${chroot_dir}/dev/null" c 1 3
|
||||
}
|
||||
|
||||
# The chroot fixtures assume a glibc layout (fixed dynamic-linker path under
|
||||
# /lib64, coreutils binaries). On musl Alpine that setup does not apply, and
|
||||
# nvm_get_arch's musl mapping is already covered by the "nvm_get_arch alpine"
|
||||
# test, so skip the chroot checks there and still run the ls-remote checks.
|
||||
if [ -f "/etc/alpine-release" ]; then
|
||||
echo "on Alpine; skipping chroot arch checks (covered by 'nvm_get_arch alpine')"
|
||||
else
|
||||
setup_chroot "${CHROOT_WITH_ALPINE}"
|
||||
setup_chroot "${CHROOT_WITHOUT_ALPINE}"
|
||||
|
||||
@@ -66,6 +73,7 @@ ARCH_WITH_ALPINE=$(sudo chroot "${CHROOT_WITH_ALPINE}" /bin/sh -c ". ./nvm.sh &&
|
||||
|
||||
ARCH_WITHOUT_ALPINE=$(sudo chroot "${CHROOT_WITHOUT_ALPINE}" /bin/sh -c ". ./nvm.sh && nvm_get_arch")
|
||||
[ "${ARCH_WITHOUT_ALPINE}" != "x64-musl" ] || die "Did not expect x64-musl for non-alpine environment"
|
||||
fi
|
||||
|
||||
# Run tests for nvm ls-remote
|
||||
test_default_ls_remote() {
|
||||
|
||||
@@ -14,6 +14,14 @@ die () { >&2 echo "$@" ; cleanup ; exit 1; }
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
# v0.12.18 predates musl binaries and the expected output hardcodes the glibc
|
||||
# x64 tarball URL, so on Alpine nvm would request a nonexistent -musl build.
|
||||
# The progress-bar behavior is not OS-specific, so skip below the musl floor.
|
||||
if [ -f "/etc/alpine-release" ]; then
|
||||
echo 'on Alpine; skipping (v0.12.18 has no musl binary)'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
cleanup
|
||||
|
||||
OUTPUT="$(TERM=dumb 2>&1 nvm install --no-progress v0.12.18)"
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
WORK="$PWD/ls_remote-traversal-work.$$"
|
||||
export HOME="$WORK/home"
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
BASHRC="$HOME/.bashrc"
|
||||
|
||||
cleanup() {
|
||||
unset -f die cleanup nvm_download
|
||||
rm -rf "$WORK"
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
mkdir -p "$NVM_DIR/alias"
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
# a malicious/compromised mirror: the LTS codename field ($10) carries path
|
||||
# traversal, and the version field ($1) carries a command-substitution payload;
|
||||
# a valid codename (Iron) is included to prove real aliases still get written
|
||||
nvm_download() {
|
||||
printf 'version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\tlts\tsecurity\n'
|
||||
printf '$(>%s/pwned)\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\t../../../.bashrc\t-\n' "$WORK"
|
||||
printf 'v20.0.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\tIron\t-\n'
|
||||
}
|
||||
|
||||
nvm_ls_remote >/dev/null 2>&1 || true
|
||||
|
||||
[ ! -e "$BASHRC" ] || die "path traversal wrote outside the alias dir: $BASHRC was created"
|
||||
[ ! -e "$WORK/pwned" ] || die "mirror-supplied payload landed: $WORK/pwned was created"
|
||||
[ -f "$NVM_DIR/alias/lts/iron" ] || die "valid LTS alias lts/iron was not created"
|
||||
|
||||
nvm_make_alias 'lts/../../../escape' 'v1.0.0' 2>/dev/null && die 'nvm_make_alias accepted a traversing alias name'
|
||||
[ ! -e "$NVM_DIR/../escape" ] || die 'nvm_make_alias wrote outside the alias dir'
|
||||
nvm_make_alias 'lts/carbon' 'v8.0.0' >/dev/null 2>&1 || die 'nvm_make_alias rejected a valid alias name'
|
||||
[ -f "$NVM_DIR/alias/lts/carbon" ] || die 'nvm_make_alias did not create a valid alias'
|
||||
|
||||
cleanup
|
||||
echo "nvm_ls_remote LTS codename traversal: passed"
|
||||
@@ -63,9 +63,15 @@ test_install_data() {
|
||||
echo "$current_ref" | grep -q "$ref" || die "install_nvm_from_git ${message} did not clone with ref ${ref}"
|
||||
fi
|
||||
|
||||
local head_ref="$(git for-each-ref --points-at HEAD --format='%(refname:short)' 'refs/tags/')"
|
||||
if [ -n "${avoid_ref}" ] && [ "${head_ref}" != "${avoid_ref}" ]; then
|
||||
echo "${current_ref}" | grep -q "$avoid_ref" && die "install_nvm_from_git ${message} did clone with unwanted ref ${avoid_ref}"
|
||||
if [ -n "${avoid_ref}" ] && echo "${current_ref}" | grep -q "${avoid_ref}"; then
|
||||
# the avoided tag decorating HEAD is only legitimate if HEAD really is that
|
||||
# tag's commit in the installed clone (eg master released at that tag); query
|
||||
# the clone itself, not the caller's checkout, so the trigger ref cannot skew it
|
||||
local avoid_changeset
|
||||
avoid_changeset="$(git --git-dir "$NVM_DIR"/.git rev-parse --verify --quiet "refs/tags/${avoid_ref}^{commit}" 2>/dev/null)"
|
||||
if [ "${avoid_changeset}" != "${current_changeset}" ]; then
|
||||
die "install_nvm_from_git ${message} did clone with unwanted ref ${avoid_ref}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$changeset" ]; then
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
#!/bin/sh
|
||||
|
||||
OLDPATH="$PATH"
|
||||
WORK="$PWD/nvm_download-noeval-work.$$"
|
||||
TEST_BIN="$WORK/bin"
|
||||
ARGV_LOG="$WORK/argv.log"
|
||||
PROOF="$WORK/nvm_injection_proof"
|
||||
|
||||
cleanup() {
|
||||
unset -f die cleanup
|
||||
rm -rf "$WORK"
|
||||
export PATH="$OLDPATH"
|
||||
}
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
NVM_ENV=testing \. ../../install.sh
|
||||
|
||||
mkdir -p "$TEST_BIN"
|
||||
|
||||
# fake curl/wget: record each received argument verbatim, then succeed
|
||||
{
|
||||
echo '#!/bin/sh'
|
||||
echo ': > "$ARGV_LOG"'
|
||||
echo 'for a in "$@"; do printf "%s\n" "$a" >> "$ARGV_LOG"; done'
|
||||
echo 'exit 0'
|
||||
} > "$TEST_BIN/curl"
|
||||
chmod +x "$TEST_BIN/curl"
|
||||
cp "$TEST_BIN/curl" "$TEST_BIN/wget"
|
||||
|
||||
# the wget-path calls below restrict PATH to $TEST_BIN so that no real curl is
|
||||
# found; link sed and touch in so that a regression to the old sed|eval
|
||||
# implementation fails this test by actually injecting, rather than by failing
|
||||
# to find the binaries the injection needs
|
||||
ln -s "$(command -v sed)" "$TEST_BIN/sed"
|
||||
ln -s "$(command -v touch)" "$TEST_BIN/touch"
|
||||
|
||||
export ARGV_LOG
|
||||
export PATH="$TEST_BIN:$OLDPATH"
|
||||
|
||||
URL="https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/nvm.sh"
|
||||
|
||||
# given a url containing command-substitution syntax
|
||||
INJECT_URL="http://example.test/v1\$(touch ${PROOF})/x"
|
||||
|
||||
# when nvm_download is invoked (curl path)
|
||||
rm -f "$PROOF"
|
||||
nvm_download "$INJECT_URL" -o - || die 'nvm_download (curl) returned nonzero on injection url'
|
||||
# then the substitution must not have executed
|
||||
[ ! -e "$PROOF" ] || die "command injection fired via curl path: proof file was created"
|
||||
# and curl must have received the url as one literal argument
|
||||
grep -Fxq "$INJECT_URL" "$ARGV_LOG" || die "curl did not receive the url as a single literal argument; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# given curl is unavailable (the wget-path calls run with PATH limited to our
|
||||
# fake wget, so neither the fake nor the system curl is found)
|
||||
rm -f "$TEST_BIN/curl"
|
||||
|
||||
# when nvm_download is invoked with the injection url (wget path)
|
||||
rm -f "$PROOF"
|
||||
( PATH="$TEST_BIN"; export PATH; nvm_download "$INJECT_URL" -o - ) || die 'nvm_download (wget) returned nonzero on injection url'
|
||||
# then the substitution must not have executed
|
||||
[ ! -e "$PROOF" ] || die "command injection fired via wget path: proof file was created"
|
||||
grep -Fxq "$INJECT_URL" "$ARGV_LOG" || die "wget did not receive the url as a single literal argument; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# given an output path containing a space, as a real $NVM_DIR may
|
||||
SPACED_DIR="$WORK/dir with space"
|
||||
SPACED="$SPACED_DIR/nvm.sh"
|
||||
mkdir -p "$SPACED_DIR"
|
||||
|
||||
# when nvm_download is invoked with it (wget path)
|
||||
( PATH="$TEST_BIN"; export PATH; nvm_download -s "$URL" -o "$SPACED" ) || die 'nvm_download (wget) returned nonzero on spaced output path'
|
||||
# then wget receives it as one argument rather than word-split
|
||||
grep -Fxq "$SPACED" "$ARGV_LOG" || die "wget did not receive the spaced output path as a single argument; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# given a url with an ampersand in its query string, as a real mirror may
|
||||
AMP_URL="http://example.test/nvm.sh?a=1&b=2"
|
||||
|
||||
# when nvm_download is invoked with it (wget path)
|
||||
( PATH="$TEST_BIN"; export PATH; nvm_download -s "$AMP_URL" -o - ) || die 'nvm_download (wget) returned nonzero on ampersand url'
|
||||
# then the url is passed intact rather than backgrounding the command
|
||||
grep -Fxq "$AMP_URL" "$ARGV_LOG" || die "wget did not receive the ampersand url intact; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# when invoked with -L -C - --progress-bar URL -o FILE (wget path)
|
||||
FILE="$WORK/target"
|
||||
( PATH="$TEST_BIN"; export PATH; nvm_download -L -C - --progress-bar "$URL" -o "$FILE" ) || die 'nvm_download (wget) returned nonzero on normal url'
|
||||
# then flags are translated to wget equivalents
|
||||
grep -Fxqe "-c" "$ARGV_LOG" || die "wget did not translate -C - to -c; got: $(cat "$ARGV_LOG")"
|
||||
grep -Fxqe "--progress=bar" "$ARGV_LOG" || die "wget did not translate --progress-bar; got: $(cat "$ARGV_LOG")"
|
||||
grep -Fxqe "-O" "$ARGV_LOG" || die "wget did not translate -o to -O; got: $(cat "$ARGV_LOG")"
|
||||
grep -Fxqe "-L" "$ARGV_LOG" && die "wget should drop -L; got: $(cat "$ARGV_LOG")"
|
||||
grep -Fxqe "-C" "$ARGV_LOG" && die "wget should not pass -C through; got: $(cat "$ARGV_LOG")"
|
||||
grep -Fxqe "-" "$ARGV_LOG" && die "wget should drop the lone - after -C; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
# when invoked with -s (wget path)
|
||||
( PATH="$TEST_BIN"; export PATH; nvm_download -s "$URL" -o "$FILE" ) || die 'nvm_download (wget) returned nonzero on -s url'
|
||||
# then -s becomes -q
|
||||
grep -Fxqe "-q" "$ARGV_LOG" || die "wget did not translate -s to -q; got: $(cat "$ARGV_LOG")"
|
||||
|
||||
cleanup
|
||||
echo "nvm_download no eval injection: passed"
|
||||
Reference in New Issue
Block a user