rack 3.1.8 → 3.1.16

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: cd9b9438930771f3687ff42be3f3506df2faeea5d947d8ed4fa9e5eec1b5970c
4
- data.tar.gz: 170b7d3e30e472e5a5403f9bb889f37b60e4e9eced41e94f97a88d848e5c2fb4
3
+ metadata.gz: 9cfb0a3abaaa98c515919466c018ed20c30b3f4d025d0ec68cfc61614735270f
4
+ data.tar.gz: 4fd015b49d2c70a01d6518ea38b593d14b6d93de09132c3142390ab5fd719ff2
5
5
  SHA512:
6
- metadata.gz: 0a5c0c56cda8181c7ec4e87a348b54a22938d4c450a9647fbbf07aaec37282ff89230d3964ba0dfd9f5bc7f7e60d99eaf704636de143704c5e9156120bd04624
7
- data.tar.gz: eeef987e1c6dc77ff1fc40e5cc0e37bde704d354c62217a834e6a4d36828900a71dac09e591a9743273fc5ea678bf603d36c3e165f9c7dbfa1759301c42f957f
6
+ metadata.gz: db64e3a6431f22b41af6ec7a31d38465d4db45612843f402692893665d88c904d4058469137372b208dbc6d79d7dcde12460e4fb7707681d81de8d3a6dc8e45f
7
+ data.tar.gz: 695b14f7308dfb1a6be5304fb9bcf460ee855e296308ad114d8b9f12b9dcb420a17d4af3883f3a47f3fc66df2e28793fe4871965dec51b557840d136de14c22c
data/CHANGELOG.md CHANGED
@@ -2,8 +2,48 @@
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.15] - 2025-05-18
6
+
7
+ - Optional support for `CGI::Cookie` if not available. ([#2327](https://github.com/rack/rack/pull/2327), [#2333](https://github.com/rack/rack/pull/2333), [@earlopain])
8
+
9
+ ## [3.1.14] - 2025-05-06
10
+
11
+ ### Security
12
+
13
+ - [CVE-2025-46727](https://github.com/rack/rack/security/advisories/GHSA-gjh7-p2fx-99vx) Unbounded parameter parsing in `Rack::QueryParser` can lead to memory exhaustion.
14
+
15
+ ## [3.1.13] - 2025-04-13
16
+
17
+ - Ensure `Rack::ETag` correctly updates response body. ([#2324](https://github.com/rack/rack/pull/2324), [@ioquatix])
18
+
19
+ ## [3.1.12] - 2025-03-11
20
+
21
+ ### Security
22
+
23
+ - [CVE-2025-27610](https://github.com/rack/rack/security/advisories/GHSA-7wqh-767x-r66v) Local file inclusion in `Rack::Static`.
24
+
25
+ ## [3.1.11] - 2025-03-04
26
+
27
+ ### Security
28
+
29
+ - [CVE-2025-27111](https://github.com/rack/rack/security/advisories/GHSA-8cgq-6mh2-7j6v) Possible Log Injection in `Rack::Sendfile`.
30
+
31
+ ## [3.1.10] - 2025-02-12
32
+
33
+ ### Security
34
+
35
+ - [CVE-2025-25184](https://github.com/rack/rack/security/advisories/GHSA-7g2v-jj9q-g3rg) Possible Log Injection in `Rack::CommonLogger`.
36
+
37
+ ## [3.1.9] - 2025-01-31
38
+
39
+ ### Fixed
40
+
41
+ - `Rack::MediaType#params` now handles parameters without values. ([#2263](https://github.com/rack/rack/pull/2263), [@AllyMarthaJ](https://github.com/AllyMarthaJ))
42
+
5
43
  ## [3.1.8] - 2024-10-14
6
44
 
45
+ ### Fixed
46
+
7
47
  - Resolve deprecation warnings about uri `DEFAULT_PARSER`. ([#2249](https://github.com/rack/rack/pull/2249), [@earlopain])
8
48
 
9
49
  ## [3.1.7] - 2024-07-11
@@ -103,6 +143,46 @@ Rack v3.1 is primarily a maintenance release that removes features deprecated in
103
143
 
104
144
  - In `Rack::Files`, ignore the `Range` header if served file is 0 bytes. ([#2159](https://github.com/rack/rack/pull/2159), [@zarqman])
105
145
 
146
+ ## [3.0.18] - 2025-05-22
147
+
148
+ - Fix incorrect backport of optional `CGI::Cookie` support. ([#2335](https://github.com/rack/rack/pull/2335), [@jeremyevans])
149
+
150
+ ## [3.0.17] - 2025-05-18
151
+
152
+ - Optional support for `CGI::Cookie` if not available. ([#2327](https://github.com/rack/rack/pull/2327), [#2333](https://github.com/rack/rack/pull/2333), [@earlopain])
153
+
154
+ ## [3.0.16] - 2025-05-06
155
+
156
+ ### Security
157
+
158
+ - [CVE-2025-46727](https://github.com/rack/rack/security/advisories/GHSA-gjh7-p2fx-99vx) Unbounded parameter parsing in `Rack::QueryParser` can lead to memory exhaustion.
159
+
160
+ ## [3.0.15] - 2025-04-13
161
+
162
+ - Ensure `Rack::ETag` correctly updates response body. ([#2324](https://github.com/rack/rack/pull/2324), [@ioquatix])
163
+
164
+ ## [3.0.14] - 2025-03-11
165
+
166
+ ### Security
167
+
168
+ - [CVE-2025-27610](https://github.com/rack/rack/security/advisories/GHSA-7wqh-767x-r66v) Local file inclusion in `Rack::Static`.
169
+
170
+ ## [3.0.13] - 2025-03-04
171
+
172
+ ### Security
173
+
174
+ - [CVE-2025-27111](https://github.com/rack/rack/security/advisories/GHSA-8cgq-6mh2-7j6v) Possible Log Injection in `Rack::Sendfile`.
175
+
176
+ ### Fixed
177
+
178
+ - Remove autoloads for constants no longer shipped with Rack. ([#2269](https://github.com/rack/rack/pull/2269), [@ccutrer](https://github.com/ccutrer))
179
+
180
+ ## [3.0.12] - 2025-02-12
181
+
182
+ ### Security
183
+
184
+ - [CVE-2025-25184](https://github.com/rack/rack/security/advisories/GHSA-7g2v-jj9q-g3rg) Possible Log Injection in `Rack::CommonLogger`.
185
+
106
186
  ## [3.0.11] - 2024-05-10
107
187
 
108
188
  - Backport #2062 to 3-0-stable: Do not allow `BodyProxy` to respond to `to_str`, make `to_ary` call close . ([#2062](https://github.com/rack/rack/pull/2062), [@jeremyevans](https://github.com/jeremyevans))
@@ -231,7 +311,7 @@ Rack v3.1 is primarily a maintenance release that removes features deprecated in
231
311
  - Remove deprecated Rack::Request::SCHEME_WHITELIST. ([@jeremyevans])
232
312
  - Remove internal cookie deletion using pattern matching, there are very few practical cases where it would be useful and browsers handle it correctly without us doing anything special. ([#1844](https://github.com/rack/rack/pull/1844), [@ioquatix])
233
313
  - Remove `rack.version` as it comes too late to be useful. ([#1938](https://github.com/rack/rack/pull/1938), [@ioquatix])
234
- - Extract `rackup` command, `Rack::Server`, `Rack::Handler`, `Rack::Lobster` and related code into a separate gem. ([#1937](https://github.com/rack/rack/pull/1937), [@ioquatix])
314
+ - Extract `rackup` command, `Rack::Server`, `Rack::Handler` and related code into a separate gem. ([#1937](https://github.com/rack/rack/pull/1937), [@ioquatix])
235
315
 
236
316
  ### Added
237
317
 
@@ -279,6 +359,84 @@ Rack v3.1 is primarily a maintenance release that removes features deprecated in
279
359
  - 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))
280
360
  - `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))
281
361
 
362
+ ## [2.2.16] - 2025-05-22
363
+
364
+ - Fix incorrect backport of optional `CGI::Cookie` support. ([#2335](https://github.com/rack/rack/pull/2335), [@jeremyevans])
365
+
366
+ ## [2.2.15] - 2025-05-18
367
+
368
+ - Optional support for `CGI::Cookie` if not available. ([#2327](https://github.com/rack/rack/pull/2327), [#2333](https://github.com/rack/rack/pull/2333), [@earlopain])
369
+
370
+ ## [2.2.14] - 2025-05-06
371
+
372
+ ### Security
373
+
374
+ - [CVE-2025-46727](https://github.com/rack/rack/security/advisories/GHSA-gjh7-p2fx-99vx) Unbounded parameter parsing in `Rack::QueryParser` can lead to memory exhaustion.
375
+
376
+ ## [2.2.13] - 2025-03-11
377
+
378
+ ### Security
379
+
380
+ - [CVE-2025-27610](https://github.com/rack/rack/security/advisories/GHSA-7wqh-767x-r66v) Local file inclusion in `Rack::Static`.
381
+
382
+ ## [2.2.12] - 2025-03-04
383
+
384
+ ### Security
385
+
386
+ - [CVE-2025-27111](https://github.com/rack/rack/security/advisories/GHSA-8cgq-6mh2-7j6v) Possible Log Injection in `Rack::Sendfile`.
387
+
388
+ ## [2.2.11] - 2025-02-12
389
+
390
+ ### Security
391
+
392
+ - [CVE-2025-25184](https://github.com/rack/rack/security/advisories/GHSA-7g2v-jj9q-g3rg) Possible Log Injection in `Rack::CommonLogger`.
393
+
394
+ ## [2.2.10] - 2024-10-14
395
+
396
+ - Fix compatibility issues with Ruby v3.4.0. ([#2248](https://github.com/rack/rack/pull/2248), [@byroot](https://github.com/byroot))
397
+
398
+ ## [2.2.9] - 2023-03-21
399
+
400
+ - Return empty when parsing a multi-part POST with only one end delimiter. ([#2104](https://github.com/rack/rack/pull/2104), [@alpaca-tc])
401
+
402
+ ## [2.2.8] - 2023-07-31
403
+
404
+ - Regenerate SPEC ([#2102](https://github.com/rack/rack/pull/2102), [@skipkayhil](https://github.com/skipkayhil))
405
+ - Limit file extension length of multipart tempfiles ([#2015](https://github.com/rack/rack/pull/2015), [@dentarg](https://github.com/dentarg))
406
+ - Fix "undefined method DelegateClass for Rack::Session::Cookie:Class" ([#2092](https://github.com/rack/rack/pull/2092), [@onigra](https://github.com/onigra) [@dchandekstark](https://github.com/dchandekstark))
407
+
408
+ ## [2.2.7] - 2023-03-13
409
+
410
+ - Correct the year number in the changelog ([#2015](https://github.com/rack/rack/pull/2015), [@kimulab](https://github.com/kimulab))
411
+ - Support underscore in host names for Rack 2.2 (Fixes [#2070](https://github.com/rack/rack/issues/2070)) ([#2015](https://github.com/rack/rack/pull/2071), [@jeremyevans](https://github.com/jeremyevans))
412
+
413
+ ## [2.2.6.4] - 2023-03-13
414
+
415
+ - [CVE-2023-27539] Avoid ReDoS in header parsing
416
+
417
+ ## [2.2.6.3] - 2023-03-02
418
+
419
+ - [CVE-2023-27530] Introduce multipart_total_part_limit to limit total parts
420
+
421
+ ## [2.2.6.2] - 2023-01-17
422
+
423
+ - [CVE-2022-44570] Fix ReDoS in Rack::Utils.get_byte_ranges
424
+
425
+ ## [2.2.6.1] - 2023-01-17
426
+
427
+ - [CVE-2022-44571] Fix ReDoS vulnerability in multipart parser
428
+ - [CVE-2022-44572] Forbid control characters in attributes (also ReDoS)
429
+
430
+ ## [2.2.6] - 2023-01-17
431
+
432
+ - Extend `Rack::MethodOverride` to handle `QueryParser::ParamsTooDeepError` error. ([#2011](https://github.com/rack/rack/pull/2011), [@byroot](https://github.com/byroot))
433
+
434
+ ## [2.2.5] - 2022-12-27
435
+
436
+ ### Fixed
437
+
438
+ - `Rack::URLMap` uses non-deprecated form of `Regexp.new`. ([#1998](https://github.com/rack/rack/pull/1998), [@weizheheng](https://github.com/weizheheng))
439
+
282
440
  ## [2.2.4] - 2022-06-30
283
441
 
284
442
  - Better support for lower case headers in `Rack::ETag` middleware. ([#1919](https://github.com/rack/rack/pull/1919), [@ioquatix](https://github.com/ioquatix))
@@ -996,3 +1154,4 @@ Items below this line are from the previously maintained HISTORY.md and NEWS.md
996
1154
  [@wjordan]: https://github.com/wjordan "Will Jordan"
997
1155
  [@BlakeWilliams]: https://github.com/BlakeWilliams "Blake Williams"
998
1156
  [@davidstosik]: https://github.com/davidstosik "David Stosik"
1157
+ [@earlopain]: https://github.com/earlopain "Earlopain"
data/README.md CHANGED
@@ -183,6 +183,33 @@ quickly and without doing the same web stuff all over:
183
183
  Rack exposes several configuration parameters to control various features of the
184
184
  implementation.
185
185
 
186
+ ### `RACK_QUERY_PARSER_BYTESIZE_LIMIT`
187
+
188
+ This environment variable sets the default for the maximum query string bytesize
189
+ that `Rack::QueryParser` will attempt to parse. Attempts to use a query string
190
+ that exceeds this number of bytes will result in a
191
+ `Rack::QueryParser::QueryLimitError` exception. If this enviroment variable is
192
+ provided, it must be an integer, or `Rack::QueryParser` will raise an exception.
193
+
194
+ The default limit can be overridden on a per-`Rack::QueryParser` basis using
195
+ the `bytesize_limit` keyword argument when creating the `Rack::QueryParser`.
196
+
197
+ ### `RACK_QUERY_PARSER_PARAMS_LIMIT`
198
+
199
+ This environment variable sets the default for the maximum number of query
200
+ parameters that `Rack::QueryParser` will attempt to parse. Attempts to use a
201
+ query string with more than this many query parameters will result in a
202
+ `Rack::QueryParser::QueryLimitError` exception. If this enviroment variable is
203
+ provided, it must be an integer, or `Rack::QueryParser` will raise an exception.
204
+
205
+ The default limit can be overridden on a per-`Rack::QueryParser` basis using
206
+ the `params_limit` keyword argument when creating the `Rack::QueryParser`.
207
+
208
+ This is implemented by counting the number of parameter separators in the
209
+ query string, before attempting parsing, so if the same parameter key is
210
+ used multiple times in the query, each counts as a separate parameter for
211
+ this check.
212
+
186
213
  ### `param_depth_limit`
187
214
 
188
215
  ```ruby
@@ -20,7 +20,7 @@ module Rack
20
20
  # The actual format is slightly different than the above due to the
21
21
  # separation of SCRIPT_NAME and PATH_INFO, and because the elapsed
22
22
  # time in seconds is included at the end.
23
- FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %d %s %0.4f\n}
23
+ FORMAT = %{%s - %s [%s] "%s %s%s%s %s" %d %s %0.4f }
24
24
 
25
25
  # +logger+ can be any object that supports the +write+ or +<<+ methods,
26
26
  # which includes the standard library Logger. These methods are called
@@ -66,7 +66,8 @@ module Rack
66
66
  length,
67
67
  Utils.clock_time - began_at)
68
68
 
69
- msg.gsub!(/[^[:print:]\n]/) { |c| sprintf("\\x%x", c.ord) }
69
+ msg.gsub!(/[^[:print:]]/) { |c| sprintf("\\x%x", c.ord) }
70
+ msg[-1] = "\n"
70
71
 
71
72
  logger = @logger || request.get_header(RACK_ERRORS)
72
73
  # Standard library logger doesn't support write but it supports << which actually
data/lib/rack/etag.rb CHANGED
@@ -32,6 +32,9 @@ module Rack
32
32
  body = body.to_ary
33
33
  digest = digest_body(body)
34
34
  headers[ETAG_STRING] = %(W/"#{digest}") if digest
35
+
36
+ # Body was modified, so we need to re-assign it:
37
+ response[2] = body
35
38
  end
36
39
 
37
40
  unless headers[CACHE_CONTROL]
@@ -27,6 +27,11 @@ module Rack
27
27
  # provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8",
28
28
  # this method responds with the following Hash:
29
29
  # { 'charset' => 'utf-8' }
30
+ #
31
+ # This will pass back parameters with empty strings in the hash if they
32
+ # lack a value (e.g., "text/plain;charset=" will return { 'charset' => '' },
33
+ # and "text/plain;charset" will return { 'charset' => '' }, similarly to
34
+ # the query params parser (barring the latter case, which returns nil instead)).
30
35
  def params(content_type)
31
36
  return {} if content_type.nil?
32
37
 
@@ -40,9 +45,9 @@ module Rack
40
45
 
41
46
  private
42
47
 
43
- def strip_doublequotes(str)
44
- (str.start_with?('"') && str.end_with?('"')) ? str[1..-2] : str
45
- end
48
+ def strip_doublequotes(str)
49
+ (str && str.start_with?('"') && str.end_with?('"')) ? str[1..-2] : str || ''
50
+ end
46
51
  end
47
52
  end
48
53
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'cgi/cookie'
4
3
  require 'time'
5
4
 
6
5
  require_relative 'response'
@@ -11,6 +10,36 @@ module Rack
11
10
  # MockRequest.
12
11
 
13
12
  class MockResponse < Rack::Response
13
+ begin
14
+ # Recent versions of the CGI gem may not provide `CGI::Cookie`.
15
+ require 'cgi/cookie'
16
+ Cookie = CGI::Cookie
17
+ rescue LoadError
18
+ class Cookie
19
+ attr_reader :name, :value, :path, :domain, :expires, :secure
20
+
21
+ def initialize(args)
22
+ @name = args["name"]
23
+ @value = args["value"]
24
+ @path = args["path"]
25
+ @domain = args["domain"]
26
+ @expires = args["expires"]
27
+ @secure = args["secure"]
28
+ end
29
+
30
+ def method_missing(method_name, *args, &block)
31
+ @value.send(method_name, *args, &block)
32
+ end
33
+ # :nocov:
34
+ ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
35
+ # :nocov:
36
+
37
+ def respond_to_missing?(method_name, include_all = false)
38
+ @value.respond_to?(method_name, include_all) || super
39
+ end
40
+ end
41
+ end
42
+
14
43
  class << self
15
44
  alias [] new
16
45
  end
@@ -83,7 +112,7 @@ module Rack
83
112
  Array(set_cookie_header).each do |cookie|
84
113
  cookie_name, cookie_filling = cookie.split('=', 2)
85
114
  cookie_attributes = identify_cookie_attributes cookie_filling
86
- parsed_cookie = CGI::Cookie.new(
115
+ parsed_cookie = Cookie.new(
87
116
  'name' => cookie_name.strip,
88
117
  'value' => cookie_attributes.fetch('value'),
89
118
  'path' => cookie_attributes.fetch('path', nil),
@@ -100,7 +129,7 @@ module Rack
100
129
  def identify_cookie_attributes(cookie_filling)
101
130
  cookie_bits = cookie_filling.split(';')
102
131
  cookie_attributes = Hash.new
103
- cookie_attributes.store('value', cookie_bits[0].strip)
132
+ cookie_attributes.store('value', Array(cookie_bits[0].strip))
104
133
  cookie_bits.drop(1).each do |bit|
105
134
  if bit.include? '='
106
135
  cookie_attribute, attribute_value = bit.split('=', 2)
@@ -31,10 +31,12 @@ module Rack
31
31
  Error = BoundaryTooLongError
32
32
 
33
33
  EOL = "\r\n"
34
+ FWS = /[ \t]+(?:\r\n[ \t]+)?/ # whitespace with optional folding
35
+ HEADER_VALUE = "(?:[^\r\n]|\r\n[ \t])*" # anything but a non-folding CRLF
34
36
  MULTIPART = %r|\Amultipart/.*boundary=\"?([^\";,]+)\"?|ni
35
- MULTIPART_CONTENT_TYPE = /Content-Type: (.*)#{EOL}/ni
36
- MULTIPART_CONTENT_DISPOSITION = /Content-Disposition:(.*)(?=#{EOL}(\S|\z))/ni
37
- MULTIPART_CONTENT_ID = /Content-ID:\s*([^#{EOL}]*)/ni
37
+ MULTIPART_CONTENT_TYPE = /^Content-Type:#{FWS}?(#{HEADER_VALUE})/ni
38
+ MULTIPART_CONTENT_DISPOSITION = /^Content-Disposition:#{FWS}?(#{HEADER_VALUE})/ni
39
+ MULTIPART_CONTENT_ID = /^Content-ID:#{FWS}?(#{HEADER_VALUE})/ni
38
40
 
39
41
  class Parser
40
42
  BUFSIZE = 1_048_576
@@ -21,21 +21,47 @@ module Rack
21
21
  include BadRequest
22
22
  end
23
23
 
24
- # ParamsTooDeepError is the error that is raised when params are recursively
25
- # nested over the specified limit.
26
- class ParamsTooDeepError < RangeError
24
+ # QueryLimitError is for errors raised when the query provided exceeds one
25
+ # of the query parser limits.
26
+ class QueryLimitError < RangeError
27
27
  include BadRequest
28
28
  end
29
29
 
30
- def self.make_default(param_depth_limit)
31
- new Params, param_depth_limit
30
+ # ParamsTooDeepError is the old name for the error that is raised when params
31
+ # are recursively nested over the specified limit. Make it the same as
32
+ # as QueryLimitError, so that code that rescues ParamsTooDeepError error
33
+ # to handle bad query strings also now handles other limits.
34
+ ParamsTooDeepError = QueryLimitError
35
+
36
+ def self.make_default(param_depth_limit, **options)
37
+ new(Params, param_depth_limit, **options)
32
38
  end
33
39
 
34
40
  attr_reader :param_depth_limit
35
41
 
36
- def initialize(params_class, param_depth_limit)
42
+ env_int = lambda do |key, val|
43
+ if str_val = ENV[key]
44
+ begin
45
+ val = Integer(str_val, 10)
46
+ rescue ArgumentError
47
+ raise ArgumentError, "non-integer value provided for environment variable #{key}"
48
+ end
49
+ end
50
+
51
+ val
52
+ end
53
+
54
+ BYTESIZE_LIMIT = env_int.call("RACK_QUERY_PARSER_BYTESIZE_LIMIT", 4194304)
55
+ private_constant :BYTESIZE_LIMIT
56
+
57
+ PARAMS_LIMIT = env_int.call("RACK_QUERY_PARSER_PARAMS_LIMIT", 4096)
58
+ private_constant :PARAMS_LIMIT
59
+
60
+ def initialize(params_class, param_depth_limit, bytesize_limit: BYTESIZE_LIMIT, params_limit: PARAMS_LIMIT)
37
61
  @params_class = params_class
38
62
  @param_depth_limit = param_depth_limit
63
+ @bytesize_limit = bytesize_limit
64
+ @params_limit = params_limit
39
65
  end
40
66
 
41
67
  # Stolen from Mongrel, with some small modifications:
@@ -47,7 +73,7 @@ module Rack
47
73
 
48
74
  params = make_params
49
75
 
50
- (qs || '').split(separator ? (COMMON_SEP[separator] || /[#{separator}] */n) : DEFAULT_SEP).each do |p|
76
+ check_query_string(qs, separator).split(separator ? (COMMON_SEP[separator] || /[#{separator}] */n) : DEFAULT_SEP).each do |p|
51
77
  next if p.empty?
52
78
  k, v = p.split('=', 2).map!(&unescaper)
53
79
 
@@ -74,7 +100,7 @@ module Rack
74
100
  params = make_params
75
101
 
76
102
  unless qs.nil? || qs.empty?
77
- (qs || '').split(separator ? (COMMON_SEP[separator] || /[#{separator}] */n) : DEFAULT_SEP).each do |p|
103
+ check_query_string(qs, separator).split(separator ? (COMMON_SEP[separator] || /[#{separator}] */n) : DEFAULT_SEP).each do |p|
78
104
  k, v = p.split('=', 2).map! { |s| unescape(s) }
79
105
 
80
106
  _normalize_params(params, k, v, 0)
@@ -189,6 +215,22 @@ module Rack
189
215
  true
190
216
  end
191
217
 
218
+ def check_query_string(qs, sep)
219
+ if qs
220
+ if qs.bytesize > @bytesize_limit
221
+ raise QueryLimitError, "total query size (#{qs.bytesize}) exceeds limit (#{@bytesize_limit})"
222
+ end
223
+
224
+ if (param_count = qs.count(sep.is_a?(String) ? sep : '&')) >= @params_limit
225
+ raise QueryLimitError, "total number of query parameters (#{param_count+1}) exceeds limit (#{@params_limit})"
226
+ end
227
+
228
+ qs
229
+ else
230
+ ''
231
+ end
232
+ end
233
+
192
234
  def unescape(string, encoding = Encoding::UTF_8)
193
235
  URI.decode_www_form_component(string, encoding)
194
236
  end
data/lib/rack/sendfile.rb CHANGED
@@ -138,7 +138,7 @@ module Rack
138
138
  end
139
139
  when '', nil
140
140
  else
141
- env[RACK_ERRORS].puts "Unknown x-sendfile variation: '#{type}'.\n"
141
+ env[RACK_ERRORS].puts "Unknown x-sendfile variation: #{type.inspect}"
142
142
  end
143
143
  end
144
144
  response
data/lib/rack/static.rb CHANGED
@@ -124,8 +124,9 @@ module Rack
124
124
 
125
125
  def call(env)
126
126
  path = env[PATH_INFO]
127
+ actual_path = Utils.clean_path_info(Utils.unescape_path(path))
127
128
 
128
- if can_serve(path)
129
+ if can_serve(actual_path)
129
130
  if overwrite_file_path(path)
130
131
  env[PATH_INFO] = (add_index_root?(path) ? path + @index : @urls[path])
131
132
  elsif @gzip && env['HTTP_ACCEPT_ENCODING'] && /\bgzip\b/.match?(env['HTTP_ACCEPT_ENCODING'])
data/lib/rack/version.rb CHANGED
@@ -12,7 +12,7 @@
12
12
  # so it should be enough just to <tt>require 'rack'</tt> in your code.
13
13
 
14
14
  module Rack
15
- RELEASE = "3.1.8"
15
+ RELEASE = "3.1.16"
16
16
 
17
17
  # Return the Rack release as a dotted string.
18
18
  def self.release
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.8
4
+ version: 3.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leah Neukirchen
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-14 00:00:00.000000000 Z
10
+ date: 2025-06-04 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: minitest
@@ -143,7 +142,6 @@ metadata:
143
142
  changelog_uri: https://github.com/rack/rack/blob/main/CHANGELOG.md
144
143
  documentation_uri: https://rubydoc.info/github/rack/rack
145
144
  source_code_uri: https://github.com/rack/rack
146
- post_install_message:
147
145
  rdoc_options: []
148
146
  require_paths:
149
147
  - lib
@@ -158,8 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
156
  - !ruby/object:Gem::Version
159
157
  version: '0'
160
158
  requirements: []
161
- rubygems_version: 3.5.11
162
- signing_key:
159
+ rubygems_version: 3.6.2
163
160
  specification_version: 4
164
161
  summary: A modular Ruby webserver interface.
165
162
  test_files: []