Multipart `:length` limit not charged for part and header framing in Plug.Parsers.MULTIPART
Affected packages
| Package | Affected → Fixed | |
|---|---|---|
| elixir-plugplug |
≥ e06acbd3d381931f23cbde7d763136c9ccb091ac (no fix yet)→ 3d3fb645323643935c6c94863c1b3edfd62e2828, 497913f2a6d744d693e98e96c5b9c6d88c265695 |
3d3fb645323643935c6c94863c1b3edfd62e2828, 497913f2a6d744d693e98e96c5b9c6d88c265695 |
| Hexplug |
≥ 1.13.0, < 1.20.4→ 1.20.4 |
1.20.4 |
Original description The description as published by the source.
Summary
Allocation of Resources Without Limits or Throttling vulnerability in Plug.Parsers.MULTIPART in elixir-plug plug allows an unauthenticated remote attacker to exhaust memory via a multipart request body built from parts without headers, or from header lines without a name and a value. The parser charges the :length limit only with the name and value bytes of each part header and the bytes of each part body. The part delimiter, the header separator, and the line endings cost nothing.
In lib/plug/parsers/multipart.ex, Plug.Parsers.MULTIPART.parse_multipart_headers/5 keeps an entry for every part without a content-disposition header, together with its header list, until the whole body is read. A request made of such parts does not reach the limit at any size, and the parser process holds a multiple of the request size in memory until parsing completes. Any endpoint that uses Plug.Parsers with the :multipart parser is reachable.
This issue affects plug: from 1.13.0 before 1.20.4.
Details
1. What the limit counts. Plug.Parsers.MULTIPART.parse_multipart_headers/5 subtracts the result of headers_size/1 from the remaining :length limit. headers_size/1 sums byte_size(key) + byte_size(value) for each header. The part delimiter, the colon and CRLF of each header line, and the blank line that ends the header block are not counted.
2. Inputs that cost zero. A part without headers has an empty header list, so its charge is 0. A header line…
Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory
References
- advisory github.com
- advisory github.com
- advisory nvd.nist.gov
- package hex.pm
- package github.com
- patch github.com
- patch github.com
- web cna.erlef.org
- web osv.dev
- web github.com
- web github.com
- web repo.hex.pm