Course contentsShow
← Security
Lesson 1194 of 3,05224. Application Security - Input ValidationFree lesson

Prototype Pollution Attack Vectors

Identifying common sources of prototype pollution including JSON parsing, recursive merge, and property assignment vulnerabilities.

Prototype Pollution Attack Vectors

What you'll learn: You'll discover the common entry points attackers exploit to inject malicious properties into JavaScript prototypes.

Now that you understand what prototype pollution is (from the previous lesson), let's identify where these attacks actually happen in real applications.

Common Attack Entry Points

JSON Parsing Vulnerabilities

When applications parse JSON from untrusted sources without validation, attackers can craft payloads that pollute prototypes:

{"__proto__": {"isAdmin": true}}

If your code merges this JSON into an object using unsafe methods, that isAdmin property suddenly exists on all objects in your application.

Recursive Merge Functions

Libraries that deeply merge objects are prime targets. Think of it like mixing paint colors—if you're not careful about what you're mixing in, contamination spreads everywhere:

// Vulnerable merge pattern
function merge(target, source) {
  for (let key in source) {
    if (typeof source[key] === 'object') {
      merge(target[key], source[key]);
    } else {
      target[key] = source[key]; // Danger if key is "__proto__"
    }
  }
}

Property Assignment Vulnerabilities

Dynamic property assignment using bracket notation with user-controlled keys is dangerous:

// User controls propertyName from URL or form
obj[propertyName] = userValue;

If propertyName is "__proto__" or "constructor.prototype", you've just polluted the prototype chain.

Why These Matter

These vectors are everywhere: configuration parsers, deep cloning utilities, query parameter handlers, and API request processors. Attackers look for any place where user input flows into object manipulation logic without proper filtering of prototype-related keys.

Key Takeaway: Prototype pollution attacks exploit JSON parsing, recursive merging, and dynamic property assignments—anywhere user-controlled data touches JavaScript object manipulation without validating against prototype-chain keywords like __proto__ and constructor.