mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-09-29 05:02:45 +00:00
[Fix] nvm_get_mirror
: ensure only a valid URL is allowed
This commit is contained in:
@@ -23,18 +23,25 @@ set -e
|
||||
[ "$(nvm_get_mirror node std)" = "https://nodejs.org/dist" ] || die "incorrect default node-std mirror"
|
||||
[ "$(nvm_get_mirror iojs std)" = "https://iojs.org/dist" ] || die "incorrect default iojs-std mirror"
|
||||
|
||||
NVM_NODEJS_ORG_MIRROR="test://domain"
|
||||
[ "$(nvm_get_mirror node std)" = "test://domain" ] || die "node-std mirror should respect NVM_NODEJS_ORG_MIRROR"
|
||||
NVM_NODEJS_ORG_MIRROR="https://test-domain"
|
||||
[ "$(nvm_get_mirror node std)" = "https://test-domain" ] || die "node-std mirror should respect NVM_NODEJS_ORG_MIRROR"
|
||||
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"
|
||||
NVM_IOJS_ORG_MIRROR="https://test-domain"
|
||||
[ "$(nvm_get_mirror iojs std)" = "https://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'
|
||||
testMirrors() {
|
||||
NVM_NODEJS_ORG_MIRROR="${1-}"
|
||||
! nvm_get_mirror node std || die "NVM_NODEJS_ORG_MIRROR errors with command injection attempt (${1-})"
|
||||
[ "$(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'
|
||||
NVM_IOJS_ORG_MIRROR="${1-}"
|
||||
! nvm_get_mirror iojs std || die "NVM_IOJS_ORG_MIRROR errors with command injection attempt (${1-})"
|
||||
[ "$(nvm_get_mirror iojs std)" = "" ] || die 'NVM_IOJS_ORG_MIRROR is protected against command injection'
|
||||
}
|
||||
|
||||
testMirrors '`do something bad`'
|
||||
testMirrors 'https://nodejs.org/dist; xdg-open http://www.google.com;'
|
||||
testMirrors 'https://nodejs.org/dist&&xdg-open http://www.google.com;'
|
||||
testMirrors 'https://nodejs.org/dist|xdg-open http://www.google.com;'
|
||||
|
Reference in New Issue
Block a user