How to fix: Object.assign source from user input
Object.assign(target, userInput) with a user-supplied source (the second argument) copies every enumerable key from userInput onto target, including __proto__ or unexpected fields the caller never intended to accept.
Why it matters
Never pass unsanitized user input as the Object.assign source (second argument); use an allowlist or spread with key filtering instead
Object.assign(target, userInput) with a user-supplied source can pollute Object.prototype or let the caller overwrite fields on target that were never meant to be user-settable.
How to fix it
- 1Never pass unsanitized user input as the Object.assign source (second argument); use an allowlist or spread with key filtering instead
Code examples
Block prototype pollution in Object.assign
function safeAssign<T extends object>(target: T, source: Record<string, unknown>): T {
const banned = new Set(["__proto__", "constructor", "prototype"]);
for (const [k, v] of Object.entries(source)) {
if (!banned.has(k)) (target as Record<string, unknown>)[k] = v;
}
return target;
}
// Never: Object.assign(config, req.body) without validationReferences
Detected automatically by VulnRadar. The check id is code-object-assign-from-user, 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 source from user input?
- 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-object-assign-from-user, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Object.assign source from user input 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.