Rack: Multipart parser searches the load path for every unknown part `charset`, allowing denial of service via CPU exhaustion
Published 3 Dec 2026 · Updated 4 Dec 2026
Affected packages
- Affected
- >=3.0.0 <3.1.24
- Fixed in
- 3.1.24
bundle update --conservative rack # Gemfile: '>= 3.1.24'- Affected
- >=3.2.0 <3.2.9
- Fixed in
- 3.2.9
bundle update --conservative rack # Gemfile: '>= 3.2.9'Which rack does your project really install?
Works for private projects: the file is read in memory to run the scan and then dropped. Also reads Gemfile.
Public repo?
Look after several Rails or Ruby apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie
Details
Summary
Rack::Multipart::Parser#tag_multipart_encoding calls Encoding.find once for every charset parameter in the Content-Type header of a multipart part. When the name is not a known encoding, Ruby's Encoding.find attempts to load an encoding library of that name, which searches every directory on $LOAD_PATH before failing. Rack rescues the resulting ArgumentError and falls back to binary, does not remember the failure, and does not limit the number of charset parameters a part may carry. An attacker can send a part whose Content-Type contains thousands of unknown charset parameters, and each one costs a full load-path search. This results in a denial of service condition for applications that accept multipart requests.
Details
The relevant code is:
if k == "charset" encoding = find_encoding(v) end def find_encoding(enc) Encoding.find enc rescue ArgumentError Encoding::BINARY end
For a name absent from Encoding.name_list, Encoding.find calls load_encoding in encoding.c, which requires enc/<name>.so through Ruby's internal loader. The lookup is not cached, is not visible to RubyGems or Bootsnap, and costs roughly 3–5 µs per $LOAD_PATH entry: about 30 µs on a bare Ruby, about 500 µs in a Bundler application with 200 load-path entries on macOS, and about 2.5 ms per lookup measured on Linux with 167 entries.
Each ;charset=x costs 10 bytes. Existing limits do not bound the attack: the part limit (RACK_MULTIPART_PART_LIMIT, 4096) counts parts, not parameters; the 64 KiB part header limit is only enforced when a header spans two reads, so a single header of up to the 1 MiB buffer size is accepted; and part headers count toward the 16 MiB retained-size limit, which allows about 1.6 million lookups per request. A single part with 4000 unknown charset parameters (64 KB) takes about 1.7 s to parse in a mid-sized Bundler application; a 1 MB request with 16 such parts takes 27–40 s. Through Puma in a default Rails application, four concurrent 1 MB requests delayed an unrelated health-check endpoint by over 10 s. The result is binary regardless of how many unknown names appear, so none of the lookups beyond the first are useful.
Rack 3.0, 3.1 and 3.2 are affected. Rack 2.2 is not affected by the denial of service: it does not rescue the ArgumentError, so the first unknown charset aborts parsing after a single lookup.
Impact
Any application that parses multipart bodies through Rack::Request#POST or #params is affected in its default configuration. In a default Rails application a POST to any path, including one with no route, is sufficient, because Rack::MethodOverride parses the body before routing. An unauthenticated attacker can occupy a worker thread for tens of seconds with a request under 1 MB, and for minutes with a larger one; concurrent requests exhaust the thread pool. The cost grows with the number of gems in the application's bundle. No authentication, malformed HTTP, or unusual configuration is required.
Mitigation
- Update to a patched version of Rack, in which
Encoding.findis only called for names present inEncoding.name_list, so unknowncharsetvalues are mapped to binary without searching the load path. - At a reverse proxy, limit the size of multipart requests and reject requests whose part headers contain many repeated
charsetparameters.
Is GHSA-58mf-c3jj-277p in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected rack, and gives you the command that fixes it.
More advisories for rack
- MediumCVE-2026-142591Rack: `Rack::QueryParser` separator pattern allocates ~48 bytes per space after `&`, allowing denial of service via memory amplification · 3 Dec 2026
- MediumCVE-2026-142593Rack: `Rack::Directory` lists directories outside the root when `..` follows a symbolic link · 3 Dec 2026
- LowCVE-2026-142594Rack: `Rack::Multipart` extracts the boundary by substring match rather than parameter parsing, allowing parser differentials and WAF bypass · 3 Dec 2026
- MediumCVE-2026-142590Rack: `Rack::Multipart::Parser` preserves CRLF from multipart part headers in parsed parameter names (incomplete fix for CVE-2026-26962) · 2 Dec 2026
- HighCVE-2026-125111Rack: Multipart parsing allows DoS via unbounded scan buffer growth · 10 Nov 2026
- LowCVE-2026-125108Rack: Multipart boundary ambiguity guard in Rack::Multipart::Parser can be bypassed with a quoted boundary value, allowing WAF bypass · 10 Nov 2026
References
- Linkgithub.com/rack/rack/security/advisories/GHSA-58mf-c3jj-277p
- Advisorynvd.nist.gov/vuln/detail/CVE-2026-142592
- Linkgithub.com/rack/rack/commit/7c16c669fe2040ac395cf05a242f80527ddab16b
- Linkgithub.com/rack/rack/commit/8ae2ea868a13eec2cfa7065a1ea8b527c567fad9
- Packagegithub.com/rack/rack
- Linkgithub.com/rack/rack/releases/tag/v3.1.24
- Linkgithub.com/rack/rack/releases/tag/v3.2.9
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.