Skip to content
Myr

[Fix] `nvm_get_checksum`: pass the tarball name to awk as data, not program text

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

The awk program string-interpolated the slug (which embeds the untrusted, mirror-supplied version) into its source, so a crafted version such as `v1"==$2){system("touch${IFS}/tmp/x")}#` was executed by awk's `system()`. Pass the value via `-v tarball=...` so awk treats it as data and never as code. See GHSA-3c52-35h2-gfmm (a second injection sink fed by the same untrusted version field that `nvm_download`'s eval was; the source-install path reaches this during a normal `nvm install <version>`).

authored by Jordan Harband · committed by Jordan Harband · parent 6d870d1 · Browse files · 2 files+29 added−1 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+29 added−1 removed

  • tests:+28 added−0 removed
  • other:+1 added−1 removed

2 files+29 added−1 removed

added:test/fast/Unit tests/nvm_get_checksum awk injection+28 added
1#!/bin/sh23WORK="${TMPDIR:-/tmp}/nvm_get_checksum_awk.$$"4PROOF="${WORK}/PWNED"56cleanup () {7 unset -f die cleanup nvm_download8 rm -rf "${WORK}"9}10die () { echo "$@" ; cleanup ; exit 1; }1112\. ../../../nvm.sh1314mkdir -p "${WORK}"1516# GHSA-3c52-35h2-gfmm: nvm_get_checksum must treat the (untrusted, version-derived)17# slug as awk data, never as awk program text.18# given a crafted slug carrying an unconditional awk system() action19# and a mock that supplies one SHASUMS record (so such an action would fire)20nvm_download () { printf 'deadbeef sometarball\n'; }21# when nvm_get_checksum runs with that slug as its 4th argument22rm -f "${PROOF}"23nvm_get_checksum node std v1 'x" == $2) print $1} {system("touch${IFS}'"$PROOF"'")} #' tar.gz >/dev/null 2>&124# then the injected awk code must not execute25[ ! -e "${PROOF}" ] || die 'awk injection fires in nvm_get_checksum (slug interpolated into awk program text)'2627cleanup28echo 'nvm_get_checksum awk injection: passed'
modified:nvm.sh+1 added-1 removed
1925 unmodified lines
1926 else1927 SHASUMS_URL="${MIRROR}/${3}/SHASUMS.txt"1928 fi19291930 nvm_download -L -s "${SHASUMS_URL}" -o - | command awk "{ if (\"${4}.${5}\" == \$2) print \$1}"1930 nvm_download -L -s "${SHASUMS_URL}" -o - | command awk -v tarball="${4}.${5}" '{ if (tarball == $2) print $1 }'1931}19321933nvm_print_versions() {1934 local NVM_CURRENT
2906 unmodified lines