[Fix] nvm_download_artifact: reject version strings with disallowed characters

The mirror-supplied (untrusted) version flows into download URLs,
filesystem paths, and the checksum awk match.
Reject any version outside the node/io.js grammar
(`[0-9A-Za-z._+-]`) before it is used.
A blocklist of metacharacters is used rather than a strict semver allowlist so RCs, nightlies, v8-canary, and io.js versions still install.

Completes the remediation of GHSA-3c52-35h2-gfmm.
This commit is contained in:
Jordan Harband
2026-06-03 13:09:07 -07:00
parent 90bb88748b
commit 70fb4ede6b
2 changed files with 56 additions and 4 deletions

14
nvm.sh
View File

@@ -2506,10 +2506,16 @@ nvm_download_artifact() {
local VERSION
VERSION="${4}"
if [ -z "${VERSION}" ]; then
nvm_err 'A version number is required.'
return 3
fi
case "${VERSION}" in
'')
nvm_err 'A version number is required.'
return 3
;;
*[!0-9A-Za-z._+-]*)
nvm_err 'Invalid version: contains disallowed characters'
return 3
;;
esac
if [ "${KIND}" = 'binary' ] && ! nvm_binary_available "${VERSION}"; then
nvm_err "No precompiled binary available for ${VERSION}."