From 5671e688d2d4b32b1c1a178c7fbf0cd5c0f5d30c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 16 Nov 2026 11:35:44 -0800 Subject: [PATCH] [readme] zsh and fish auto-switch hooks: let nvm parse `.nvmrc` The zsh `load-nvmrc` and fish `load_nvm` examples passed `$(cat .nvmrc)` to `nvm version` and `nvm install`, so a `.nvmrc` symlinked to any readable file put that file's content, a whole one-line file with no `=` needed, in the arguments of `find`, `sed`, and (for fish) `bass` and `bash`, which every local user can read, and tried to install it as a version. Get the version from `nvm_process_nvmrc` instead, as the bash `cdnvm` example has since c314f1cb. bass runs its arguments as bash code, so the fish example also ran `.nvmrc` content like `v20$(touch x)`; pass the path and version to bass in the environment instead. Reported by Anthropic's OSS Scanner, alongside vulnerability ANT-2026-GG4I2LOU. --- README.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ce459708..589d65d4 100644 --- a/README.md +++ b/README.md @@ -866,8 +866,13 @@ load-nvmrc() { nvmrc_path="$(nvm_find_nvmrc)" if [ -n "$nvmrc_path" ]; then + local nvmrc_version + # Let nvm parse `.nvmrc`, so that comments are ignored and the content of an invalid + # or symlinked `.nvmrc` is not passed along to other commands + nvmrc_version="$(nvm_process_nvmrc "${nvmrc_path}")" || return + local nvmrc_node_version - nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")") + nvmrc_node_version=$(nvm version "${nvmrc_version}") if [ "$nvmrc_node_version" = "N/A" ]; then nvm install @@ -906,9 +911,15 @@ function load_nvm --on-variable="PWD" set -l node_version (nvm version) set -l nvmrc_path (nvm_find_nvmrc) if test -n "$nvmrc_path" - set -l nvmrc_node_version (nvm version (cat $nvmrc_path)) + # Let nvm parse `.nvmrc`, so that comments are ignored and the content of an invalid + # or symlinked `.nvmrc` is not passed along to other commands. + # bass runs its arguments as bash code, so pass the path and version in the environment. + set -lx NVMRC_PATH $nvmrc_path + set -lx NVMRC_VERSION (bass source ~/.nvm/nvm.sh --no-use ';' nvm_process_nvmrc '"$NVMRC_PATH"') + or return + set -l nvmrc_node_version (nvm version '"$NVMRC_VERSION"') if test "$nvmrc_node_version" = "N/A" - nvm install (cat $nvmrc_path) + nvm install '"$NVMRC_VERSION"' else if test "$nvmrc_node_version" != "$node_version" nvm use $nvmrc_node_version end