[BUG] npx@7 regression: command injection / impossible to pass a bactick as argument #3306
Closed
1 task done
Labels
Bug
thing that needs fixing
cmd:run-script
related to `npm run-script`
Priority 2
secondary priority issue
Release 7.x
work is associated with a specific npm 7 release
Release 8.x
work is associated with a specific npm 8 release
Is there an existing issue for this?
Current Behavior
Let’s say you have a
create-blog-post
CLI installed globally. You run it like so:One day you install
create-blog-post
locally instead. Then how do you run it? Well, you could just slapnpx
at the start, right? Wrong! The following does not do what you expect:Let me show why. I’m using
node -p 'process.argv[2]' --
instead ofcreate-blog-post
to show that the implementation of that tool wouldn’t matter:With
npx
in front:Oops! The argument was treated as shell script, executed
ls
and put the result in my string (backticks means command interpolation)!Expected Behavior
npx@6
got it right:The worst thing is that I don’t even know how to workaround this issue in npx@7. Trying to add backslashes does not help. I just can’t figure out a way to pass literal backticks as an argument.
Steps To Reproduce
npx node -p 'process.argv[1]' '`'
(tested insh
,bash
,zsh
,fish
)sh: -c: line 0: unexpected EOF while looking for matching ``'
Environment
Fix
npm/run-script#31
I’m posting an issue here as well so the PR has something to close 😄 And also to help people who have encountered the same problem can more easily find this.
The text was updated successfully, but these errors were encountered: