Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.JS switch user while running

Is it possible for a Node.JS program that is running as root, to downgrade its authority while it is running? This would be one of the first things it does, and the purpose is of course to limit possible damage it could cause, in the unlikely event that there is a vulnerability, or mis-trusted code that runs in this process.

Alternatively, is there a way for Node.JS process that is running as root, to start a separate process which is non-root? (preferably without adding a layer in between, such as sudo)

like image 718
700 Software Avatar asked Nov 06 '12 21:11

700 Software


2 Answers

Try process.setuid (and likewise, process.setgid).

like image 86
mabako Avatar answered Nov 14 '22 07:11

mabako


Yes, use process.setuid(id) and process.setguid(id) to change the effective user/group id of the current process.

like image 3
Peter Lyons Avatar answered Nov 14 '22 06:11

Peter Lyons