-
Notifications
You must be signed in to change notification settings - Fork 62
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
Allow arguments to be passed out-of-band from script text #83
Comments
To be clear, by the way, the given |
Yes, I agree with you. It's dangerous. But considering most (if not all) of the users of IMHO, injections like Thanks for your advice anyway. I will put a warning on the documentation. |
It's not just dangerous, it can stop things from working if, say, the filename contains a space. (And I suspect this can happen very easily under Windows!) So, ideally the interpolation operation ( |
Escaping at interpolation time is only safe if you know the quoting context into which those results are going to be used. The escaping that's appropriate for (As an example, if you just have a name with a space, Passing data out-of-band from code, by contrast, there is no such thing as a quoting context -- the entire range of issues is moot. |
Yes, that's how any escaping works. :) However, this could at least produce one correct way of embedding dynamic data into the shell invocation, without changing the overall usage pattern. And this one correct way can then be explicitly documented. Definitely an improvement over the current situation, when there is no reliable/safe way to embed the data at all.
To be honest, one can screw the shell command even in such circumstances. For example, if the file name is passed as an environment variable, you can forget to quote it (for example, in |
"A problem", certainly. Arbitrary code execution, more rarely -- the example given runs an arbitrary A solution that split the difference -- offering both quoted expansion into a string parsed as code and out-of-band argument-passing, with choice at the user's discretion -- would be well in line with practices in other parts of the world (ie. the Python standard library providing both a |
Templating filenames as strings into a shell script -- as
gulp-shell
recommends -- is extremely dangerous practice from a security perspective. The best-practice approach is for script text to be hardcoded, and for parameters to be passed out-of-band, as arguments or in the environment. Demonstrating two possible argument vectors with the same literal argument:Note the literal single quotes in dangerString, such that even putting single quotes around the expansion cannot prevent one or the other of the command substitutions contained within from being expanded.
Not only should a tool that's advertised as a way to call a shell from JavaScript implement a safe way to do so, but it should document and advertise safe practices as the preferred way to use it.
The text was updated successfully, but these errors were encountered: