[Fix] install.sh: don't let a git repository in the current directory affect git ls-remote

`install_nvm_from_git` checked whether `$NVM_INSTALL_VERSION` is a ref with a bare `git ls-remote`,
which discovers and loads the config of whatever repository contains the current directory.
That repository's `url.*.insteadOf` and `core.sshCommand` could then redirect or hijack the check,
unlike every other git command in the function,
which already passes `--git-dir="$INSTALL_DIR"/.git`.
Pass `--git-dir` here too;
`ls-remote` works even when that directory does not exist yet,
as on a fresh install

Discovered by Anthropic's OSS Scanner, as ANT-2026-JS4YHKRK; the scanner reported it as a vulnerability, but it is not one.
This commit is contained in:
Jordan Harband committed 2026-10-23 08:53:59 -07:00
1 parent 0333df56ca
commit 00217de1e1
2 files changed
+65 -1

No files matched your search

+1 -1
View File
@@ -157,7 +157,7 @@ install_nvm_from_git() {
NVM_VERSION="${NVM_INSTALL_VERSION:-$(nvm_latest_version)}"
if [ -n "${NVM_INSTALL_VERSION:-}" ]; then
# Check if version is an existing ref
if command git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q -e "$NVM_VERSION" ; then
if command git --git-dir="$INSTALL_DIR"/.git ls-remote "$(nvm_source "git")" "$NVM_VERSION" | nvm_grep -q -e "$NVM_VERSION" ; then
:
# Check if version is an existing changeset
elif ! nvm_download -o /dev/null "$(nvm_source "script-nvm-exec")"; then