Skip to content
Prototype pollution Disclosed report Advanced CVE-2023-30581

The use of __proto__ in process.mainModule.__proto__.require() bypasses the permission system in Node v19.6.1

Node's experimental permission policy system checked require() on process.mainModule but not the same method reached through the object's prototype. An attacker who could run a script under a restrictive policy could load modules the policy did not permit.

haxatron1 Follow

Originally disclosed on HackerOne

High 8.4 View original
  • Triaged in 6 days
  • Fixed in 4 months
  • Disclosed after 5 months

process.mainModule.require() correctly works with permission system in Node v19.6.1. But the use of __proto__ in process.mainModule.__proto__.require() can bypass the check.

Description and STR

Consider the following policy.json:

{
  "resources": {
    "./proc.js": {
      "integrity": true
    }
  }
}

The policy only allows proc.js file to be loaded without any dependencies.

However with the following proc.js

const os = process.mainModule.__proto__.require("os")

console.log(process.version)
console.log(os.version())

We get the output:

└─$ ../node-v19.6.1-linux-x64/bin/node --experimental-policy=policy.json proc.js
v19.6.1
#1 SMP PREEMPT Debian 5.16.18-1kali1 (2022-04-01)
(node:2720) ExperimentalWarning: Policies are experimental.
(Use `node --trace-warnings ...` to show where the warning was created)

Therefore os dependency can be loaded and os.version executed even if unspecified in permission system.

Impact

Bypass the permission system

The original report as published on HackerOne, by haxatron1. 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 check was attached to the process.mainModule.require property rather than to the underlying loader, so the same function reached via the prototype chain skipped the check.

Impact

A script running under the experimental policy could load and execute modules the policy did not allow, bypassing the permission system.

What the attacker needed

Ability to run a script under a Node policy; Node v19.6.1 with experimental policies

How it was found

  1. Create a policy file that permits only one script and no dependencies.
  2. Write a script that loads a module through the prototype of process.mainModule instead of calling require directly.
  3. Run Node with the experimental policy flag and observe the module loading despite the policy.

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.

Node can be told, through a policy file, which files and modules a script is allowed to load. The check was applied to one way of calling the module loader but not to an equivalent way reached through the object's prototype, so a script could load a module the policy meant to block.

What is Prototype pollution?

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.

More by haxatron1

View all

30 more disclosed reports, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Prototype pollution

The lesson behind this report.

Input changes JavaScript's shared object prototype, altering behaviour across the application, sometimes to XSS or code execution.