RequestSizeLimit middleware fails to enforce limits on chunked requests
0 reputation · 25 Oct 2021, 18:16 UTC
0 reputation · 25 Oct 2021, 18:16 UTC
When the RequestSizeLimit middleware is configured, Traefik should reject requests whose body size exceeds the specified limit with an HTTP 413 response. However, the middleware’s documentation does not mention handling of Transfer‑Encoding: chunked streams.
In both Traefik v2.x and v3.x, a POST request that uses chunked transfer encoding and whose cumulative payload exceeds the configured limit is forwarded to the backend. No 413 error is returned, and Traefik logs do not indicate that the size check was performed.
The RequestSizeLimit middleware does not enforce size limits on requests using Transfer-Encoding: chunked. It only checks the Content-Length header, which is absent in chunked encoding. Traefik streams chunked requests to the backend without buffering or counting bytes, so no HTTP 413 is returned and no custom error page is triggered.
req.TransferEncoding contains "chunked" and no Content-Length is present (source: github.com/traefik/traefik/v3/pkg/middlewares/requestsizelimit).A malicious client can send many small chunks that cumulatively exceed the configured limit. Since Traefik passes them through, the backend consumes memory and CPU processing the oversized payload. The backend must implement its own chunked-body limits.
curl -v -H "Transfer-Encoding: chunked" --data-binary @largefile.bin http://traefik-host/
Observe that Traefik forwards the request and the backend responds (no 413 from Traefik).
--log.level=DEBUG. The middleware logs "Request body size exceeds limit" only for Content-Length requests, not for chunked.http.MaxBytesReader, Spring Boot server.max-http-request-header-size, Node.js body-parser limits).Content-Length instead.What exact Traefik version are you running? (Run traefik version.) If you are on a v3.0+ release with experimental features enabled, the behavior could differ. Otherwise, the above applies to all current stable versions.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.