A '.' entry on PATH lets the repo you just opened execute its own npm
env paths · case
Affectsnode, cmd, windows, win32 api
Fails assilent
Mechanismpathext resolution
Safe fixskip relative path entries
Symptom
Section titled “Symptom”A tool spawns npm on Windows. In most directories it runs the real npm. In
one particular cloned repo, it runs… something else. Nothing errored; the
attacker-controlled npm.cmd in the repo root simply won.
PATH=.;C:\Program Files\nodejs\cd C:\cloned\evil-repo # contains npm.cmdnpm --version # executes .\npm.cmd — the repo's filecmd.exe (and resolution that mimics it) walks every PATH entry in order,
including relative entries like .. A leading dot entry makes the CURRENT
DIRECTORY the highest-priority tool source — so opening a repository is
equivalent to prepending that repository to PATH.
Workaround
Section titled “Workaround”- When resolving commands for spawn, skip relative PATH entries and the exact cwd (but not legitimate home-subtree entries like %AppData%\npm — the referenced fix threads that needle).
- Defense in depth: resolve to absolute paths once, then spawn the absolute path.