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
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");
}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)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
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
- Find object lookups keyed by external input that test only truthiness.
- Replace them with Object.hasOwn checks or a Map with has().
- Confirm resolvers reject reserved names such as __proto__, constructor, and toString.