Node.js & Libuv•Part 4: Express, Fastify, APIs & Middleware (36 - 50)
Security vulnerabilities: Prototype Pollution and ReDoS.
In Simple Words:
- Prototype Pollution: Merging untrusted user objects directly into existing objects mutating
__proto__. Fix: UseObject.create(null)or validate inputs with Zod. - ReDoS (Regular Expression Denial of Service): Evil regexes with catastrophic backtracking freeze the Event Loop. Fix: Avoid nested quantifiers and use safe regex engines like
re2.
javascript
// Prototype pollution vulnerability:
// target["__proto__"]["isAdmin"] = true;
// Safe object creation:
const safeDictionary = Object.create(null);
safeDictionary['user_input'] = 'value'; // Cannot pollute Object.prototype!