API request decompression limits: bound compressed and expanded data
Compressed requests reduce transfer size, but a small encoded body can expand dramatically after decompression. A server should bound not only incoming bytes, but also decoded output and processing time. If an API does not need compressed requests, disable decoding; if it does, use a streaming decoder that counts output as it is produced.
Compressed requests reduce transfer size, but a small encoded body can expand dramatically after decompression. A server should bound not only incoming bytes, but also decoded output and processing time. If an API does not need compressed requests, disable decoding; if it does, use a streaming decoder that counts output as it is produced.
Why a compressed-size limit is not enough
HTTP Content-Encoding: gzip identifies a content coding applied to the request representation. The recipient decodes it before processing the media type. Therefore, even if a proxy allows only 1 MiB of transferred data, the decoded content can occupy far more memory.
At minimum, distinguish these limits:
| Resource | Purpose | What to measure |
|---|---|---|
| Transferred body bytes | Protect network, proxy buffers, and ingress bandwidth | Actual bytes in the encoded request body |
| Decompressed output bytes | Protect memory, parsers, and temporary files | Cumulative bytes produced while decoding |
| Processing time and concurrent decoders | Protect CPU and worker capacity | Decode deadline, request timeout, and concurrent work cap |
| Nested data structures | Prevent excessive recursive parsing and archive extraction | Depth, entry count, per-entry size, and total expanded size |
The last item may concern a different feature from HTTP gzip decoding, such as extracting a ZIP archive. Apply separate limits in each decoder and archive extractor. Do not assume one “compression ratio” prevents every attack or resource exhaustion.
Decode requests safely in the request path
**Accept compression only on endpoints that need it.** A route that does not consume content codings can reject compressed requests. Avoid automatically decoding every request in global middleware before authentication; attach a decoder only to routes that need one.
**Enforce the transfer cap before decompression.** Limit received body bytes at the CDN, proxy, or server ingress so a large compressed file cannot consume network or buffer resources.
**Enforce the output cap during decompression.** Count bytes emitted by the decompression stream and stop the stream as soon as the cap is reached. Then fail the request. Checking size only after building the full result in memory is too late.
**Bound time and concurrency too.** Set request timeouts and a maximum number of simultaneous decodes, and confirm cancellation also stops decompression work. A compression ratio can be a monitoring signal, but it varies by input and is partly attacker-controlled; it cannot replace an absolute output cap.
**Use distinct, safe errors.** Under RFC 9110, an unsupported `Content-Encoding` should be reported as 415. A body over a configured size policy can receive an appropriate 413. Do not expose internal decoder errors or resource details.
Do not assume one parser option enforces both “compressed input size” and “decompressed output size.” Check the middleware documentation and version to learn which bytes its limit counts. If necessary, build a bounded output stream or reject compressed input.
Express body-parser and the 2026 security advisory
Express body-parser inflates supported compressed request bodies when its inflate option is true, which is also the default. The limit option caps the parser body, but check the documentation and implementation version to determine how it applies before and after inflation. Do not infer that this option also defines a separate absolute expanded-output limit, CPU-time budget, or concurrency policy.
An Express security advisory published on October 28, 2026 describes a denial-of-service vulnerability in affected body-parser versions with request decompression enabled: a malicious request could terminate the process. The advisory lists body-parser 2.0.0–2.3.0 as fixed in 2.4.0, and 1.20.8 and earlier as fixed in 1.20.9. If compressed requests are needed, use at least the fixed version. If they are unnecessary, inflate: false rejects compressed bodies. That workaround does not replace upgrading when compressed input is required. These versions were checked against the advisory on November 20, 2026; verify the official advisory again before deployment.
Verification and operations
In an isolated test environment, check ordinary uncompressed requests, valid compressed requests, synthetic data with a large output from a small input, malformed compressed streams, output just over the cap, timeouts, and client cancellation. Do not send attack archives to production. No request or server configuration was run or tested here.
Does the proxy cap count the actual transferred bytes?
Does the decoder count cumulative output before buffering the complete result?
Are CPU time, concurrent decoders, archive depth, and entry count bounded?
Is decoding disabled on routes that do not need compressed input?
Are middleware versions and security advisories checked before deployment?
Do logs and metrics show rejection reason and layer without exposing request bodies?
References
[RFC 9110 §8.4: Content-Encoding](https://www.rfc-editor.org/rfc/rfc9110.html#section-8.4)
[Express body-parser: inflate and size errors](https://expressjs.com/en/resources/middleware/body-parser.html)
[Express security advisory: CVE-2026-111181](https://expressjs.com/en/blog/2026-10-28-cve-2026-111181/)
[OWASP Web Security Testing Guide: ZIP bombs](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/10-Business_Logic/09-Upload_of_Malicious_Files/)