Detecting Prototype Pollution Vulnerabilities
What you'll learn: How to systematically find prototype pollution flaws before attackers exploit them in your JavaScript applications.
The Detection Challenge
Now that you understand prototype pollution's dangers, finding these vulnerabilities in real codebases becomes critical. Detection requires specialized techniques because these flaws hide in innocent-looking property assignments, especially in deep merge operations and recursive functions.
Three Core Detection Methods
1. Gadget Chains
Think of gadgets as "exploitable stepping stones." Scanners look for code patterns that use polluted properties—like template engines reading Object.prototype.template or frameworks checking Object.prototype.isAdmin. Finding gadgets proves a pollution vulnerability is actually exploitable, not just theoretical.
2. Property Testing
This direct approach injects test properties (like __proto__.testProperty123) then checks if they appear on clean objects:
// Detection test pattern
let testObj = {};
merge(userInput, targetObject); // Potentially vulnerable
if (testObj.testProperty123 !== undefined) {
// Prototype pollution detected!
}
3. Automated Tools
Specialized scanners analyze:
- Static analysis: Parse code to find dangerous patterns like
obj[key] = valuewithout__proto__checks - Dependency scanning: Check if npm packages have known pollution CVEs
- Dynamic testing: Run applications with crafted payloads and monitor prototype chains
Effective Detection Workflow
- Audit dependencies for known vulnerabilities (lodash <4.17.12, etc.)
- Scan user-controlled input paths to merge/extend functions
- Test with payloads like
{"__proto__": {"polluted": true}} - Monitor Object.prototype in staging environments for unexpected properties
Key Takeaway: Detecting prototype pollution requires combining automated tools (for scale), gadget chain analysis (for exploitability), and property testing (for confirmation)—defense begins with knowing where pollution hides.