运行 bash 后台脚本安全吗?

Running bash script in backend safe?

您好,我对网络安全还很陌生,担心可能的 shell/command 注入风险。我想知道仅在我的 nodejs 后端 运行 命令行脚本并让 Web 主机 运行 它是否安全。

据我了解,运行 是安全的,因为无法从网站及其前端访问后端。

From my understanding, it would be safe to run as the backend is not able to be accessed from the website and its front end.

这基本上是正确的,但我会改写为:

It is safe to run a shell script from your web server as long as the parameters you are passing to the shell script are either hard-coded or server-generated values.

Shell - 当您获取来自网络用户的字符串并将它们作为参数传递给 exec 调用时,就会发生注入。可以安全地执行此操作,但您需要仔细清理或转义输入以使其命令行安全,但这有点棘手且难以正确执行,因为您需要的“危险字符”列表bash vs zsh vs powershell 等

中的清理/转义是不同的