Version Number
7.80.0
Steps to reproduce
The unset() utility in src/utils/unset.ts traverses path segments using baseGet() without filtering out prototype-pollution keywords (__proto__, constructor, prototype).
set.ts already guards against this with:
if (PROTOTYPE_KEYWORDS.includes(key)) {
return;
}
But unset.ts (and its internal baseGet helper) have no equivalent protection. As a result, a path like "__proto__.foo" causes baseGet to walk from the target object into Object.prototype, and the subsequent delete childObject[key] then deletes a property from Object.prototype itself.
import unset from "./src/utils/unset";
// Assume Object.prototype has been extended (e.g. by another library)
Object.prototype.polluted = "SENSITIVE";
console.log({}.polluted); // "SENSITIVE"
unset({}, "__proto__.polluted");
console.log({}.polluted); // undefined — deleted from the prototype!
Expected behaviour
unset() should ignore (no-op) any path that contains __proto__, constructor, or prototype, consistent with the protection already present in set.ts.
Root cause
unset.ts:baseGet traverses path segments unconditionally:
function baseGet(object: any, updatePath: (string | number)[]) {
// ...
while (index < length) {
object = object[updatePath[index]]; // ← no prototype keyword check
index++;
}
return object;
}
stringToPath("__proto__.polluted") → ["__proto__", "polluted"].
baseGet then dereferences object["__proto__"] → Object.prototype.
delete Object.prototype["polluted"] follows.
set.ts guards the equivalent traversal loop, but unset.ts was not updated to match.
What browsers are you seeing the problem on?
All (Node.js repro confirmed)
Code of Conduct
Version Number
7.80.0
Steps to reproduce
The
unset()utility insrc/utils/unset.tstraverses path segments usingbaseGet()without filtering out prototype-pollution keywords (__proto__,constructor,prototype).set.tsalready guards against this with:But
unset.ts(and its internalbaseGethelper) have no equivalent protection. As a result, a path like"__proto__.foo"causesbaseGetto walk from the target object intoObject.prototype, and the subsequentdelete childObject[key]then deletes a property fromObject.prototypeitself.Expected behaviour
unset()should ignore (no-op) any path that contains__proto__,constructor, orprototype, consistent with the protection already present inset.ts.Root cause
unset.ts:baseGettraverses path segments unconditionally:stringToPath("__proto__.polluted")→["__proto__", "polluted"].baseGetthen dereferencesobject["__proto__"]→Object.prototype.delete Object.prototype["polluted"]follows.set.tsguards the equivalent traversal loop, butunset.tswas not updated to match.What browsers are you seeing the problem on?
All (Node.js repro confirmed)
Code of Conduct