-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do what we can to avoid command injection #46
Conversation
Nice find! The solution doesn't work however on Linux Ubuntu I think, as I can still reproduce even with this fix 🤔 I'm not familiar enough with what could be different from your system (Windows? MacOs?). Do you have any clue? 🤔 |
I wrote this on macOS, but I booted up my Ubuntu 20.04 machine now and it behaves exactly the same. When I test this, I run |
Then I’d try to reproduce from the Node.js REPL instead to minimize the surface and get faster feedback. Something like this:
|
@jfmengels I made a new branch in the repro repo that installs my branch of node-elm-review and automatically verifies that it works: https://github.com/lydell/elm-review-command-injection/tree/fixed
If that prints “ALL OK!” it works, if it prints “PWNED!” it doesn’t (edit: it actually doesn’t print PWNED – see below). |
It's very weird. When trying the REPL, I get the same results that you do. But when I try actually using (Details: I'm never getting the echo "PWNED!" because |
So, the command injection still happens if using I made a PR for npm/npx: npm/run-script#31 But I’d like to fix node-elm-review by removing trying to run elm-format using If you execute If you execute
…because I’d also like to fix the command injection in But before I do anything, I’d like to double-check with @jfmengels:
|
Sorry for the delay!
If everything is as you say (and it seems like it makes sense), then yes. I'm willing to try it out and see if people run into issues. If they do, we can backtrack to re-using
Yes, it's a rarely used feature of the tool and a pretty big package, so I figured it would be okay to include it as needed 😅
I imagine that the most likely case for Thanks for the awesome investigative work, and I hope your work gets merged into |
So to summarize:
Am I understanding that correctly? |
That all sounds good. For the license, I think I already do some validation about the user/repo names (to be confirmed), I'm not sure what can be done about the license question though 🤔 |
We decided to leave the We’ll revisit how to call |
If you have a source-directory named
$(touch pwned)
(like one typically does 😅 ), runningelm-review --fix
results in command injection – a file calledpwned
is created in this case.Repro repo: https://github.com/lydell/elm-review-command-injection
This is because some
spawn
calls useshell: true
. This means “I want my arguments to be interpreted as shell script”, but that’s not what we want in elm-review’s case – we want all arguments to be passed as-is to the program we’re spawning.(Note: One reason to use
shell: true
with Node.js’ built-inspawn
function is to be able to spawn more stuff on Windows, but we’re already using cross-spawn so that’s not something we need to think about: https://github.com/moxystudio/node-cross-spawn#using-optionsshell-as-an-alternative-to-cross-spawn)As far as I can tell,
shell: true
has been there since the code was written. #43 noticed something was up with the arguments handling, but solved it with a non-sufficient escape technique.I’ve tested this on my repro repo. That example also has a space in a folder name and things still work, so #43 should still be fixed.