Blog / A03:2021 Injection
A03:2021 · Injection

A document lookup that answers with inherited properties

A loader indexed a plain object by an arbitrary identifier and returned whatever was truthy. Names like toString resolve up the prototype chain and come back looking like real documents.

loader receivesan…identifier usedto index a…an inheritedproperty…unintended objector…downstreamprocessing…ATTACKER INPUTIMPACTcode path executes
Attack path · loader receives an arbitrary identifier → identifier used to index a plain object → an inherited property resolves and looks truthy → unintended object or function returned → downstream processing consumes it

A loader indexed a plain object by an arbitrary identifier and returned whatever was truthy. Names like toString resolve up the prototype chain and come back looking like real documents.

What goes wrong

The loader keeps known documents in a plain object and looks them up by identifier. It checks that the lookup returned something truthy, then treats that as a valid document. The check never asks whether the property actually belongs to the object.

A plain object inherits toString, constructor, and a handful of others from its prototype. Ask for one of those by name and the lookup returns the inherited function or object, which is truthy, so it passes. Downstream code that expected a document now gets a function or the constructor. Depending on what it does next, that is a validation bypass or a crash.

This one is low severity, and it should be treated that way. Nothing is being written and no prototype is being changed, only inherited properties read by accident. It is still worth fixing, because the fix is small and the failure is silent.

The pattern

Vulnerable
function loadDocument(id) {
  const doc = KNOWN_DOCS[id];   // inherited props resolve too
  if (doc) {
    return doc;                 // "toString" passes this check
  }
  throw new Error("not found");
}
Hardened
function loadDocument(id) {
  if (!Object.hasOwn(KNOWN_DOCS, id)) {
    throw new Error("not found");
  }
  return KNOWN_DOCS[id];
}
// or store documents in a Map and use map.has(id)
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

On its own this is a minor input-validation gap, not an emergency. The reason to close it is that JSON-LD and similar processors do real work on whatever they are handed, and feeding one an unexpected function or object is a cheap way to probe for a bigger bug. Own-property checks and Maps make the whole class disappear.

Check your own code