Skip to main content
Module 3 · Lesson 4 of 411/42 in the course~15 min
Module lessons (4/4)

Prototype Pollution in Deep Merge

Lesson preview6 hands-on exercises readyApplication & Web Security · Module 3 — XSS, CSP & Client-Side Security

Pollute Object.prototype through recursive JSON merging, then harden deep merge helpers against prototype keys.

What you'll learn in this lesson

  • Explain how JavaScript prototype-chain lookup allows {}.isAdmin to return true when Object.prototype is polluted by JSON input.
  • Exploit naive deep-merge utilities via constructor.prototype gadgets even when __proto__ is explicitly blocked.
  • Implement recursive prototype-safe merging (Object.hasOwn + key blocklist) and harden dot-path configuration setters against nested pollution.

Overview

In JavaScript, JSON.parse() treats "__proto__" as a normal own string key on the parsed object rather than updating its prototype. When a recursive merge or query-string parser blindly copies target[key] = source[key], every {} object in the process can suddenly inherit attacker-chosen properties!

Walk through all four stages of the bug and defense:

Sections covered in this lesson

  1. 11. How Recursive Merge Corrupts Every Object in Memory
  2. 22. Interactive Explorer: Gadget Propagation into Client Sinks
  3. 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
  4. 44. Checkpoints & Code Review
Pro Lesson · Module 3 — XSS, CSP & Client-Side Security

Unlock "Prototype Pollution in Deep Merge" and the full Application & Web Security curriculum

Pollute Object.prototype through recursive JSON merging, then harden deep merge helpers against prototype keys.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Application & Web Security plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.