且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

节点-防止子进程进入父目录

更新时间:2023-02-05 21:23:54

您可以将进程作为 chroot 的参数生成,这将更改您进程的根目录:

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', ...]);

另一种方法是使用 chroot node-posix 模块中的函数(但要防止生成您的Node进程)外部程序也不会被chroot,您可能需要先进行派生并从子进程中调用chroot。)

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).