[Robustness] reject unsafe LTS alias names from a mirror's index.tab

A mirror-supplied LTS codename (field 10 of index.tab) was used verbatim as an alias filename,
so a hostile codename such as `../../../.bashrc` could make nvm_make_alias write outside $NVM_DIR/alias
- with the default layout, into shell startup files.
Constrain remote codenames to safe filename characters at ingestion in nvm_ls_remote_index_tab,
and reject any `..` path component in nvm_make_alias as a backstop for every caller.
This commit is contained in:
Jordan Harband
2026-07-15 13:46:52 -07:00
parent 882ed79ece
commit 9275c5badd
2 changed files with 48 additions and 0 deletions
+8
View File
@@ -1283,6 +1283,13 @@ nvm_make_alias() {
nvm_err "an alias target version is required"
return 2
fi
# slashes are legal (eg `lts/iron`), but a `..` component would escape the alias dir
case "/${ALIAS}/" in
*/../*)
nvm_err "invalid alias name: ${ALIAS}"
return 3
;;
esac
nvm_echo "${VERSION}" | tee "$(nvm_alias_path)/${ALIAS}" >/dev/null
}
@@ -1797,6 +1804,7 @@ nvm_ls_remote_index_tab() {
command mkdir -p "$(nvm_alias_path)/lts"
{ command awk '{
if ($10 ~ /^\-?$/) { next }
if (tolower($10) !~ /^[a-z0-9][a-z0-9._-]*$/) { next }
if ($10 && !a[tolower($10)]++) {
if (alias) { print alias, version }
alias_name = "lts/" tolower($10)