Prototype pollution from deep-merging user JSON into objects

Last updated November 11, 2026
Steps
- Search the project for hand-written merge, clone, extend, defaultsDeep, set-by-path and “apply patch” helpers, plus any loop that does target[key] = source[key] over request JSON, query strings or form data.
- In each, skip or reject the keys __proto__, constructor and prototype at every level—or better, rebuild the object from an allowlist of expected fields.
- Validate request bodies with a strict schema (Zod, Joi, Ajv, Pydantic-style) that rejects unknown keys, so arbitrary nested keys never reach merge code.
- Use Map or Set for user-keyed lookups instead of plain objects, and create plain dictionaries with Object.create(null) so they have no prototype to pollute.
- Avoid authorization checks that read a property that might come from the prototype (if (user.isAdmin)); use Object.hasOwn(user, 'isAdmin') or explicit fields from your database.
- Update merge and query-string libraries: prototype pollution has been reported in popular helpers, and fixes ship in newer versions. Run npm audit and check advisories.
- As defense in depth on Node.js servers, consider starting with --disable-proto=delete, and test that your dependencies still work.
- Retest: send {"__proto__":{"polluted":true}} and a constructor.prototype variant to every JSON endpoint, then confirm ({}).polluted is still undefined on the server.
Why it matters
MITRE CWE-1321 notes the weakness is often found in code that assigns object attributes from user input or merges and clones objects recursively, and lists real CVEs in object-merging and set-by-path helpers. OWASP’s Prototype Pollution Prevention Cheat Sheet recommends Map/Set, prototype-less objects via Object.create(null), carefully tested freezing of built-in prototypes, and Node’s --disable-proto flag as a defense-in-depth measure. PortSwigger’s Web Security Academy covers both server-side and client-side variants.
Sources
MITRE CWE-1321: Improperly Controlled Modification of Object Prototype Attributes — https://cwe.mitre.org/data/definitions/1321.html
OWASP Cheat Sheet: Prototype Pollution Prevention — https://cheatsheetseries.owasp.org/cheatsheets/Prototype_Pollution_Prevention_Cheat_Sheet.html
PortSwigger Web Security Academy: Prototype pollution — https://portswigger.net/web-security/prototype-pollution
MDN Web Docs: JavaScript prototype pollution — https://developer.mozilla.org/en-US/docs/Web/Security/Attacks/Prototype_pollution
Node.js documentation: Command-line options (--disable-proto) — https://nodejs.org/api/cli.html
Checked at the source on November 7, 2026.
Related patterns
- Mass assignment: users can set fields like role or is_admin
- Running AI or user output with eval, exec or new Function (code injection)
- Server-side template injection from unsanitized template strings
- Outdated packages with known vulnerabilities
- AI-suggested packages that don't exist (slopsquatting)
- NoSQL operator injection: login and search filters built from raw JSON
Found a problem you'd rather not fix yourself?
Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.
Get it fixed by StorenTechVibe Security Weekly
One email a week with new failure patterns and how to fix them.
By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.