How Secure is using execFile for Bash Scripts?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:35:20

问题


I have a node.js app which is using the child_process.execFile command to run a command-line utility.

I'm worried that it would be possible for a user to run commands locally (a rm / -rf horror scenario comes to mind).

How secure is using execFile for Bash scripts? Any tips to ensure that flags I pass to execFile are escaped by the unix box hosting the server?

Edit

To be more precise, I'm more wondering if the arguments being sent to the file could be interpreted as a command and executed.

The other concern is inside the bash script itself, which is technically outside the scope of this question.


回答1:


Using child_process.execFile by itself is perfectly safe as long as the user doesn't get to specify the command name.

It does not run the command in a shell (like child_process.exec does), so there is no need to escape anything.




回答2:


child_process.execFile will execute commands with the user id of the node process, so it can do anything that user could do, which includes removing all the server files.

Not a good idea to let user pass in command as you seem to be implying by your question.

You could consider running the script in a sandbox by using chroot, and limiting the commands and what resides on the available file system, but this could get complet in a hurry.

The command you pass will get executed directly via some flavor of exec, so unless what you trying to execute is a script, it does not need to be escaped in any way.



来源:https://stackoverflow.com/questions/15168071/how-secure-is-using-execfile-for-bash-scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!