Ruby/rack/3.0.0.beta1
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
https://rubygems.org/gems/rack
MIT
15 Security Vulnerabilities
Rack has a Directory Traversal via Rack:Directory
Summary
Rack::Directory’s path check used a string prefix match on the expanded path. A request like /../root_example/ can escape the configured root if the target path starts with the root string, allowing directory listing outside the intended root.
Details
In directory.rb, File.expand_path(File.join(root, path_info)).start_with?(root) does not enforce a path boundary. If the server root is /var/www/root, a path like /var/www/root_backup passes the check because it shares the same prefix, so Rack::Directory will list that directory also.
Impact
Information disclosure via directory listing outside the configured root when Rack::Directory is exposed to untrusted clients and a directory shares the root prefix (e.g., public2, www_backup).
Mitigation
- Update to a patched version of Rack that correctly checks the root prefix.
- Don't name directories with the same prefix as one which is exposed via
Rack::Directory.
Stored XSS in Rack::Directory via javascript: filenames rendered into anchor href
Summary
Rack::Directory generates an HTML directory index where each file entry is rendered as a clickable link. If a file exists on disk whose basename begins with the javascript: scheme (e.g. javascript:alert(1)), the generated index includes an anchor whose href attribute is exactly javascript:alert(1). Clicking this entry executes arbitrary JavaScript in the context of the hosting application.
This results in a client-side XSS condition in directory listings generated by Rack::Directory.
Details
Rack::Directory renders directory entries using an HTML row template similar to:
<a href='%s'>%s</a>
The %s placeholder is populated directly with the file’s basename. If the basename begins with javascript:, the resulting HTML contains an executable JavaScript URL:
<a href='javascript:alert(1)'>javascript:alert(1)</a>
Because the value is inserted directly into the href attribute without scheme validation or normalization, browsers interpret it as a JavaScript URI. When a user clicks the link, the JavaScript executes in the origin of the Rack application.
Impact
If Rack::Directory is used to expose filesystem contents over HTTP, an attacker who can create or upload files within that directory may introduce a malicious filename beginning with javascript:.
When a user visits the directory listing and clicks the entry, arbitrary JavaScript executes in the application's origin. Exploitation requires user interaction (clicking the malicious entry).
Mitigation
- Update to a patched version of Rack in which
Rack::Directoryprefixes generated anchors with a relative path indicator (e.g../filename). - Avoid exposing user-controlled directories via
Rack::Directory. - Apply a strict Content Security Policy (CSP) to reduce impact of potential client-side execution issues.
- Where feasible, restrict or sanitize uploaded filenames to disallow dangerous URI scheme prefixes.
Denial of service via header parsing in Rack
There is a possible denial of service vulnerability in the Range header parsing component of Rack. This vulnerability has been assigned the CVE identifier CVE-2022-44570.
Versions Affected: >= 1.5.0 Not affected: None. Fixed Versions: 2.0.9.2, 2.1.4.2, 2.2.6.2, 3.0.4.1
Impact
Carefully crafted input can cause the Range header parsing component in Rack to take an unexpected amount of time, possibly resulting in a denial of service attack vector. Any applications that deal with Range requests (such as streaming applications, or applications that serve files) may be impacted.
Workarounds
There are no feasible workarounds for this issue.
Denial of Service Vulnerability in Rack Content-Disposition parsing
There is a denial of service vulnerability in the Content-Disposition parsing component of Rack. This vulnerability has been assigned the CVE identifier CVE-2022-44571.
Versions Affected: >= 2.0.0 Not affected: None. Fixed Versions: 2.0.9.2, 2.1.4.2, 2.2.6.1, 3.0.4.1
Impact
Carefully crafted input can cause Content-Disposition header parsing in Rack to take an unexpected amount of time, possibly resulting in a denial of service attack vector. This header is used typically used in multipart parsing. Any applications that parse multipart posts using Rack (virtually all Rails applications) are impacted.
Workarounds
There are no feasible workarounds for this issue.
Denial of service via multipart parsing in Rack
There is a denial of service vulnerability in the multipart parsing component of Rack. This vulnerability has been assigned the CVE identifier CVE-2022-44572.
Versions Affected: >= 2.0.0 Not affected: None. Fixed Versions: 2.0.9.2, 2.1.4.2, 2.2.6.1, 3.0.4.1
Impact
Carefully crafted input can cause RFC2183 multipart boundary parsing in Rack to take an unexpected amount of time, possibly resulting in a denial of service attack vector. Any applications that parse multipart posts using Rack (virtually all Rails applications) are impacted.
Workarounds
There are no feasible workarounds for this issue.
Possible DoS Vulnerability in Multipart MIME parsing
There is a possible DoS vulnerability in the Multipart MIME parsing code in Rack. This vulnerability has been assigned the CVE identifier CVE-2023-27530.
Versions Affected: All. Not affected: None Fixed Versions: 3.0.4.2, 2.2.6.3, 2.1.4.3, 2.0.9.3
Impact
The Multipart MIME parsing code in Rack limits the number of file parts, but does not limit the total number of parts that can be uploaded. Carefully crafted requests can abuse this and cause multipart parsing to take longer than expected.
All users running an affected release should either upgrade or use one of the workarounds immediately.
Workarounds
A proxy can be configured to limit the POST body size which will mitigate this issue.
Possible Denial of Service Vulnerability in Rack’s header parsing
There is a denial of service vulnerability in the header parsing component of Rack. This vulnerability has been assigned the CVE identifier CVE-2023-27539.
Versions Affected: >= 2.0.0 Not affected: None. Fixed Versions: 2.2.6.4, 3.0.6.1
Impact
Carefully crafted input can cause header parsing in Rack to take an unexpected amount of time, possibly resulting in a denial of service attack vector. Any applications that parse headers using Rack (virtually all Rails applications) are impacted.
Workarounds
Setting Regexp.timeout in Ruby 3.2 is a possible workaround.
Denial of Service Vulnerability in Rack Content-Type Parsing
There is a possible denial of service vulnerability in the content type parsing component of Rack. This vulnerability has been assigned the CVE identifier CVE-2024-25126.
Versions Affected: >= 0.4 Not affected: < 0.4 Fixed Versions: 3.0.9.1, 2.2.8.1
Impact
Carefully crafted content type headers can cause Rack’s media type parser to take much longer than expected, leading to a possible denial of service vulnerability.
Impacted code will use Rack’s media type parser to parse content type headers. This code will look like below:
request.media_type
## OR
request.media_type_params
## OR
Rack::MediaType.type(content_type)
Some frameworks (including Rails) call this code internally, so upgrading is recommended!
All users running an affected release should either upgrade or use one of the workarounds immediately.
Releases
The fixed releases are available at the normal locations.
Workarounds
There are no feasible workarounds for this issue.
Possible DoS Vulnerability with Range Header in Rack
There is a possible DoS vulnerability relating to the Range request header in Rack. This vulnerability has been assigned the CVE identifier CVE-2024-26141.
Versions Affected: >= 1.3.0. Not affected: < 1.3.0 Fixed Versions: 3.0.9.1, 2.2.8.1
Impact
Carefully crafted Range headers can cause a server to respond with an unexpectedly large response. Responding with such large responses could lead to a denial of service issue.
Vulnerable applications will use the Rack::File middleware or the Rack::Utils.byte_ranges methods (this includes Rails applications).
Releases
The fixed releases are available at the normal locations.
Workarounds
There are no feasible workarounds for this issue.
Possible Denial of Service Vulnerability in Rack Header Parsing
There is a possible denial of service vulnerability in the header parsing routines in Rack. This vulnerability has been assigned the CVE identifier CVE-2024-26146.
Versions Affected: All. Not affected: None Fixed Versions: 2.0.9.4, 2.1.4.4, 2.2.8.1, 3.0.9.1
Impact
Carefully crafted headers can cause header parsing in Rack to take longer than expected resulting in a possible denial of service issue. Accept and Forwarded headers are impacted.
Ruby 3.2 has mitigations for this problem, so Rack applications using Ruby 3.2 or newer are unaffected.
Releases
The fixed releases are available at the normal locations.
Workarounds
There are no feasible workarounds for this issue.
Rack's unbounded multipart preamble buffering enables DoS (memory exhaustion)
Summary
Rack::Multipart::Parser buffers the entire multipart preamble (bytes before the first boundary) in memory without any size limit. A client can send a large preamble followed by a valid boundary, causing significant memory use and potential process termination due to out-of-memory (OOM) conditions.
Details
While searching for the first boundary, the parser appends incoming data into a shared buffer (@sbuf.concat(content)) and scans for the boundary pattern:
@sbuf.scan_until(@body_regex)
If the boundary is not yet found, the parser continues buffering data indefinitely. There is no trimming or size cap on the preamble, allowing attackers to send arbitrary amounts of data before the first boundary.
Impact
Remote attackers can trigger large transient memory spikes by including a long preamble in multipart/form-data requests. The impact scales with allowed request sizes and concurrency, potentially causing worker crashes or severe slowdown due to garbage collection.
Mitigation
Upgrade: Use a patched version of Rack that enforces a preamble size limit (e.g., 16 KiB) or discards preamble data entirely per RFC 2046 § 5.1.1.
Workarounds:
- Limit total request body size at the proxy or web server level.
- Monitor memory and set per-process limits to prevent OOM conditions.
Multipart parser buffers large non‑file fields entirely in memory, enabling DoS (memory exhaustion)
Summary
Rack::Multipart::Parser stores non-file form fields (parts without a filename) entirely in memory as Ruby String objects. A single large text field in a multipart/form-data request (hundreds of megabytes or more) can consume equivalent process memory, potentially leading to out-of-memory (OOM) conditions and denial of service (DoS).
Details
During multipart parsing, file parts are streamed to temporary files, but non-file parts are buffered into memory:
body = String.new # non-file → in-RAM buffer
@mime_parts[mime_index].body << content
There is no size limit on these in-memory buffers. As a result, any large text field—while technically valid—will be loaded fully into process memory before being added to params.
Impact
Attackers can send large non-file fields to trigger excessive memory usage. Impact scales with request size and concurrency, potentially leading to worker crashes or severe garbage-collection overhead. All Rack applications processing multipart form submissions are affected.
Mitigation
Upgrade: Use a patched version of Rack that enforces a reasonable size cap for non-file fields (e.g., 2 MiB).
Workarounds:
- Restrict maximum request body size at the web-server or proxy layer (e.g., Nginx
client_max_body_size). - Validate and reject unusually large form fields at the application level.
- Restrict maximum request body size at the web-server or proxy layer (e.g., Nginx
Rack's multipart parser buffers unbounded per-part headers, enabling DoS (memory exhaustion)
Summary
Rack::Multipart::Parser can accumulate unbounded data when a multipart part’s header block never terminates with the required blank line (CRLFCRLF). The parser keeps appending incoming bytes to memory without a size cap, allowing a remote attacker to exhaust memory and cause a denial of service (DoS).
Details
While reading multipart headers, the parser waits for CRLFCRLF using:
@sbuf.scan_until(/(.*?\r
)\r
/m)
If the terminator never appears, it continues appending data (@sbuf.concat(content)) indefinitely. There is no limit on accumulated header bytes, so a single malformed part can consume memory proportional to the request body size.
Impact
Attackers can send incomplete multipart headers to trigger high memory use, leading to process termination (OOM) or severe slowdown. The effect scales with request size limits and concurrency. All applications handling multipart uploads may be affected.
Mitigation
Upgrade to a patched Rack version that caps per-part header size (e.g., 64 KiB).
Until then, restrict maximum request sizes at the proxy or web server layer (e.g., Nginx
client_max_body_size).
Rack has a Possible Information Disclosure Vulnerability
Summary
A possible information disclosure vulnerability existed in Rack::Sendfile when running behind a proxy that supports x-sendfile headers (such as Nginx). Specially crafted headers could cause Rack::Sendfile to miscommunicate with the proxy and trigger unintended internal requests, potentially bypassing proxy-level access restrictions.
Details
When Rack::Sendfile received untrusted x-sendfile-type or x-accel-mapping headers from a client, it would interpret them as proxy configuration directives. This could cause the middleware to send a redirect
response to the proxy, prompting it to reissue a new internal request that was not subject to the proxy's access controls.
An attacker could exploit this by: 1. Setting a crafted x-sendfile-type: x-accel-redirect header. 2. Setting a crafted x-accel-mapping header. 3. Requesting a path that qualifies for proxy-based acceleration.
Impact
Attackers could bypass proxy-enforced restrictions and access internal endpoints intended to be protected (such as administrative pages). The vulnerability did not allow arbitrary file reads but could expose sensitive application routes.
This issue only affected systems meeting all of the following conditions:
- The application used
Rack::Sendfilewith a proxy that supportsx-accel-redirect(e.g., Nginx). - The proxy did not always set or remove the
x-sendfile-typeandx-accel-mappingheaders. - The application exposed an endpoint that returned a body responding to
.to_path.
Mitigation
- Upgrade to a fixed version of Rack which requires explicit configuration to enable
x-accel-redirect:
use Rack::Sendfile, "x-accel-redirect"
- Alternatively, configure the proxy to always set or strip the headers (you should be doing this!):
proxy_set_header x-sendfile-type x-accel-redirect;
proxy_set_header x-accel-mapping /var/www/=/files/;
- Or in Rails applications, disable sendfile completely:
config.action_dispatch.x_sendfile_header = nil
Rack is vulnerable to a memory-exhaustion DoS through unbounded URL-encoded body parsing
Summary
Rack::Request#POST reads the entire request body into memory for Content-Type: application/x-www-form-urlencoded, calling rack.input.read(nil) without enforcing a length or cap. Large request bodies can therefore be buffered completely into process memory before parsing, leading to denial of service (DoS) through memory exhaustion.
Details
When handling non-multipart form submissions, Rack’s request parser performs:
form_vars = get_header(RACK_INPUT).read
Since read is called with no argument, the entire request body is loaded into a Ruby String. This occurs before query parameter parsing or enforcement of any params_limit. As a result, Rack applications without an upstream body-size limit can experience unbounded memory allocation proportional to request size.
Impact
Attackers can send large application/x-www-form-urlencoded bodies to consume process memory, causing slowdowns or termination by the operating system (OOM). The effect scales linearly with request size and concurrency. Even with parsing limits configured, the issue occurs before those limits are enforced.
Mitigation
- Update to a patched version of Rack that enforces form parameter limits using
query_parser.bytesize_limit, preventing unbounded reads ofapplication/x-www-form-urlencodedbodies. - Enforce strict maximum body size at the proxy or web server layer (e.g., Nginx
client_max_body_size, ApacheLimitRequestBody).
175 Other Versions
| Version | License | Security | Released | |
|---|---|---|---|---|
| 3.0.0.rc1 | MIT | 15 | 2022-09-04 - 23:52 | over 3 years |
| 3.0.0.beta1 | MIT | 15 | 2022-08-08 - 20:34 | over 3 years |
| 2.2.22 | MIT | 2026-02-16 - 03:40 | 6 days | |
| 2.2.21 | MIT | 2 | 2025-11-02 - 12:19 | 4 months |
| 2.2.20 | MIT | 2 | 2025-10-10 - 00:36 | 5 months |
| 2.2.19 | MIT | 4 | 2025-10-07 - 01:51 | 5 months |
| 2.2.18 | MIT | 7 | 2025-09-25 - 09:02 | 5 months |
| 2.2.17 | MIT | 9 | 2025-06-03 - 01:57 | 9 months |
| 2.2.16 | MIT | 9 | 2025-05-22 - 05:33 | 9 months |
| 2.2.15 | MIT | 9 | 2025-05-18 - 02:38 | 9 months |
| 2.2.14 | MIT | 9 | 2025-05-06 - 21:33 | 10 months |
| 2.2.13 | MIT | 12 | 2025-03-10 - 21:19 | 12 months |
| 2.2.12 | MIT | 13 | 2025-03-04 - 05:45 | 12 months |
| 2.2.11 | MIT | 14 | 2025-02-12 - 03:54 | about 1 year |
| 2.2.10 | MIT | 15 | 2024-10-14 - 01:47 | over 1 year |
| 2.2.9 | MIT | 15 | 2024-03-21 - 01:19 | almost 2 years |
| 2.2.8.1 | MIT | 15 | 2024-02-21 - 19:23 | about 2 years |
| 2.2.8 | MIT | 21 | 2023-07-31 - 02:43 | over 2 years |
| 2.2.7 | MIT | 21 | 2023-04-24 - 23:22 | almost 3 years |
| 2.2.6.4 | MIT | 21 | 2023-03-13 - 18:10 | almost 3 years |
| 2.2.6.3 | MIT | 23 | 2023-03-02 - 22:57 | almost 3 years |
| 2.2.6.2 | MIT | 25 | 2023-01-17 - 21:22 | about 3 years |
| 2.2.6.1 | MIT | 27 | 2023-01-17 - 20:48 | about 3 years |
| 2.2.6 | MIT | 31 | 2023-01-16 - 21:05 | about 3 years |
| 2.2.5 | MIT | 31 | 2022-12-26 - 20:19 | about 3 years |
| 2.2.4 | MIT | 31 | 2022-06-30 - 22:22 | over 3 years |
| 2.2.3.1 | MIT | 31 | 2022-05-27 - 15:31 | over 3 years |
| 2.2.3 | MIT | 35 | 2020-06-15 - 22:25 | over 5 years |
| 2.2.2 | MIT | 37 | 2020-02-10 - 22:25 | about 6 years |
| 2.2.1 | MIT | 37 | 2020-02-09 - 06:20 | about 6 years |
| 2.2.0 | MIT | 37 | 2020-02-08 - 18:26 | about 6 years |
| 2.1.4.4 | MIT | 30 | 2024-02-21 - 19:21 | about 2 years |
| 2.1.4.3 | MIT | 32 | 2023-03-02 - 22:57 | almost 3 years |
| 2.1.4.2 | MIT | 34 | 2023-01-17 - 20:48 | about 3 years |
| 2.1.4.1 | MIT | 40 | 2022-05-27 - 15:31 | over 3 years |
| 2.1.4 | MIT | 44 | 2020-06-15 - 22:24 | over 5 years |
| 2.1.3 | MIT | 45 | 2020-05-12 - 21:44 | almost 6 years |
| 2.1.2 | MIT | 46 | 2020-01-27 - 22:42 | about 6 years |
| 2.1.1 | MIT | 46 | 2020-01-11 - 22:18 | about 6 years |
| 2.1.0 | MIT | 46 | 2020-01-10 - 17:49 | about 6 years |
| 2.0.9.4 | MIT | 34 | 2024-02-21 - 19:20 | about 2 years |
| 2.0.9.3 | MIT | 36 | 2023-03-02 - 22:57 | almost 3 years |
| 2.0.9.2 | MIT | 38 | 2023-01-17 - 20:48 | about 3 years |
| 2.0.9.1 | MIT | 44 | 2022-05-27 - 15:31 | over 3 years |
| 2.0.9 | MIT | 48 | 2020-02-08 - 18:21 | about 6 years |
| 2.0.8 | MIT | 48 | 2019-12-18 - 18:08 | about 6 years |
| 2.0.7 | MIT | 50 | 2019-04-02 - 16:54 | almost 7 years |
| 2.0.6 | MIT | 50 | 2018-11-05 - 20:00 | over 7 years |
| 2.0.5 | MIT | 54 | 2018-04-23 - 17:47 | almost 8 years |
| 2.0.4 | MIT | 54 | 2018-01-31 - 18:17 | about 8 years |
