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

You decompressed the bomb, then did it again

Inflating attacker-controlled bytes with no size cap is a classic bomb. Doing it a second time in a side effect just doubles what the attacker gets for one payload.

caller sendscompressed bytescode inflateswith no capside effectinflates againsmall payloaddoubles into…ATTACKER INPUTIMPACTresource exhausted
Attack path · caller sends compressed bytes → code inflates with no cap → side effect inflates again → small payload doubles into a blowup

Inflating attacker-controlled bytes with no size cap is a classic bomb. Doing it a second time in a side effect just doubles what the attacker gets for one payload.

What goes wrong

The decode inflates the caller's compressed bytes with no limit on the expanded size. A small, highly compressed input balloons into whatever the attacker chose. That alone is a denial of service.

This version does it twice. A side-effect block re-inflates the same input, presumably to read one property of the result, and pays the full decompression cost again. So the attacker's single small payload buys two large allocations. Even a modest bomb becomes twice the problem, and the second pass is pure waste.

The pattern

Vulnerable
function inflate(bytes) {
  const out = zlibInflate(bytes)     // no output cap
  // side effect re-inflates the same input
  const again = zlibInflate(bytes)
  logSize(again.length)
  return out
}
Hardened
function inflate(bytes) {
  const out = zlibInflateBounded(bytes, MAX_OUTPUT)  // caps output
  logSize(out.length)                // reuse it, do not redo it
  return out
}
How the pipeline adjudicated itHELD
ABCDEFGH

Grounding and reachability were confirmed. The exploit-path gate would not conclude without the calling code, so the finding was held and an evidence request was raised instead of being reported as fact.

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

Why it matters to you

Decompression hides inside so many formats that people stop seeing it: an archive, a content encoding, a token, a saved document. Wherever attacker bytes get inflated, a bound on the output is the difference between a rejected request and a dead process. The double-inflate is a reminder to look at what you do with the result, because a careless second pass can erase whatever headroom you had.

Bound the output of every inflate, and compute anything you need from the result once. Re-running an expensive decode to fetch one field is a cost you can delete.

Check your own code