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
function handleUpload(bytes) {
const tmp = createTempFile('.zip')
// no check on bytes.length
writeAllBytes(tmp, bytes)
const archive = openArchive(tmp)
return archive
}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
}
}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
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
- Set a maximum payload size before writing anything to disk.
- Delete temp files in a finally block so failures do not leak them.
- Bound how many concurrent uploads can buffer at once.
- Give the temp directory a quota separate from critical storage.