Preprocessing a credential means walking its fields recursively. With no depth cap, a deeply nested document runs the call stack out and stops the flow cold.
What goes wrong
The preprocessing step that tidies up a credential before display is also the step an attacker can use to kill the request. Before a credential gets rendered or stored, its fields get a pass: localize a label here, normalize a value there. That pass walks the whole object tree, and it walks it with recursion.
The object tree is attacker-supplied. Nothing checks how deep it goes. A document nested deeply enough sends the traversal past the stack limit and the preprocessing step throws an error it cannot recover from. Whatever was serving that request goes with it. The attacker spends almost nothing: the payload is small and compresses well on the wire.
The pattern
function localizeFields(obj, lang) {
for (const key of keys(obj)) {
const value = obj[key]
if (isObject(value)) localizeFields(value, lang) // no depth guard
else obj[key] = pickLanguage(value, lang)
}
}function localizeFields(obj, lang, depth = 0) {
if (depth > MAX_DEPTH) throw new BadInput("credential nested too deeply")
for (const key of keys(obj)) {
const value = obj[key]
if (isObject(value)) localizeFields(value, lang, depth + 1)
else obj[key] = pickLanguage(value, lang)
}
}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 untrusted documents reach this code before anyone has validated their shape, you have handed callers a switch that stops your processing on demand. It will not leak data, but it will interrupt whatever pipeline depends on it, and quietly enough that the first sign is a spike in restarts.
Validate structure before you traverse it. A schema check with a bounded depth turns this from an incident into a rejected request.
Check your own code
- Check whether untrusted documents are structurally validated before any recursive pass touches them.
- Add a depth bound to every recursive traversal of externally supplied objects.
- Confirm a traversal failure becomes a 4xx, not an unhandled crash.
- Fuzz the preprocessing entry with pathologically nested input.