Blog / A03:2021 Injection
A03:2021 · Injection

A config object that can rewrite your hash function's guts

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.

caller passes aconfig objectconfig merged viaan…an own __proto__or method key…prototype ormethod…hashing behaviorcontrolled by…ATTACKER INPUTIMPACTcode path executes
Attack path · caller passes a config object → config merged via an unrestricted property copy → an own __proto__ or method key is applied → prototype or method gets replaced → hashing behavior controlled by the attacker

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

Vulnerable
function extend(target, config) {
  for (const key in config) {
    if (config.hasOwnProperty(key)) {
      target[key] = config[key];   // no key filtering
    }
  }
  return target;
}
Hardened
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;
}
How the pipeline adjudicated itPROVEN
ABCDEFGH

Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

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