question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Escaping shell arguments to exec()

See original GitHub issue

First 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:closed
  • Created 9 years ago
  • Reactions:17
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

17reactions
cscottcommented, Feb 7, 2016

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.

13reactions
OmgImAlexiscommented, Sep 11, 2017

Are there any updates on this? This has been open for 3 years now.

Ref: https://snyk.io/vuln/npm:shelljs:20140723

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found