Performing actions that require superuser privileges


#1

I want to add rules to the users’ firewall. To do this I need super-user (sudo) privileges so I need to prompt the user for their password. What is the best way to do this in Electron?


#2

Prompt the user for a password, use child_processes and expect and write.
Theoretically, saving the password in memory would mean that other programs who have access to the memory would be able to dump it.


#3

Is there a native password input dialog box? Presenting the user with a web-based form seems like it could confuse the user and raise security concerns.

I’m considering using node-applescript although that will mean that I will need to come up with a different approach for other platforms.

applescript.execString('do shell script "sudo something" with administrator privileges');

#4

If I’m correct, there’s gksudo and kdesudo for that, but you’ll never be sure the user has those installed…


#5

Is it worth creating a feature request for something like this on Electron? I think it would it be useful if Electron could handle this, rather than having to come up with a custom approach for each platform.


#6

I’ve used sudo-prompt before, still annoying for users but works:

https://www.npmjs.com/package/sudo-prompt