Skip to content

requires - require modules securely (restricted access to fs,net, etc) #29788

@Z3TA

Description

@Z3TA

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    deprecationsIssues and PRs related to deprecations.experimentalIssues and PRs related to experimental features.policyIssues and PRs related to the policy subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions