🇰🇷 한글 설명
Node Version Manager(nvm) 0.40.0부터 0.40.8까지의 버전에서 `nvm use --save` 및 `nvm install --save`(또는 `-w`) 명령이 해석된 버전을 `$PWD/.nvmrc`에 `tee`로 기록하는데, 이 과정에서 심볼릭 링크를 따라가 쓰기가 이루어집니다. 저장소가 외부 경로를 가리키는 `.nvmrc` 심볼릭 링크를 포함하면, 사용자가 쓰기 권한을 가진 쉘 시작 파일이나 `~/.ssh/authorized_keys` 같은 파일이 잘려 나가고 버전 문자열로 덮어써질 수 있습니다. 공격자가 기록되는 내용을 통제할 수 없으므로 데이터 손실 문제이며 코드 실행으로 이어지지는 않습니다. 0.41.0 버전에서는 현재 디렉터리의 `.nvmrc`가 심볼릭 링크(끊어진 링크 포함)이면 경고와 함께 쓰기를 거부합니다.
💡 쉬운 설명
nvm을 쓰는 사용자가 악성 저장소를 받아 특정 명령을 실행하면, 저장소 안의 링크를 통해 내 중요한 설정 파일이 버전 번호 글자로 덮어써져 내용이 사라질 수 있습니다. 해커가 새로운 코드를 심을 수는 없지만 파일 손실 피해가 발생합니다.
🇺🇸 원문 (English)
Node Version Manager (nvm) is a POSIX-compliant shell function for managing multiple node.js versions. In versions 0.40.0 through 0.40.8, `nvm use --save` and `nvm install --save` (or `-w`) write the resolved version to `$PWD/.nvmrc` with `tee`, which follows a symbolic link. A repository that commits `.nvmrc` as a symlink to a path outside itself (git recreates the link on clone) therefore makes `--save` truncate any file the user can write, such as a shell startup file or `~/.ssh/authorized_keys`, and replace its contents with the version string, or create the target of a dangling link; the link itself is left unchanged, so `git status` stays clean. The attacker does not control the content written, so this is data loss, not code execution. Version 0.41.0 refuses, with a warning, to write when `.nvmrc` in the current directory is a symlink, dangling or not, rather than writing through it or replacing it.
📍 영향받는 시스템
nvm 0.40.0 ~ 0.40.8 (0.41.0 이상에서 수정)
⚔️ 공격 벡터
외부 경로를 가리키는 .nvmrc 심볼릭 링크가 포함된 저장소를 클론한 뒤 `nvm use --save` 또는 `nvm install --save`를 실행하여 링크 대상 파일을 덮어쓰게 함
🛡️ 대응 방법
nvm을 0.41.0 이상으로 업그레이드하고, 신뢰할 수 없는 저장소의 .nvmrc 심볼릭 링크를 확인하여 제거
🔧 검증 코드
출력된 버전이 0.40.0~0.40.8 범위에 해당하면 취약하며, 0.41.0 이상이면 패치된 상태입니다.
nvm --version 2>/dev/null || (. ~/.nvm/nvm.sh && nvm --version)