Node - Prevent child process from going in to parent directory

浪子不回头ぞ 提交于 2019-12-24 09:09:47

问题


I am spawning a process from my node server, that is in /tmp/running/username (it is a node process uploaded by the user)

how do I prevent it from reading (or knowing of the existence of) anything other than /tmp/running/username?

I can spawn the process in any required way.


回答1:


You could spawn the process as an argument for chroot, which will change the root directory for your process:

spawn('chroot', ['/tmp/running/username', 'yourprocess', 'arg1', ...]);

An alternative would be to use the chroot function from the node-posix module (but to prevent the Node process from which you spawn your external program from being chrooted as well, you may need to fork first and call chroot from the child process).



来源:https://stackoverflow.com/questions/15852387/node-prevent-child-process-from-going-in-to-parent-directory

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