Menu

☣️ Prototype Pollution in Node.js: Fix Your Deep Merge, Then Prove It
📰

☣️ Prototype Pollution in Node.js: Fix Your Deep Merge, Then Prove It

DEV Community: appsec·Krishna Kumar·12 days ago
#o7DkPapx
#devtoappsec#devto#dev#prototype#object
Long article (2460 words) — no AI summary yet.
Reading 0:00
15s threshold

Plenty of Node apps have a small deep-merge helper somewhere in utils/ . It takes a user's settings JSON, merges it over the defaults, and returns the result. It's ten lines long, it looks harmless, and with the right payload it can add a property to every object in the process.

That's prototype pollution. This post is the developer side of it: what the bug is, where it hides, how to fix it so the fix holds, and a small test suite that proves the fix instead of hoping. Everything below runs on your own machine with stand-in data. Only test systems you own or are authorized to test.

What prototype pollution is

Almost every JavaScript object inherits from Object.prototype . When you read a property an object doesn't have, the runtime walks up the prototype chain and checks there.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.