-
-
Notifications
You must be signed in to change notification settings - Fork 35k
Description
problem: When you use third party modules, they often have a lot of dependencies, and it only takes one compromised module out of tens of thousands to infect your own app with a backdoor, that might steal your .ssh keys or crypto wallet, or create a remote shell.
solution: A new function "requires" (require securely) that works similar to require, but does not give access to fs, net, os, native (and others) built in modules unless specifically allowed when requiring the module.
const foo = requires("bar", {fs: true, net: "0.0.0.0:8000", os: true});
First parameter is the module name (bar), and the second parameter is the settings object; which specifies what native modules can be used.
If the value is truthy, it will be allowed.
Further settings can be specified as a string or object (for future refinement) eg. if we want to add the option to restrict port and IP.
Alternatives are Realms and SES (Secure ECMAScript), but I think requires will be easier to implement, and easier for the user/developer to require modules securely.
Currently you can restrict your app using Linux namespaces, se_linux, Apparmor, user access, etc, but then it will apply to your whole app! The idea is to make restrictions to individual modules and their dependencies!
With "requires" you can give for example file-system (fs) access to only the modules that actually need it.
Additional request:
If "requires" is implemented, effort should be taken in order to make it fast, see: #29789