Skip to content
Prototype pollution Write-up Advanced

Exploiting prototype pollution in Node without the filesystem

A new technique lets an attacker turn server-side prototype pollution into code execution by abusing the Node --import command line flag with a data URL, so no file on disk is needed. An attacker who can pollute Object.prototype can set NODE_OPTIONS and have a forked child process load and run arbitrary JavaScript.

Gareth Heyes Follow

Published on portswigger.net

In this post, we'll introduce a new exploitation technique for Server-Side Prototype Pollution.

Gareth Heyes (@garethheyes), on portswigger.net

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

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

How it worked

Root cause

Likely Node accepts the --import flag inside NODE_OPTIONS and allows data: URLs as the module source, so a polluted prototype value reaches a fork() sink and loads attacker code.

Impact

An attacker who can pollute the prototype and reach a fork() sink could execute arbitrary code and read or write files on the server; the Node maintainers did not treat the flag behaviour as a security issue in their threat model.

What the attacker needed

Server-side prototype pollution; a fork() sink in the app; Node 19.0.0 or later

The fix

Node should be fixed so that NODE_OPTIONS rejects the --import flag or data: URLs, since the maintainers declined to change it.

How it was found

  1. Pollute Object.prototype with a NODE_OPTIONS value that uses the --import flag with a data URL.
  2. Trigger a fork() call so a child Node process starts with the polluted options.
  3. The child process loads the data URL module, which imports Node modules and runs the attacker's code.

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 write-up has not been written yet. The Original tab links to the source.

Prototype pollution is when an attacker sneaks extra settings into a shared object that many parts of a program rely on. Here the polluted setting is an environment variable that Node reads when it starts a child process, and it tells Node to load code from a data URL instead of a file. That means the attacker's code runs on the server, which is a serious step up from just changing values.

What is Prototype pollution?

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

More by Gareth Heyes

View all

15 more disclosed reports, best first.

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.