rack 3.2.8 → 3.2.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57fe61378c6650847203c66b4d5597dadee788d07e9178bb38d89de37ce91f8a
4
- data.tar.gz: 5cb0747f5ce457a10d836fed60259ab7f7ae37fe33b9c164c2cf201b4d58d306
3
+ metadata.gz: 525ce504d772e1970a38da54295bca3e708d2064c817a36b43354b4fe1f3f5f6
4
+ data.tar.gz: 216bab19d15bb18906f9754ccae2f815e3f592e4c10a0155800d7d9fd2f6112c
5
5
  SHA512:
6
- metadata.gz: 4f28e8f049827ce264fcd4845adfad131796e3e1d18d036fc22bbbd68db80800bf124b0324f59ccc098c9bfb0b59a0ecb8ec1d75d22727896681b591b0a68794
7
- data.tar.gz: 3dcb3e16c41b6c95e06a35d282e9c35ebc7b26a31505be8beb3d17582bfd8a2e182ca132c8e4f1122f15122581165b8cd3337e943c150247d3c577686913f541
6
+ metadata.gz: 4cae1db3881df0d79caa750578e2620cccd51aed3e8387554609ed05429ad7f9179313d19bb7738f5163dad67020aa520af0fa6c2c282a3f5683574078eaee11
7
+ data.tar.gz: 6adb94f5d1df18c3f0c4cd33c7c34caf3038473d04867c3e7373fcfd29ccabfd522d4fc87346530938594aeb3f06b926eee5b8c34053186f02f3c75f74af5ca4
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.2.9] - 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.2.8] - 2026-10-30
6
24
 
7
25
  ### Security
