Skip to main content

CVE-2026-34831 — Rack has Content-Length mismatch in rack

MEDIUM

Rack has Content-Length mismatch in Rack::Files error responses

Published April 2, 2026Updated September 10, 2026Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (0.26%). Schedule for your next planned update.

Does your project use an affected rack version?

Paste your Gemfile.lock to check it for CVE-2026-34831 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my Gemfile.lock

Summary

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:

def fail(status, body, headers = {})
  body += "\n"
  [
    status,
    {
      "content-type" => "text/plain",
      "content-length" => body.size.to_s,
      "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.

Advisory Timeline

  • First published April 2, 2026 (238 days ago).
  • Last revised September 10, 2026 — 160 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Bundler
Update rack to 2.2.23 or later
gem install rack -v 2.2.23
Bundler
Update rack to 3.2.6 or later
gem install rack -v 3.2.6
Bundler
Update rack to 3.1.21 or later
gem install rack -v 3.1.21

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (3)

Affects 1 ecosystem: RubyGems (1).

PackageFixed In
rack RubyGems · Affected: 0.1.0, 0.2.0, 0.3.0, 0.4.0 (+119 more)2.2.23
rack RubyGems · Affected: 3.2.0, 3.2.1, 3.2.2, 3.2.3 (+2 more)3.2.6
rack RubyGems · Affected: 3.0.0, 3.0.0.beta1, 3.0.0.rc1, 3.0.1 (+42 more)3.1.21

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 4.8 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
High
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality
Low
Integrity
Low
Availability
None

CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N

Frequently Asked Questions

What is CVE-2026-34831?
Rack has Content-Length mismatch in Rack::Files error responses. This vulnerability has been assigned a severity rating of MEDIUM (CVSS score: 4.8/10).
How do I check if my project is affected by CVE-2026-34831?
CVE-2026-34831 affects rack. It has a 0.3% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2026-34831 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
4.8

Exploitation requires specific conditions, or the impact is limited.

EPSS Score (30-day exploit probability)
0.26%
EPSS percentile: 10.9

This is a below-median EPSS score — only 10.9% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.

Also Known As

GHSA-q2ww-5357-x388

Related CVEs

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my Gemfile.lock