rack 3.1.23 → 3.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/lib/rack/directory.rb +2 -1
- data/lib/rack/multipart/parser.rb +87 -16
- data/lib/rack/query_parser.rb +28 -8
- data/lib/rack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f9f5949aafc42d0d4f0604f1dd1814d9afef49c59bef8a861fd94ea1b33f9a4
|
|
4
|
+
data.tar.gz: 540e0171cd56eca530429bea72df6db1d715e553bf80a716aa3784ada8af02b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf70345c136c1e76a6a4794454cda220e1be0047c6fed75d6c33f1449008fd0ff5dd76f96081a368ae8492fbcf11cd82e5bcc61eb8d8fbcc3f608be33f608d51
|
|
7
|
+
data.tar.gz: cbf782156cc1ec35e0f38e5587a12a88d2edafbe7800158bdec7bb3ee5e93bf894ff363ab0e5f7aff9cb34d594c3d408c934a89110ac74c3fdfe584f4cbfca72
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
+
## [3.1.24] - 2026-11-20
|
|
6
|
+
|
|
7
|
+
### Security
|
|
8
|
+
|
|
9
|
+
- [GHSA-r243-pfwh-7rpx](https://github.com/advisories/GHSA-r243-pfwh-7rpx) Multipart boundary was extracted by substring match rather than parameter parsing, allowing parser differentials and WAF bypass.
|
|
10
|
+
- [GHSA-58mf-c3jj-277p](https://github.com/advisories/GHSA-58mf-c3jj-277p) Multipart parser searched the load path for every unknown part `charset`, allowing denial of service via CPU exhaustion.
|
|
11
|
+
- [GHSA-mhj6-xc86-54m8](https://github.com/advisories/GHSA-mhj6-xc86-54m8) `Rack::Directory` listed directories outside the root when `..` followed a symbolic link.
|
|
12
|
+
- [GHSA-frgv-948x-h96g](https://github.com/advisories/GHSA-frgv-948x-h96g) `Rack::Multipart::Parser` did not unfold a folded `Content-ID` header, preserving CRLF in the parsed parameter name.
|
|
13
|
+
- [GHSA-f7cc-57h7-qrcg](https://github.com/advisories/GHSA-f7cc-57h7-qrcg) `Rack::QueryParser` separator pattern allocated about 48 bytes per space after `&`, and nested parameter name splitting about 48 bytes per bracket, allowing denial of service via memory amplification. `DEFAULT_SEP` and the `COMMON_SEP` entries for `&` and `;` are now Strings rather than Regexps.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- The multipart `Content-Type` header is now parsed according to RFC 9110. An unquoted `boundary` containing characters outside the token grammar (such as `=`, `/`, `:`, `?`, parentheses, or spaces), or parameters not separated by `;`, now raise `Rack::Multipart::Error` instead of being accepted. Quoted boundaries are unaffected. ([@jeremyevans](https://github.com/jeremyevans), [@tenderlove](https://github.com/tenderlove))
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- `Rack::Multipart` no longer raises `TypeError` for a part with `charset=internal` when no default internal encoding is set; the part is treated as binary.
|
|
22
|
+
|
|
5
23
|
## [3.1.23] - 2026-10-30
|
|
6
24
|
|
|
7
25
|
### Security
|
data/lib/rack/directory.rb
CHANGED
|
@@ -101,6 +101,7 @@ table { width:100%%; }
|
|
|
101
101
|
if client_error_response = check_bad_request(path_info) || check_forbidden(path_info)
|
|
102
102
|
client_error_response
|
|
103
103
|
else
|
|
104
|
+
path_info = Utils.clean_path_info(path_info)
|
|
104
105
|
path = ::File.join(@root, path_info)
|
|
105
106
|
list_path(env, path, path_info, script_name)
|
|
106
107
|
end
|
|
@@ -137,7 +138,7 @@ table { width:100%%; }
|
|
|
137
138
|
|
|
138
139
|
# Globbing not safe as path could contain glob metacharacters
|
|
139
140
|
body = DirectoryBody.new(@root, path, ->(basename) do
|
|
140
|
-
stat = stat(::File.join(path, basename))
|
|
141
|
+
stat = stat(basename == '..' ? ::File.dirname(path) : ::File.join(path, basename))
|
|
141
142
|
next unless stat
|
|
142
143
|
|
|
143
144
|
url = ::File.join(*url_head + [Utils.escape_path(basename)])
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'set'
|
|
3
4
|
require 'strscan'
|
|
4
5
|
|
|
5
6
|
require_relative '../utils'
|
|
@@ -107,23 +108,78 @@ module Rack
|
|
|
107
108
|
MultipartInfo = Struct.new :params, :tmp_files
|
|
108
109
|
EMPTY = MultipartInfo.new(nil, [])
|
|
109
110
|
|
|
111
|
+
# Parse the boundary parameter from a multipart content type, following
|
|
112
|
+
# the media type grammar in RFC 9110 Section 8.3.1:
|
|
113
|
+
#
|
|
114
|
+
# media-type = type "/" subtype parameters
|
|
115
|
+
# parameters = *( OWS ";" OWS [ parameter ] )
|
|
116
|
+
# parameter = parameter-name "=" parameter-value
|
|
117
|
+
# parameter-value = ( token / quoted-string )
|
|
118
|
+
#
|
|
119
|
+
# Returns nil if the content type is not multipart or has no boundary
|
|
120
|
+
# parameter. Raises Error if the parameters are malformed, the boundary
|
|
121
|
+
# is empty, or there is more than one boundary parameter.
|
|
110
122
|
def self.parse_boundary(content_type)
|
|
111
|
-
return unless content_type
|
|
112
|
-
data = content_type.match(MULTIPART)
|
|
113
|
-
return unless data
|
|
123
|
+
return unless content_type && content_type.match?(/\Amultipart\//ni)
|
|
114
124
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
#
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
scanner = StringScanner.new(content_type.b)
|
|
126
|
+
return unless scanner.skip(/multipart\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+/ni)
|
|
127
|
+
|
|
128
|
+
boundary = nil
|
|
129
|
+
boundary_seen = false
|
|
130
|
+
ows = /[ \t]*/n
|
|
131
|
+
# From RFC 9110 Section 5.6.2
|
|
132
|
+
token = /[!#$%&'*+\-.^_`|~0-9A-Za-z]+/n
|
|
133
|
+
|
|
134
|
+
loop do
|
|
135
|
+
scanner.skip(ows)
|
|
136
|
+
break if scanner.eos?
|
|
137
|
+
|
|
138
|
+
unless scanner.skip(/;/n)
|
|
139
|
+
raise Error, "invalid parameters in multipart content type"
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
scanner.skip(ows)
|
|
143
|
+
# Empty parameter, such as in "a=b;;c=d" or a trailing ";".
|
|
144
|
+
next unless name = scanner.scan(token)
|
|
145
|
+
is_boundary = name.casecmp?("boundary")
|
|
146
|
+
# RFC 2231 forms such as boundary*, boundary*0, or boundary*0*. Rack
|
|
147
|
+
# does not use them, but some parsers (for example Go's
|
|
148
|
+
# mime.ParseMediaType) prefer them over a plain boundary parameter,
|
|
149
|
+
# so treat them as boundary parameters when checking for duplicates.
|
|
150
|
+
is_rfc2231_boundary = !is_boundary && name.match?(/\Aboundary\*/ni)
|
|
151
|
+
|
|
152
|
+
unless scanner.skip(/=/n)
|
|
153
|
+
if is_boundary && scanner.match?(/\s+=/n)
|
|
154
|
+
raise Error, "whitespace between boundary parameter name and equal sign"
|
|
155
|
+
end
|
|
156
|
+
raise Error, "invalid parameter in multipart content type"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
if scanner.scan(/"((?:[\t \x21\x23-\x5B\x5D-\x7E\x80-\xFF]|\\[\t \x21-\x7E\x80-\xFF])*)"/n)
|
|
160
|
+
value = scanner[1]
|
|
161
|
+
value.gsub!(/\\(.)/mn, '\1')
|
|
162
|
+
elsif !(value = scanner.scan(token))
|
|
163
|
+
raise Error, "invalid parameter value in multipart content type"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
next unless is_boundary || is_rfc2231_boundary
|
|
167
|
+
|
|
168
|
+
if boundary_seen
|
|
169
|
+
raise BoundaryTooLongError, "multiple boundary parameters found in multipart content type"
|
|
170
|
+
end
|
|
171
|
+
boundary_seen = true
|
|
172
|
+
|
|
173
|
+
next unless is_boundary
|
|
174
|
+
|
|
175
|
+
if value.empty?
|
|
176
|
+
raise Error, "empty boundary in multipart content type"
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
boundary = value
|
|
124
180
|
end
|
|
125
181
|
|
|
126
|
-
|
|
182
|
+
boundary
|
|
127
183
|
end
|
|
128
184
|
|
|
129
185
|
def self.parse(io, content_length, content_type, tmpfile, bufsize, qp)
|
|
@@ -459,6 +515,7 @@ module Rack
|
|
|
459
515
|
end
|
|
460
516
|
else
|
|
461
517
|
name = head[MULTIPART_CONTENT_ID, 1]
|
|
518
|
+
name.gsub!(OBS_UNFOLD, '\\1') if name
|
|
462
519
|
end
|
|
463
520
|
|
|
464
521
|
if filename_star
|
|
@@ -579,13 +636,27 @@ module Rack
|
|
|
579
636
|
body.force_encoding(encoding)
|
|
580
637
|
end
|
|
581
638
|
|
|
639
|
+
ENCODING_NAMES = Set.new(Encoding.name_list.map(&:downcase)).freeze
|
|
640
|
+
private_constant :ENCODING_NAMES
|
|
641
|
+
|
|
582
642
|
# Return the related Encoding object. However, because
|
|
583
643
|
# enc is submitted by the user, it may be invalid, so
|
|
584
644
|
# use a binary encoding in that case.
|
|
585
645
|
def find_encoding(enc)
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
646
|
+
if respect_requested_encoding?(enc)
|
|
647
|
+
begin
|
|
648
|
+
Encoding.find(enc)
|
|
649
|
+
rescue ArgumentError
|
|
650
|
+
nil
|
|
651
|
+
end
|
|
652
|
+
end || Encoding::BINARY
|
|
653
|
+
end
|
|
654
|
+
|
|
655
|
+
# Whether to respect the given encoding (given as a string). If a
|
|
656
|
+
# requested encoding is not respected, binary encoding is used.
|
|
657
|
+
# The string may be nil or in any encoding, so compare it as bytes.
|
|
658
|
+
def respect_requested_encoding?(encoding_string)
|
|
659
|
+
ENCODING_NAMES.include?(encoding_string.to_s.b.downcase(:ascii))
|
|
589
660
|
end
|
|
590
661
|
|
|
591
662
|
def handle_empty_content!(content)
|
data/lib/rack/query_parser.rb
CHANGED
|
@@ -5,8 +5,8 @@ require 'uri'
|
|
|
5
5
|
|
|
6
6
|
module Rack
|
|
7
7
|
class QueryParser
|
|
8
|
-
DEFAULT_SEP =
|
|
9
|
-
COMMON_SEP = { ";" =>
|
|
8
|
+
DEFAULT_SEP = "&"
|
|
9
|
+
COMMON_SEP = { ";" => ";", ";," => /[;,]/n, "&" => "&" }
|
|
10
10
|
|
|
11
11
|
# ParameterTypeError is the error that is raised when incoming structural
|
|
12
12
|
# parameters (parsed by parse_nested_query) contain conflicting types.
|
|
@@ -75,7 +75,7 @@ module Rack
|
|
|
75
75
|
|
|
76
76
|
params = make_params
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
split_query_string(qs, separator).each do |p|
|
|
79
79
|
next if p.empty?
|
|
80
80
|
k, v = p.split('=', 2).map!(&unescaper)
|
|
81
81
|
|
|
@@ -102,7 +102,7 @@ module Rack
|
|
|
102
102
|
params = make_params
|
|
103
103
|
|
|
104
104
|
unless qs.nil? || qs.empty?
|
|
105
|
-
|
|
105
|
+
split_query_string(qs, separator).each do |p|
|
|
106
106
|
k, v = p.split('=', 2).map! { |s| unescape(s) }
|
|
107
107
|
|
|
108
108
|
_normalize_params(params, k, v, 0)
|
|
@@ -208,15 +208,35 @@ module Rack
|
|
|
208
208
|
def params_hash_has_key?(hash, key)
|
|
209
209
|
return false if /\[\]/.match?(key)
|
|
210
210
|
|
|
211
|
-
key.split(/[\[\]]+/)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
211
|
+
# Equivalent to walking key.split(/[\[\]]+/), but a quantified regexp
|
|
212
|
+
# allocates backtracking state for every bracket matched, so find the
|
|
213
|
+
# segments with single character searches instead, which do not
|
|
214
|
+
# backtrack.
|
|
215
|
+
pos = 0
|
|
216
|
+
while (start = key.index(/[^\[\]]/, pos))
|
|
217
|
+
stop = key.index(/[\[\]]/, start) || key.length
|
|
218
|
+
part = key[start, stop - start]
|
|
219
|
+
return false unless params_hash_type?(hash) && hash.key?(part)
|
|
220
|
+
hash = hash[part]
|
|
221
|
+
pos = stop
|
|
215
222
|
end
|
|
216
223
|
|
|
217
224
|
true
|
|
218
225
|
end
|
|
219
226
|
|
|
227
|
+
def split_query_string(qs, separator)
|
|
228
|
+
pairs = check_query_string(qs, separator).split(separator ? (COMMON_SEP[separator] || /[#{separator}]/n) : DEFAULT_SEP)
|
|
229
|
+
|
|
230
|
+
# Remove spaces following the separator. A quantified regexp such as
|
|
231
|
+
# /& */ allocates backtracking state for every space matched, so find
|
|
232
|
+
# the first non-space character instead, which does not backtrack.
|
|
233
|
+
pairs.each do |pair|
|
|
234
|
+
pair.slice!(0, pair.index(/[^ ]/) || pair.length) if pair.getbyte(0) == 32
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
pairs
|
|
238
|
+
end
|
|
239
|
+
|
|
220
240
|
def check_query_string(qs, sep)
|
|
221
241
|
if qs
|
|
222
242
|
if qs.bytesize > @bytesize_limit
|
data/lib/rack/version.rb
CHANGED