Moderate severityNVD Advisory· Published Feb 28, 2024· Updated Feb 13, 2025
Rack ReDos in content type parsing (2nd degree polynomial)
CVE-2024-25126
Description
Rack is a modular Ruby web server interface. 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 (ReDos 2nd degree polynomial). This vulnerability is patched in 3.0.9.1 and 2.2.8.1.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
rackRubyGems | >= 3.0.0, < 3.0.9.1 | 3.0.9.1 |
rackRubyGems | >= 0.4, < 2.2.8.1 | 2.2.8.1 |
Affected products
1Patches
2d9c163a443b8Avoid 2nd degree polynomial regexp in MediaType
1 file changed · +9 −4
lib/rack/media_type.rb+9 −4 modified@@ -4,7 +4,7 @@ module Rack # Rack::MediaType parse media type and parameters out of content_type string class MediaType - SPLIT_PATTERN = %r{\s*[;,]\s*} + SPLIT_PATTERN = /[;,]/ class << self # The media type (type/subtype) portion of the CONTENT_TYPE header @@ -15,7 +15,11 @@ class << self # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 def type(content_type) return nil unless content_type - content_type.split(SPLIT_PATTERN, 2).first.tap &:downcase! + if type = content_type.split(SPLIT_PATTERN, 2).first + type.rstrip! + type.downcase! + type + end end # The media type parameters provided in CONTENT_TYPE as a Hash, or @@ -27,9 +31,10 @@ def params(content_type) return {} if content_type.nil? content_type.split(SPLIT_PATTERN)[1..-1].each_with_object({}) do |s, hsh| + s.strip! k, v = s.split('=', 2) - - hsh[k.tap(&:downcase!)] = strip_doublequotes(v) + k.downcase! + hsh[k] = strip_doublequotes(v) end end
6efb2ceea003Avoid 2nd degree polynomial regexp in MediaType
1 file changed · +9 −4
lib/rack/media_type.rb+9 −4 modified@@ -4,7 +4,7 @@ module Rack # Rack::MediaType parse media type and parameters out of content_type string class MediaType - SPLIT_PATTERN = %r{\s*[;,]\s*} + SPLIT_PATTERN = /[;,]/ class << self # The media type (type/subtype) portion of the CONTENT_TYPE header @@ -15,7 +15,11 @@ class << self # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7 def type(content_type) return nil unless content_type - content_type.split(SPLIT_PATTERN, 2).first.tap(&:downcase!) + if type = content_type.split(SPLIT_PATTERN, 2).first + type.rstrip! + type.downcase! + type + end end # The media type parameters provided in CONTENT_TYPE as a Hash, or @@ -27,9 +31,10 @@ def params(content_type) return {} if content_type.nil? content_type.split(SPLIT_PATTERN)[1..-1].each_with_object({}) do |s, hsh| + s.strip! k, v = s.split('=', 2) - - hsh[k.tap(&:downcase!)] = strip_doublequotes(v) + k.downcase! + hsh[k] = strip_doublequotes(v) end end
Vulnerability mechanics
Synthesis attempt was rejected by the grounding validator. Re-run pending.
References
10- github.com/advisories/GHSA-22f2-v57c-j9cxghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2024-25126ghsaADVISORY
- discuss.rubyonrails.org/t/denial-of-service-vulnerability-in-rack-content-type-parsing/84941ghsax_refsource_MISCWEB
- github.com/rack/rack/commit/6efb2ceea003c4b195815a614e00438cbd543462ghsax_refsource_MISCWEB
- github.com/rack/rack/commit/d9c163a443b8cadf4711d84bd2c58cb9ef89cf49ghsax_refsource_MISCWEB
- github.com/rack/rack/security/advisories/GHSA-22f2-v57c-j9cxghsax_refsource_CONFIRMWEB
- github.com/rubysec/ruby-advisory-db/blob/master/gems/rack/CVE-2024-25126.ymlghsax_refsource_MISCWEB
- lists.debian.org/debian-lts-announce/2024/04/msg00022.htmlghsaWEB
- security.netapp.com/advisory/ntap-20240510-0005ghsaWEB
- security.netapp.com/advisory/ntap-20240510-0005/mitre
News mentions
0No linked articles in our index yet.