Skip to content

Commit

Permalink
[Fix] nvm_get_mirror: disallow some non-URL characters
Browse files Browse the repository at this point in the history
This should be improved in the future, but is fine for now
  • Loading branch information
ljharb committed Nov 2, 2023
1 parent ef7fc2f commit 905a22e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 13 additions & 2 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2023,14 +2023,25 @@ nvm_is_merged_node_version() {
}

nvm_get_mirror() {
local NVM_MIRROR
NVM_MIRROR=''
case "${1}-${2}" in
node-std) nvm_echo "${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;
iojs-std) nvm_echo "${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;;
node-std) NVM_MIRROR="${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;
iojs-std) NVM_MIRROR="${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;;
*)
nvm_err 'unknown type of node.js or io.js release'
return 1
;;
esac

case "${NVM_MIRROR}" in
*\`* | *\\* | *\'* | *\(* )
nvm_err '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL'
return 2
;;
esac

nvm_echo "${NVM_MIRROR}"
}

# args: os, prefixed version, version, tarball, extract directory
Expand Down
8 changes: 8 additions & 0 deletions test/fast/Unit tests/nvm_get_mirror
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ unset NVM_NODEJS_ORG_MIRROR
NVM_IOJS_ORG_MIRROR="test://domain"
[ "$(nvm_get_mirror iojs std)" = "test://domain" ] || die "iojs-std mirror should respect NVM_IOJS_ORG_MIRROR"
unset NVM_IOJS_ORG_MIRROR

NVM_NODEJS_ORG_MIRROR='`do something bad`'
! nvm_get_mirror node std || die 'NVM_NODEJS_ORG_MIRROR errors with command injection attempt'
[ "$(nvm_get_mirror node std)" = "" ] || die 'NVM_NODEJS_ORG_MIRROR is protected against command injection'

NVM_IOJS_ORG_MIRROR='`do something bad`'
! nvm_get_mirror iojs std || die 'NVM_IOJS_ORG_MIRROR errors with command injection attempt'
[ "$(nvm_get_mirror iojs std)" = "" ] || die 'NVM_IOJS_ORG_MIRROR is protected against command injection'

0 comments on commit 905a22e

Please sign in to comment.