@@ -128,6 +146,24 @@ This release continues Rack's evolution toward a cleaner, more efficient foundat
128
146
  - `SERVER_NAME` and `HTTP_HOST` are now more strictly validated according to the relevant specifications. ([#2298](https://github.com/rack/rack/pull/2298), [@ioquatix])
129
147
  - `Rack::Lint` now disallows `PATH_INFO="" SCRIPT_NAME=""`. ([#2298](https://github.com/rack/rack/issues/2307), [@jeremyevans])
130
148
 
149
+ ## [3.1.24] - 2026-11-20
150
+
151
+ ### Security
152
+
153
+ - [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.
154
+ - [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.
155
+ - [GHSA-mhj6-xc86-54m8](https://github.com/advisories/GHSA-mhj6-xc86-54m8) `Rack::Directory` listed directories outside the root when `..` followed a symbolic link.
156
+ - [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.
157
+ - [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.
158
+
159
+ ### Changed
160
+
161
+ - 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))
162
+
163
+ ### Fixed
164
+
165
+ - `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.
166
+
131
167
  ## [3.1.23] - 2026-10-30
132
168
 
133
169
  ### Security
@@ -561,6 +597,19 @@ This release introduces major improvements to Rack, including enhanced support f
561
597
  - Fix multipart filename generation for filenames that contain spaces. Encode spaces as "%20" instead of "+" which will be decoded properly by the multipart parser. ([#1736](https://github.com/rack/rack/pull/1645), [@muirdm](https://github.com/muirdm))
562
598
  - `Rack::Request#scheme` returns `ws` or `wss` when one of the `X-Forwarded-Scheme` / `X-Forwarded-Proto` headers is set to `ws` or `wss`, respectively. ([#1730](https://github.com/rack/rack/issues/1730), [@erwanst](https://github.com/erwanst))
563
599
 
600
+ ## [2.2.26] - 2026-11-20
601
+
602
+ ### Security
603
+
604
+ - [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.
605
+ - [GHSA-mhj6-xc86-54m8](https://github.com/advisories/GHSA-mhj6-xc86-54m8) `Rack::Directory` listed directories outside the root when `..` followed a symbolic link.
606
+ - [GHSA-frgv-948x-h96g](https://github.com/advisories/GHSA-frgv-948x-h96g) `Rack::Multipart::Parser` accepted raw CR and LF characters inside quoted multipart header values, preserving them in parsed parameter names.
607
+ - [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. The `COMMON_SEP` entries for `&` and `;` are now Strings rather than Regexps.
608
+
609
+ ### Changed
610
+
611
+ - 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 `EOFError` instead of being accepted. Quoted boundaries are unaffected. ([@jeremyevans](https://github.com/jeremyevans), [@tenderlove](https://github.com/tenderlove))
612
+
564
613
  ## [2.2.25] - 2026-10-30
565
614
 
566
615
  ### Security
@@ -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'
@@ -119,23 +120,78 @@ module Rack
119
120
  MultipartInfo = Struct.new :params, :tmp_files
120
121
  EMPTY = MultipartInfo.new(nil, [])
121
122
 
123
+ # Parse the boundary parameter from a multipart content type, following
124
+ # the media type grammar in RFC 9110 Section 8.3.1:
125
+ #
126
+ # media-type = type "/" subtype parameters
127
+ # parameters = *( OWS ";" OWS [ parameter ] )
128
+ # parameter = parameter-name "=" parameter-value
129
+ # parameter-value = ( token / quoted-string )
130
+ #
131
+ # Returns nil if the content type is not multipart or has no boundary
132
+ # parameter. Raises Error if the parameters are malformed, the boundary
133
+ # is empty, or there is more than one boundary parameter.
122
134
  def self.parse_boundary(content_type)
123
- return unless content_type
124
- data = content_type.match(MULTIPART)
125
- return unless data
135
+ return unless content_type && content_type.match?(/\Amultipart\//ni)
126
136
 
127
- unless data[1].empty?
128
- raise Error, "whitespace between boundary parameter name and equal sign"
129
- end
130
- # Count across the whole header rather than only after the match: the
131
- # lazy prefix in MULTIPART can skip a first boundary parameter whose
132
- # value is empty or starts with a quote, semicolon, or comma. Also
133
- # count RFC 2231 boundary* parameters, which some parsers prefer.
134
- if content_type.scan(/boundary(?:\*\d*\*?)?\s*=/i).size > 1
135
- raise BoundaryTooLongError, "multiple boundary parameters found in multipart content type"
137
+ scanner = StringScanner.new(content_type.b)
138
+ return unless scanner.skip(/multipart\/[!#$%&'*+\-.^_`|~0-9A-Za-z]+/ni)
139
+
140
+ boundary = nil
141
+ boundary_seen = false
142
+ ows = /[ \t]*/n
143
+ # From RFC 9110 Section 5.6.2
144
+ token = /[!#$%&'*+\-.^_`|~0-9A-Za-z]+/n
145
+
146
+ loop do
147
+ scanner.skip(ows)
148
+ break if scanner.eos?
149
+
150
+ unless scanner.skip(/;/n)
151
+ raise Error, "invalid parameters in multipart content type"
152
+ end
153
+
154
+ scanner.skip(ows)
155
+ # Empty parameter, such as in "a=b;;c=d" or a trailing ";".
156
+ next unless name = scanner.scan(token)
157
+ is_boundary = name.casecmp?("boundary")
158
+ # RFC 2231 forms such as boundary*, boundary*0, or boundary*0*. Rack
159
+ # does not use them, but some parsers (for example Go's
160
+ # mime.ParseMediaType) prefer them over a plain boundary parameter,
161
+ # so treat them as boundary parameters when checking for duplicates.
162
+ is_rfc2231_boundary = !is_boundary && name.match?(/\Aboundary\*/ni)
163
+
164
+ unless scanner.skip(/=/n)
165
+ if is_boundary && scanner.match?(/\s+=/n)
166
+ raise Error, "whitespace between boundary parameter name and equal sign"
167
+ end
168
+ raise Error, "invalid parameter in multipart content type"
169
+ end
170
+
171
+ if scanner.scan(/"((?:[\t \x21\x23-\x5B\x5D-\x7E\x80-\xFF]|\\[\t \x21-\x7E\x80-\xFF])*)"/n)
172
+ value = scanner[1]
173
+ value.gsub!(/\\(.)/mn, '\1')
174
+ elsif !(value = scanner.scan(token))
175
+ raise Error, "invalid parameter value in multipart content type"
176
+ end
177
+
178
+ next unless is_boundary || is_rfc2231_boundary
179
+
180
+ if boundary_seen
181
+ raise BoundaryTooLongError, "multiple boundary parameters found in multipart content type"
182
+ end
183
+ boundary_seen = true
184
+
185
+ next unless is_boundary
186
+
187
+ if value.empty?
188
+ raise Error, "empty boundary in multipart content type"
189
+ end
190
+
191
+ boundary = value
136
192
  end
137
193
 
138
- data[2]
194
+ boundary
139
195
  end
140
196
 
141
197
  def self.parse(io, content_length, content_type, tmpfile, bufsize, qp)
@@ -468,6 +524,7 @@ module Rack
468
524
  end
469
525
  else
470
526
  name = head[MULTIPART_CONTENT_ID, 1]
527
+ name.gsub!(OBS_UNFOLD, '\1') if name
471
528
  end
472
529
 
473
530
  if filename_star
@@ -588,13 +645,27 @@ module Rack
588
645
  body.force_encoding(encoding)
589
646
  end
590
647
 
648
+ ENCODING_NAMES = Set.new(Encoding.name_list.map(&:downcase)).freeze
649
+ private_constant :ENCODING_NAMES
650
+
591
651
  # Return the related Encoding object. However, because
592
652
  # enc is submitted by the user, it may be invalid, so
593
653
  # use a binary encoding in that case.
594
654
  def find_encoding(enc)
595
- Encoding.find enc
596
- rescue ArgumentError
597
- Encoding::BINARY
655
+ if respect_requested_encoding?(enc)
656
+ begin
657
+ Encoding.find(enc)
658
+ rescue ArgumentError
659
+ nil
660
+ end
661
+ end || Encoding::BINARY
662
+ end
663
+
664
+ # Whether to respect the given encoding (given as a string). If a
665
+ # requested encoding is not respected, binary encoding is used.
666
+ # The string may be nil or in any encoding, so compare it as bytes.
667
+ def respect_requested_encoding?(encoding_string)
668
+ ENCODING_NAMES.include?(encoding_string.to_s.b.downcase(:ascii))
598
669
  end
599
670
 
600
671
  REENCODE_DUMMY_ENCODINGS = {
@@ -5,8 +5,8 @@ require 'uri'
5
5
 
6
6
  module Rack
7
7
  class QueryParser
8
- DEFAULT_SEP = /& */n
9
- COMMON_SEP = { ";" => /; */n, ";," => /[;,] */n, "&" => /& */n }
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.
@@ -210,10 +210,17 @@ module Rack
210
210
  def params_hash_has_key?(hash, key)
211
211
  return false if /\[\]/.match?(key)
212
212
 
213
- key.split(/[\[\]]+/).inject(hash) do |h, part|
214
- next h if part == ''
215
- return false unless params_hash_type?(h) && h.key?(part)
216
- h[part]
213
+ # Equivalent to walking key.split(/[\[\]]+/), but a quantified regexp
214
+ # allocates backtracking state for every bracket matched, so find the
215
+ # segments with single character searches instead, which do not
216
+ # backtrack.
217
+ pos = 0
218
+ while (start = key.index(/[^\[\]]/, pos))
219
+ stop = key.index(/[\[\]]/, start) || key.length
220
+ part = key[start, stop - start]
221
+ return false unless params_hash_type?(hash) && hash.key?(part)
222
+ hash = hash[part]
223
+ pos = stop
217
224
  end
218
225
 
219
226
  true
@@ -226,7 +233,14 @@ module Rack
226
233
  raise QueryLimitError, "total query size exceeds limit (#{@bytesize_limit})"
227
234
  end
228
235
 
229
- pairs = qs.split(separator ? (COMMON_SEP[separator] || /[#{separator}] */n) : DEFAULT_SEP, @params_limit + 1)
236
+ pairs = qs.split(separator ? (COMMON_SEP[separator] || /[#{separator}]/n) : DEFAULT_SEP, @params_limit + 1)
237
+
238
+ # Remove spaces following the separator. A quantified regexp such as
239
+ # /& */ allocates backtracking state for every space matched, so find
240
+ # the first non-space character instead, which does not backtrack.
241
+ pairs.each do |pair|
242
+ pair.slice!(0, pair.index(/[^ ]/) || pair.length) if pair.getbyte(0) == 32
243
+ end
230
244
 
231
245
  if pairs.size > @params_limit
232
246
  param_count = pairs.size + pairs.last.count(separator || "&")
data/lib/rack/version.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  # See MIT-LICENSE or https://opensource.org/licenses/MIT.
7
7
 
8
8
  module Rack
9
- VERSION = "3.2.8"
9
+ VERSION = "3.2.9"
10
10
 
11
11
  RELEASE = VERSION
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.8
4
+ version: 3.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leah Neukirchen