How to fix: deep-extend / deepmerge prototype pollution
Lodash's _.merge and _.mergeWith, jQuery's $.extend(true, ...), and libraries such as deep-extend recursively copy enumerable keys. When the source contains __proto__, constructor.prototype, or prototype, the copy writes to Object.prototype.
Why it matters
Polluting Object.prototype can lead to XSS, authentication bypass, denial of service, or remote code execution.
The `code-proto-pollution-deep-merge` check verifies that the server does not expose the `proto-pollution-deep-merge` weakness in the code category. The detection runs against the response headers, body, or auxiliary probes (DNS, TLS, async fetch) as appropriate.
How to fix it
- 1Upgrade Lodash to 4.17.21+ or use lodash-es with the same patch.
- 2Replace jQuery $.extend(true, ...) with structuredClone after sanitizing keys.
- 3Sanitize keys: skip __proto__, constructor, prototype before merging.
Code examples
Protect deep merge against prototype pollution
function deepMerge(target: Record<string, unknown>, source: Record<string, unknown>) {
const blocked = new Set(["__proto__", "constructor", "prototype"]);
for (const [k, v] of Object.entries(source)) {
if (blocked.has(k)) continue;
if (v && typeof v === "object" && !Array.isArray(v)) {
target[k] = deepMerge((target[k] as Record<string, unknown>) ?? {}, v as Record<string, unknown>);
} else {
target[k] = v;
}
}
return target;
}References
Detected automatically by VulnRadar. The check id is code-proto-pollution-deep-merge, stable across every scan so you can filter or diff on it.
More code checks
- CriticalForm Submits Data Over Insecure HTTP
- MediumPotential Prototype Pollution Sinks Detected
- HighPotential Command Injection Vectors
- HighJWT Decoded Without Signature Verification
- HighPotential Path Traversal Vulnerability
- HighInsecure Authentication Mechanisms Detected
- HighPotential Insecure Deserialization
- Mediumeval() Usage in Inline Scripts
Questions
- How severe is deep-extend / deepmerge prototype pollution?
- VulnRadar rates this high severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id code-proto-pollution-deep-merge, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does deep-extend / deepmerge prototype pollution map to?
- It maps to CWE-1321.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.