BERRY9 IT Services, home +91 86868 92922

Prototype Pollution in 2025: From Toy to Tenant-Takeover

Prototype pollution was treated as a curiosity for a long time — interesting in theory, hard to exploit in practice. That has changed. In modern Node and browser code, prototype pollution is a reliable gadget for remote code execution server-side and DOM XSS client-side. Here is the current state.

Web applications · By Thimmagurudu Bathini · Published · 6 min read · Last reviewed

The primitive

JavaScript objects inherit from Object.prototype. A deep-merge or recursive-assign function that does not check property names will let an attacker write to __proto__.x, which makes x appear on every object in the runtime. Libraries with vulnerable merges include older versions of lodash, deepmerge, and any home-rolled deep copy.

// Vulnerable merge
merge({}, JSON.parse(req.body));
// payload: {"__proto__": {"isAdmin": true}}
// effect: every object now has isAdmin=true

Server-side gadgets

Once an attacker can set arbitrary keys on the prototype, the next step is finding a sink that reads from a polluted key. Common sinks: shell argument to child_process.spawn, Express options for view rendering, Mongoose schema options. Public research has demonstrated full RCE chains in real frameworks.

Client-side gadgets

In the browser, prototype pollution combined with a template engine or sanitizer that checks options against the prototype becomes DOM XSS. The path is usually: pollute __proto__.src, trigger a code path that reads options.src, end with arbitrary script execution.

Defenses

Use Object.create(null) for any object built from user input. Set Object.freeze(Object.prototype) at process start (be aware of compatibility). Update lodash and similar merge libraries to versions that explicitly reject __proto__, constructor, prototype keys. Static analysis flags most cases; manual review catches the rest. Our Node.js pitfalls piece has the framework-specific list.

Written by Thimmagurudu Bathini, BERRY9 IT SERVICES PRIVATE LIMITED, Hyderabad. Questions about your own systems? Request a scoping call or call +91 86868 92922.

Plan your next security test

Tell us what needs testing and when you need it done, and we will propose a scope and timeline. We respond within 24 hours. If you would rather talk first, call or write to us.