Skip to main content
Menu
Advisories

MultipartForm enforces no limit on the number of parts, allowing memory and file-descriptor exhaustion

GHSA-48P4-XJ33-4FW4Published Updated GitHub

Description

actix-multipart's MultipartForm extractor bounds only the number of payload bytes it reads (total_limit, default 50 MiB, and memory_limit, default 2 MiB). It never bounds the number of parts in a request, and part framing (the boundary line, the Content-Disposition header and the CRLFs) is not counted against either limit. An unauthenticated client can stream an unlimited number of zero-byte parts, each about 55 bytes on the wire and costing 0 against both limits, to exhaust server memory or file descriptors under default configuration.

Details

For an in-memory field (Vec<Bytes>, the documented multi-value pattern), Bytes::read_field allocates BytesMut::with_capacity(131072) for every part and then calls .freeze(); an empty part keeps that 128 KiB allocation alive inside the collected Vec. memory_limit counts only bytes actually written, so it gives no protection here: each empty part pins a fresh buffer. For a Vec<TempFile> field, every part opens a temporary file whose descriptor is held for the whole request, so the part count maps one-to-one onto open descriptors. The driver loop while let Some(field) = multipart.try_next().await? has no part counter, and try_consume_limits runs only on real body chunks.

Proof of concept

A handler using the documented multi-file pattern, under default configuration:

#[derive(MultipartForm)]
struct Upload { files: Vec<Bytes> }

async fn upload(form: MultipartForm<Upload>) -> impl Responder { /* ... */ }

The request is 100,000 repetitions of one empty part followed by the closing boundary:

--poc
Content-Disposition: form-data; name="files"

--poc
   (repeated 100,000 times)
--poc--

Against actix-multipart 0.8.3 this 5.4 MB request drove the worker from 4.6 MB to 422 MB resident (about 4 KB per part, roughly 77x amplification), and the handler was reached, so total_limit and memory_limit never tripped. A larger body of the same shape scales linearly toward OOM. With the field changed to Vec<TempFile>, 3,000 empty parts (a 208 KB request) left 3,018 file descriptors open at once; on a host with the common ulimit -n of 1024 that starves the worker of descriptors for every connection.

Impact

A single unauthenticated request to any endpoint that uses the documented MultipartForm multi-value or multi-file pattern can exhaust the worker's memory or file descriptors and take it down. No authentication and no non-default options are required.

Affected versions

References

GitHub · actix/actix-web