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

A tiny encoded string can flatten your service

Decode attacker input, then inflate it with no ceiling on the output, and anyone with a network connection has a one-line way to exhaust your memory.

accept encodedstringdecode to bytesinflate with nosize capheap and eventloop exhaustedATTACKER INPUTIMPACTresource exhausted
Attack path · accept encoded string → decode to bytes → inflate with no size cap → heap and event loop exhausted

Decode attacker input, then inflate it with no ceiling on the output, and anyone with a network connection has a one-line way to exhaust your memory.

What goes wrong

A few kilobytes can turn into a few gigabytes, and this function allocates every one of them without blinking. The decode path takes a caller's string, turns it back into bytes, then runs those bytes through decompression. Nowhere does it ask how large the result is allowed to get.

Because the function is exported and reachable from the network with no auth, the whole cost lands on the defender. On a single-threaded runtime the inflate call also blocks the event loop, so one request can stall every other request in flight. You do not need a botnet. One client and a loop will do.

The pattern

Vulnerable
function decode(input) {
  const raw = fromTextEncoding(input)   // untrusted, off the wire
  const bytes = inflate(raw)            // no cap on output size
  return parse(bytes)                   // whatever came out
}
// 3 KB in can become 900 MB out
Hardened
function decode(input) {
  const raw = fromTextEncoding(input)
  if (raw.length > MAX_COMPRESSED) throw new Error("input too large")
  // inflate incrementally, abort past the ceiling
  const bytes = inflateWithLimit(raw, MAX_DECOMPRESSED)
  return parse(bytes)
}
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

Availability bugs get filed under "later" until the day one goes off in production. A decompression bomb is cheap to send and hard to tell apart from a legitimate large payload after the fact. If this decoder sits on a hot path, a single client can degrade or drop service for everyone.

The fix is boring, and that is the point. Put a ceiling on the compressed input and a separate ceiling on the decompressed output, then decompress in chunks so you can bail the moment either is crossed.

Check your own code