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

Attacker input goes straight to a temp file, no cap

Writing a caller-supplied byte array to a temporary file with no size limit lets a few concurrent requests fill the disk and take the service down with it.

caller submitsraw bytescode writes themto a temp fileno size limitappliedconcurrent writesexhaust the diskATTACKER INPUTIMPACTresource exhausted
Attack path · caller submits raw bytes → code writes them to a temp file → no size limit applied → concurrent writes exhaust the disk

Writing a caller-supplied byte array to a temporary file with no size limit lets a few concurrent requests fill the disk and take the service down with it.

What goes wrong

The decode path takes the full byte array from the caller and writes it to a temporary archive file. Nothing limits how many bytes it will accept. On its own, one oversized request just wastes some space.

The trouble shows up under load. Several large requests in flight at once, each writing its own temp file, and the volume fills. Once the disk is full, every write starts failing, including the ones from other requests that had nothing to do with the attack. The resource that looked most abundant is shared, and it is the easiest one to exhaust because nobody was watching it.

The pattern

Vulnerable
function handleUpload(bytes) {
  const tmp = createTempFile('.zip')
  // no check on bytes.length
  writeAllBytes(tmp, bytes)
  const archive = openArchive(tmp)
  return archive
}
Hardened
function handleUpload(bytes) {
  if (bytes.length > MAX_UPLOAD) throw new Error('payload too large')
  const tmp = createTempFile('.zip')
  try {
    writeAllBytes(tmp, bytes)
    return openArchive(tmp)
  } finally {
    deleteQuietly(tmp)      // never leak the temp file
  }
}
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

Disk exhaustion is the resource attack people forget, because heap and CPU get all the attention. It is also nastier: a full disk drags down neighbors that had nothing to do with the request, and recovery often needs a human. If your service accepts uploads and buffers them to disk, an unauthenticated flood is all it takes.

Cap the input at the edge, clean up temp files in a finally block, and give the temp directory its own quota so a spike cannot starve the rest of the box.

Check your own code