A hashing library merged caller-supplied config with an unrestricted property copy. Slip in a __proto__ key and you can move the object's prototype, or replace its finalize step outright.
What goes wrong
Initialization took a config object and copied its properties onto the new instance with a generic mixin. The mixin walks the config's own keys and assigns each one, with no allow-list of what a config is permitted to set.
Two things go wrong. An own property named __proto__ can change the prototype of the object being built, poisoning the chain other code reads from. Worse for a hashing primitive, a property named after a real method (the finalize or reset step) overwrites that method with attacker-chosen behavior. The object still looks like a hasher and still returns a digest. The digest is now whatever the attacker decided it should be.
Anywhere untrusted data reaches a dynamic property copy, you need a guard. Skip __proto__, constructor, and prototype, and copy only the fields the config is actually allowed to carry.
The pattern
function extend(target, config) {
for (const key in config) {
if (config.hasOwnProperty(key)) {
target[key] = config[key]; // no key filtering
}
}
return target;
}const BLOCKED = new Set(["__proto__", "constructor", "prototype"]);
function extend(target, config) {
for (const key of Object.keys(config)) {
if (BLOCKED.has(key)) continue;
if (!ALLOWED_FIELDS.has(key)) continue; // allow-list wins
target[key] = config[key];
}
return target;
}Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
Why it matters to you
If any of your hashing config can be reached by request data or a config file, an attacker who gets to it can quietly neutralize the hash. Password checks that always pass. Integrity checks that never fail. The output keeps the right shape, which is exactly what makes it hard to notice.
Check your own code
- Find every generic merge, extend, or mixin that copies untrusted keys onto an object.
- Reject __proto__, constructor, and prototype keys, or use a null-prototype target.
- Prefer an explicit allow-list of config fields over copying whatever arrives.