CVE-2026-34230: Rack: Quadratic complexity in Rack::Utils.select_best_encoding via wildcard Accept-Encoding header

Published Apr 2, 2026
·
Updated

Summary

Rack::Utils.selectbestencoding processes Accept-Encoding values with quadratic time complexity when the header contains many wildcard () entries. Because this method is used by Rack::Deflater to choose a response encoding, an unauthenticated attacker can send a single request with a crafted Accept-Encoding header and cause disproportionate CPU consumption on the compression middleware path.

This results in a denial of service condition for applications using Rack::Deflater.

Details

Rack::Utils.selectbestencoding expands parsed Accept-Encoding values into a list of candidate encodings. When an entry is , the method computes the set of concrete encodings by subtracting the encodings already present in the request:

ruby if m == "" (availableencodings - acceptencoding.map(&:first)).each do |m2| expandedacceptencoding << [m2, q, preference] end else expandedacceptencoding << [m, q, preference] end

Because acceptencoding.map(&:first) is evaluated inside the loop, it is recomputed for each wildcard entry. If the request contains N wildcard entries, this produces repeated scans over the full parsed header and causes quadratic behavior.

After expansion, the method also performs additional work over expandedacceptencoding, including per-entry deletion, which further increases the cost for large inputs.

Rack::Deflater invokes this method for each request when the middleware is enabled:

ruby Utils.selectbestencoding(ENCODINGS, Utils.parseencodings(acceptencoding))

As a result, a client can trigger this expensive code path simply by sending a large Accept-Encoding header containing many repeated wildcard values.

For example, a request with an approximately 8 KB Accept-Encoding header containing about 1,000 ;q=0.5 entries can cause roughly 170 ms of CPU time in a single request on the Rack::Deflater path, compared to a negligible baseline for a normal header.

This issue is distinct from CVE-2024-26146. That issue concerned regular expression denial of service during Accept header parsing, whereas this issue arises later during encoding selection after the header has already been parsed.

Impact

Any Rack application using Rack::Deflater may be affected.

An unauthenticated attacker can send requests with crafted Accept-Encoding headers to trigger excessive CPU usage in the encoding selection logic. Repeated requests can consume worker time disproportionately and reduce application availability.

The attack does not require invalid HTTP syntax or large payload bodies. A single header-sized request is sufficient to reach the vulnerable code path.

Mitigation

Update to a patched version of Rack in which encoding selection does not repeatedly rescan the parsed header for wildcard entries. Avoid enabling Rack::Deflater on untrusted traffic. Apply request filtering or header size / format restrictions at the reverse proxy or application boundary to limit abusive Accept-Encoding values.

Other sources

Rack is a modular Ruby web server interface. Prior to versions 2.2.23, 3.1.21, and 3.2.6, Rack::Utils.selectbestencoding processes Accept-Encoding values with quadratic time complexity when the header contains many wildcard () entries. Because this method is used by Rack::Deflater to choose a response encoding, an unauthenticated attacker can send a single request with a crafted Accept-Encoding header and cause disproportionate CPU consumption on the compression middleware path. This results in a denial of service condition for applications using Rack::Deflater. This issue has been patched in versions 2.2.23, 3.1.21, and 3.2.6.

MITRE

Affected Software

6 affected componentsFixes available
rubygems/rack>=3.2.0<3.2.6
3.2.6
rubygems/rack>=3.0.0.beta1<3.1.21
3.1.21
rubygems/rack<2.2.23
2.2.23
Rack Rack Ruby<2.2.23
Rack Rack Ruby>=3.0.0<3.1.21
Rack Rack Ruby>=3.2.0<3.2.6

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade rubygems/rack to a version that resolves this vulnerability.

    Fixed in 3.2.6
  2. Upgrade

    Upgrade rubygems/rack to a version that resolves this vulnerability.

    Fixed in 3.1.21
  3. Upgrade

    Upgrade rubygems/rack to a version that resolves this vulnerability.

    Fixed in 2.2.23
  4. Upgrade

    Upgrade Rack to a version that resolves this vulnerability.

    Fixed in 2.2.23
  5. Upgrade

    Upgrade Rack to a version that resolves this vulnerability.

    Fixed in 3.1.21
  6. Upgrade

    Upgrade Rack to a version that resolves this vulnerability.

    Fixed in 3.2.6
  7. Configuration

    Apply request filtering or header size/format restrictions at the reverse proxy or application boundary to limit abusive Accept-Encoding values (e.g., cap Accept-Encoding header size / number of wildcard entries).

    Reverse proxy / application boundary Request filtering for Accept-Encoding header = Limit/validate Accept-Encoding header size and format to prevent many repeated wildcard (*) entries
  8. Configuration

    Avoid enabling `Rack::Deflater` on untrusted traffic; ensure the compression middleware is not applied to requests that can be controlled by unauthenticated attackers.

    Rack::Deflater (Rack compression middleware) Rack::Deflater enablement on untrusted traffic = Do not enable on untrusted traffic

Event History

Apr 2, 2026
CVE Published
via MITRE·04:41 PM
Data Sourced
via MITRE·04:41 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:16 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:16 PM
Affected Software
Advisory Published
via GitHub·08:32 PM
Data Sourced
via GitHub·08:32 PM
DescriptionSeverityWeaknessAffected Software

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203