-
Notifications
You must be signed in to change notification settings - Fork 64
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
Unsafe use of exec #60
Comments
Something like the below might work.
|
It is a bit more complicated than that! Your solution does not protect against stuff like this: growl("my message $(ls)"); A more complete solution here: https://github.com/substack/node-shell-quote/blob/master/index.js |
Did you actually test my code? Could you please provide an example that bypasses it? (other than what you have provided as that one does not) No offense, I'm just curious. |
Oops, saw the dollar in the regex later. :( I did not check the code to be honest, but I know for a fact that just replacing one or two characters is usually not enough, you want to maybe quote the string as well. Take a look at the php description of the same thing: |
Even something like this might bypass it: growl("my message; touch a-file") |
Well, I have just checked your example by updating my code to print out the value of the resulting command variable:
So there are double quotes added for any string. (not by my code). Now you may say that let's break out by adding a double-quote. It will not work. :) |
Oops, sorry I did not see the quote part in growl's source code. So, yes probably it works for most of the cases, but I was just trying to convince you to use a more standard solution, rather than a self-baked one. One reason to do so, is that the standard solutions are extensively tested by the community and new patches are added now and then: |
So, I'm not the developer of Growl but I'm happy to play around with things a bit to help improve stuff. I have checked the shellescape you have linked earlier and it solves the problem by wrapping all the stuff in single quotes:
The only side-effect is that you will have double quotes in all parts of the notification. Ok, let's conclude that the optimal for long term would be to eliminate the use of the quote()'s and use shellescape. Deal? :) |
Actually, using spawn() of child_process seems to be a much better solution. And then there's no need for the extra dependency. |
* fix(lib): fixed command injection vulnerability according to Issue #60 * Removed unnecessary dependency by using child_process spawn() method
The module does not sanitize the input before passing it to exec. Therefore, the following code snippet may produce unexpected results for some of the users of the library:
Use a sanitization npm module like shell-quote or replace exec with spawn!
The text was updated successfully, but these errors were encountered: