CVE-2026-34831: Rack: Content-Length mismatch in Rack::Files error responses

Published Apr 2, 2026
·
Updated

Summary

Rack::Files#fail sets the Content-Length response header using String#size instead of String#bytesize. When the response body contains multibyte UTF-8 characters, the declared Content-Length is smaller than the number of bytes actually sent on the wire.

Because Rack::Files reflects the requested path in 404 responses, an attacker can trigger this mismatch by requesting a non-existent path containing percent-encoded UTF-8 characters.

This results in incorrect HTTP response framing and may cause response desynchronization in deployments that rely on the incorrect Content-Length value.

Details

Rack::Files#fail constructs error responses using logic equivalent to:

ruby def fail(status, body, headers = {}) body += "\n" [ status, { "content-type" => "text/plain", "content-length" => body.size.tos, "x-cascade" => "pass" }.merge!(headers), [body] ] end

Here, body.size returns the number of characters, not the number of bytes. For multibyte UTF-8 strings, this produces an incorrect Content-Length value.

Rack::Files includes the decoded request path in 404 responses. A request containing percent-encoded UTF-8 path components therefore causes the response body to contain multibyte characters, while the Content-Length header still reflects character count rather than byte count.

As a result, the server can send more bytes than declared in the response headers.

This violates HTTP message framing requirements, which define Content-Length as the number of octets in the message body.

Impact

Applications using Rack::Files may emit incorrectly framed error responses when handling requests for non-existent paths containing multibyte characters.

In some deployment topologies, particularly with keep-alive connections and intermediaries that rely on Content-Length, this mismatch may lead to response parsing inconsistencies or response desynchronization. The practical exploitability depends on the behavior of downstream proxies, clients, and connection reuse.

Even where no secondary exploitation is possible, the response is malformed and may trigger protocol errors in strict components.

Mitigation

Update to a patched version of Rack that computes Content-Length using String#bytesize. Avoid exposing Rack::Files directly to untrusted traffic until a fix is available, if operationally feasible. Where possible, place Rack behind a proxy or server that normalizes or rejects malformed backend responses. Prefer closing backend connections on error paths if response framing anomalies are a concern.

Other sources

Rack is a modular Ruby web server interface. Prior to versions 2.2.23, 3.1.21, and 3.2.6, Rack::Files#fail sets the Content-Length response header using String#size instead of String#bytesize. When the response body contains multibyte UTF-8 characters, the declared Content-Length is smaller than the number of bytes actually sent on the wire. Because Rack::Files reflects the requested path in 404 responses, an attacker can trigger this mismatch by requesting a non-existent path containing percent-encoded UTF-8 characters. This results in incorrect HTTP response framing and may cause response desynchronization in deployments that rely on the incorrect Content-Length value. 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::Files to a version that resolves this vulnerability.

    Fixed in 2.2.23
  5. Upgrade

    Upgrade Rack::Files to a version that resolves this vulnerability.

    Fixed in 3.1.21
  6. Upgrade

    Upgrade Rack::Files to a version that resolves this vulnerability.

    Fixed in 3.2.6
  7. Configuration

    Ensure Rack::Files#fail sets the Content-Length header using String#bytesize (not String#size/String#size alias of character count) so multibyte UTF-8 error responses are correctly framed.

    Rack::Files Content-Length calculation = String#bytesize
  8. Compensating control

    Avoid exposing Rack::Files directly to untrusted traffic until a fix is available, if operationally feasible.

  9. Compensating control

    Where possible, place Rack behind a proxy or server that normalizes or rejects malformed backend responses.

Event History

Apr 2, 2026
CVE Published
via MITRE·04:43 PM
Data Sourced
via MITRE·04:43 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:16 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·05:16 PM
Affected Software
Advisory Published
via GitHub·08:36 PM
Data Sourced
via GitHub·08:36 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