Skip to content

Commit a3f3c3e

Browse files
committed
Fix ReDoS in accept header scanning
Thanks svalkanov for the patch! [CVE-2024-26142]
1 parent 32587c3 commit a3f3c3e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

actionpack/lib/action_dispatch/http/mime_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class << self
157157
TRAILING_STAR_REGEXP = /^(text|application)\/\*/
158158
# all media-type parameters need to be before the q-parameter
159159
# https://www.rfc-editor.org/rfc/rfc7231#section-5.3.2
160-
PARAMETER_SEPARATOR_REGEXP = /\s*;\s*q="?/
160+
PARAMETER_SEPARATOR_REGEXP = /;\s*q="?/
161161
ACCEPT_HEADER_REGEXP = /[^,\s"](?:[^,"]|"[^"]*")*/
162162

163163
def register_callback(&block)
@@ -197,7 +197,7 @@ def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], s
197197
def parse(accept_header)
198198
if !accept_header.include?(",")
199199
if (index = accept_header.index(PARAMETER_SEPARATOR_REGEXP))
200-
accept_header = accept_header[0, index]
200+
accept_header = accept_header[0, index].strip
201201
end
202202
return [] if accept_header.blank?
203203
parse_trailing_star(accept_header) || Array(Mime::Type.lookup(accept_header))

0 commit comments

Comments
 (0)