How to fix: Object.assign with __proto__ key
Object.assign(target, JSON.parse(userInput)) or spread {...userInput} into a target object copies a __proto__ key literally; combined with a subsequent access, this can pollute Object.prototype in engines that honor the assignment.
Why it matters
Object.prototype pollution enables XSS, type confusion, and bypass of authorization checks.
The `code-proto-pollution-object-assign-proto` check verifies that the server does not expose the `proto-pollution-object-assign-proto` 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
- 1Use Object.create(null) as the target for untrusted key sets.
- 2Filter keys against an allowlist before Object.assign.
- 3Adopt Object.hasOwn or hasOwnProperty checks on every read.
Code examples
Strip prototype keys before Object.assign
function safeAssign<T>(target: T, ...sources: Record<string, unknown>[]): T {
const blocked = new Set(["__proto__", "constructor", "prototype"]);
for (const source of sources) {
for (const [k, v] of Object.entries(source)) {
if (!blocked.has(k)) (target as Record<string, unknown>)[k] = v;
}
}
return target;
}References
Detected automatically by VulnRadar. The check id is code-proto-pollution-object-assign-proto, 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 Object.assign with __proto__ key?
- VulnRadar rates this medium 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-object-assign-proto, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Object.assign with __proto__ key 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.