Files
nvm/test/fast/Unit tests/nvm_url_has_credentials
T
Jordan Harband 2abfc380ad [Fix] nvm_download: pass a mirror URL with credentials to curl and GNU Wget on stdin, not as an argument
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.
2026-11-16 15:15:25 -08:00

34 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
yes_creds() {
nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected success"
}
no_creds() {
! nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected failure"
}
yes_creds 'https://user:pw@mirror.example/dist'
yes_creds 'http://user:pw@127.0.0.1:8080/dist/index.tab'
yes_creds 'https://user@mirror.example'
yes_creds 'https://user:pw@[::1]:8080/dist'
yes_creds 'https://user:p@ss@mirror.example/dist'
yes_creds 'https://user:pw@mirror.example/a"b\c'
no_creds 'https://nodejs.org/dist/index.tab'
no_creds 'https://mirror.example/dist/@scope/index.tab'
no_creds 'https://mirror.example/user:pw@elsewhere.example/dist'
no_creds ''
no_creds '-o'
no_creds 'user:pw@mirror.example/dist'
no_creds 'ftp://user:pw@mirror.example/dist'
no_creds '/tmp/user:pw@mirror.example/node.tar.xz'
no_creds 'https://user:pw@mirror.example/a b'
no_creds "$(printf 'https://user:pw@mirror.example/a\nb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\rb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\033b')"