Skip to content
Myr

[Fix] `nvm_get_mirror`: disallow some non-URL characters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This should be improved in the future, but is fine for now

authored by Jordan Harband · committed by Jordan Harband · parent ef7fc2f · Browse files · 2 files+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−2 removed

  • tests:+8 added−0 removed
  • other:+13 added−2 removed

2 files+21 added−2 removed

modified:test/fast/Unit tests/nvm_get_mirror+8 added
28 unmodified lines
2930NVM_IOJS_ORG_MIRROR="test://domain"31[ "$(nvm_get_mirror iojs std)" = "test://domain" ] || die "iojs-std mirror should respect NVM_IOJS_ORG_MIRROR"32unset NVM_IOJS_ORG_MIRROR3334NVM_NODEJS_ORG_MIRROR='`do something bad`'35! nvm_get_mirror node std || die 'NVM_NODEJS_ORG_MIRROR errors with command injection attempt'36[ "$(nvm_get_mirror node std)" = "" ] || die 'NVM_NODEJS_ORG_MIRROR is protected against command injection'3738NVM_IOJS_ORG_MIRROR='`do something bad`'39! nvm_get_mirror iojs std || die 'NVM_IOJS_ORG_MIRROR errors with command injection attempt'40[ "$(nvm_get_mirror iojs std)" = "" ] || die 'NVM_IOJS_ORG_MIRROR is protected against command injection'
modified:nvm.sh+13 added-2 removed
2021 unmodified lines
2022 nvm_version_greater_than_or_equal_to "$1" v4.0.02023}20242025nvm_get_mirror() {2026 local NVM_MIRROR2027 NVM_MIRROR=''2028 case "${1}-${2}" in2027 node-std) nvm_echo "${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;2028 iojs-std) nvm_echo "${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;;2029 node-std) NVM_MIRROR="${NVM_NODEJS_ORG_MIRROR:-https://nodejs.org/dist}" ;;2030 iojs-std) NVM_MIRROR="${NVM_IOJS_ORG_MIRROR:-https://iojs.org/dist}" ;;2031 *)2032 nvm_err 'unknown type of node.js or io.js release'2033 return 12034 ;;2035 esac20362037 case "${NVM_MIRROR}" in2038 *\`* | *\\* | *\'* | *\(* )2039 nvm_err '$NVM_NODEJS_ORG_MIRROR and $NVM_IOJS_ORG_MIRROR may only contain a URL'2040 return 22041 ;;2042 esac20432044 nvm_echo "${NVM_MIRROR}"2045}20462047# args: os, prefixed version, version, tarball, extract directory2048nvm_install_binary_extract() {
2394 unmodified lines