# GHSA-58MF-C3JJ-277P: Summary Rack::Multipart::Parser#tag\_multipart\_encoding calls Encoding.find once for every charset parameter in the Content-Type header of a multipart part

- Database: GitHub
- Severity: CVSS 7.5 (High)
- Published: 2026-11-20
- Modified: 2026-12-02

## Tracked as

- [CVE-2026-142592](https://cve.now/CVE-2026-142592.md): Rack is a modular Ruby web server interface

## Affected versions

- rack (RubyGems): from 3.0, fixed in 3.1.24
- rack (RubyGems): from 3.2, fixed in 3.2.9

## Description

## 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:

```ruby
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.find` is only called for names present in `Encoding.name_list`, so unknown `charset` values 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 `charset` parameters.

## References

- https://github.com/rack/rack/security/advisories/GHSA-58mf-c3jj-277p

Page: https://cve.now/GHSA-58MF-C3JJ-277P

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
