Blog / A04:2021 Insecure Design
A04:2021 · Insecure Design

A nested credential can knock your renderer over

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.

parse credentialJSONrecurse overnested fieldsno depth limitcall stackoverflowsATTACKER INPUTIMPACTresource exhausted
Attack path · parse credential JSON → recurse over nested fields → no depth limit → call stack overflows

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

Vulnerable
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)
  }
}
Hardened
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)
  }
}
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 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