Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to restrict the access of child processes to my system in node.js?

Tags:

node.js

I am trying to build a service to execute programs in different languages in node and give the output. So far I'm using the child_process's spawn for spawning commands.

let p = spawn('python',[sourceFilePath]);

Is there a way so that I can limit the access of this child_process to my system so it can't access network,file system,etc ?

like image 986
vibhor1997a Avatar asked Aug 15 '18 04:08

vibhor1997a


1 Answers

if it's Unix you can provide uid, gid of user/group with lower permissions:

var child = spawn(process, args, {
    detached: true,
    uid: uid, 
    gid: gid, 
    cwd: appDir,
    stdio: [ 'ignore', 'pipe', 'pipe']
})
like image 82
maximus Avatar answered Nov 09 '22 08:11

maximus