Escaping shell arguments to exec()
See original GitHub issueFirst of all, I just want to say thanks for writing shelljs. It cleans up my code a lot.
I need to invoke commands with shell.exec()
, however, those commands will include some input from external sources, to be passed as arguments to system executables. Is there a “safe” way to do this? I was hoping for the classic array syntax, like:
shell.exec(["ls", "-l", "/some/path"])
Though this doesn’t seem to be implemented. It doesn’t appear nodejs itself even has a shell escape function neither. Any plans on this front?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:17
- Comments:27 (13 by maintainers)
Top Results From Across the Web
escapeshellarg - Manual - PHP
escapeshellarg — Escape a string to be used as a shell argument ... The shell functions include exec(), system() and the backtick operator....
Read more >How do I escape a string for a shell command in node?
exec (cmd). I'd like to call an external command and give it data via stdin. In nodejs there does yet not appear to...
Read more >Shell string escape for command arguments [duplicate]
For integration reasons, I have to keep the ARGS building in 2 steps: ARG = some_options + $DIR This code create 2 dirs:...
Read more >Prevent Escaping exec.Command Arguments in Go
Prevent Escaping exec.Command Arguments in Go ... In Go, I was trying to add the ability to run administrative installations in my project...
Read more >linux - bash: how to pass command line arguments containing ...
Escape each single special symbol with a backslash (as in \[abc\]_\[x\|y\] ) or; Double-quote the entire argument (as in "[abc]_[x|y]" ).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Please. Providing only a string argument here is a recipe for disaster, honestly. As pointed out, it’s basically impossible to “properly” quote any arguments given. As is,
exec
is vulnerable to file names containing spaces, special characters, semicolons, the works. Cf http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/handle-metacharacters.html and the “motivation” section of (for example) https://www.python.org/dev/peps/pep-0324/. A security-conscious API should strongly encourage providing arguments as an array by default.Are there any updates on this? This has been open for 3 years now.
Ref: https://snyk.io/vuln/npm:shelljs:20140723