Node.js · Senior · Question 27 of 75

What is prototype pollution?

merge({}, JSON.parse('{"__proto__": {"isAdmin": true}}'));
({}).isAdmin; // true

Explanation

Unsafe deep merges and path setters are the usual cause. Block __proto__, constructor and prototype keys, use Object.create(null) or Map, and validate input with a schema.

Further reading

Problem with a question

Node.js · Senior · question 27

Test yourself

Take the Node.js · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz