Problem, as an interviewer would state it:
"Write a real, safe deepMerge(target, source) where source may be genuinely UNTRUSTED (e.g. real, user-submitted JSON) — explicitly block keys that could pollute the shared, global Object.prototype."
Examples:
const malicious = JSON.parse('{"__proto__": {"polluted": "yes"}}');
safeMerge({}, malicious);
({}).polluted; // undefined -- genuinely NOT polluted
Clarifying questions expected:
- What are the SPECIFIC keys that can enable this real vulnerability, and why does JSON.parse make it a genuine, live risk (versus a literal object)?
- Should the merge recurse into nested objects, and does the same blocking need to apply at EVERY nesting level?
- Is this purely a defensive concern, or has this been a real, documented vulnerability class in real, popular libraries?
Code / implementation expected: Yes — real, direct, LIVE demonstration: a genuine malicious payload correctly blocked by the safe version, contrasted against a naive merge shown to GENUINELY pollute the real global Object.prototype.