Skip to content
Access control Disclosed report Intermediate CVE-2023-23918

Permissions policies can be bypassed via process.mainModule

Node's experimental permission policy feature was meant to restrict which built-in modules a script could load, but a script could reach any module through process.mainModule.require instead of the normal require. An attacker running code under a policy could therefore escape the intended sandbox and load modules that were not whitelisted.

goums Follow

Originally disclosed on HackerOne

High 7.1 View original
  • Triaged in 2 days
  • Fixed in 4 months
  • Disclosed after 5 months

Summary: Permissions policies module can be bypassed via process.mainModule.require

Description: Permission policies allow to run a script with a specific set of authorized node js built-in modules. However, the script could access non authorized modules by calling process.mainModule.require()

Steps To Reproduce:

  1. Create escape.js file:
console.log(process.mainModule.require("os").cpus());
  1. Create policy.json file:
{
  "onerror": "exit",
  "scopes": {
    "file:": {
      "integrity": true,
      "dependencies": {}
    }
  }
}
  1. Run:
node --experimental-policy=policy.json escape.js
  1. You will see your os cpus listed in the console even though the escape.js file does not have the permission to import the nodeos module

Impact:

Permission policies are supposed to enforce imported modules to a limited whitelist. This vulnerability allow a script to include any non-whitelisted module.

If you modify escape.js to use top level require statement, like this:

const os = require("os");
console.log(os.cpus());

and run again:

node --experimental-policy=policy.json escape.js

you'll now see this error:

Error [ERR_MANIFEST_DEPENDENCY_MISSING]: Manifest resource escape.js does not list os as a dependency specifier for conditions: require, node, node-addons

which is the expected behavior and should be enforced as well when using process.mainModule.require

Impact

Any project that uses permission policies for arbitrary code execution are vulnerable to sandbox escaping. This example show a non-critical permission gain (listing the machine cpu), but an attacker could do much more damage by accessing internal file system, running child processes, ...

The original report as published on HackerOne, by goums. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the policy enforcement only hooked the standard require path and did not cover the equivalent module-loading route exposed through process.mainModule.

Impact

A script running under a permission policy could load any non-whitelisted module, so projects relying on policies for sandboxing arbitrary code could be escaped, with the example showing only a minor gain but potentially allowing file system access or child processes.

What the attacker needed

Node run with the experimental policy flag; Attacker controls the script being run

How it was found

  1. Create a small script that loads a built-in module through process.mainModule.require and prints its output.
  2. Create a policy file that does not list that module as a dependency.
  3. Run the script with the experimental policy flag pointing at the policy file.
  4. Observe the module's output appears even though the policy did not allow it.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A permission policy is a list that says which built-in pieces of Node a script is allowed to use, a bit like a guest list. The check only looked at the normal way of asking for a module, so a script could ask through a different door and get anything it wanted. That means the guest list could be ignored.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.