Easy+50 XPA08:2021 Software and Data Integrity FailuresCWE-1321
Prototype PollutionDeep Merge
Scenario
Your application uses a recursive deep-merge utility to combine configuration objects from multiple sources.
An attacker discovers they can supply a JSON body containing a `__proto__` key, which your merge function blindly copies into the target object — polluting Object.prototype for every subsequent object in the process.
Prototype pollution lets attackers silently inject properties onto every object in the application, enabling privilege escalation, authentication bypass, and remote code execution — all without touching your database.
Your Tasks
Identify the keys that must never be merged: `__proto__`, `constructor`, and `prototype`.
Add a guard at the top of the recursive branch that throws `'Prototype pollution detected'` when a forbidden key is encountered.
Ensure normal deep merges still work correctly and return the merged object.