Skip to content

A '.' entry on PATH lets the repo you just opened execute its own npm

env paths · case

bothsilentscriptagentfirst-partyrepro: verifiedpathext-resolution
Affectsnode, cmd, windows, win32 api
Fails assilent
Mechanismpathext resolution
Safe fixskip relative path entries

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.cmd
npm --version # executes .\npm.cmd — the repo's file

cmd.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.

  • 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.