rack 2.1.4.2 → 2.1.4.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edbcf6126aae323681d2fdc8e61fbbc036661d3354419ac07a389499c9f2f04a
4
- data.tar.gz: a1071b44bbf6fa93a58ad2739f9df6f9450666c18aa94e7c69b8e813f3c290a4
3
+ metadata.gz: c6c6bc44966ead6d6a9da2aaf2491e17ae23f2ad2a812ebca495b804a4574405
4
+ data.tar.gz: 7aa862a282ed242ed951ca59158e3078a05f19ea377009cd96e4dd09ebf5f513
5
5
  SHA512:
6
- metadata.gz: 555cbd0c544abc9102e68450e0e2f7a1a6a758adac673087562419bd85073b5d4130c6446349a1efb68f0cd13ae94863eb083d3e528ec12d6c9e0d71c7047dd1
7
- data.tar.gz: 6028521bbb96e209dde73311e30e614f680359ded81465bb23723a45ada328c661104a7487bf5cebc238831504a4e5f370a763769a4dd50d7df1b524da27c24d
6
+ metadata.gz: 5ce33f287708bb007eac0960c5ab16dadbc759bdea9266f0d3ca51c9d79bab83c815a6d8b73450cd1878f3a2e10cf26b1892304352b027bd7924c07ea1a28c31
7
+ data.tar.gz: 264d2812f22b99a85e83b65664d1d08380c1699384a21f3c144837f4a6449a5b3a05e3df3187b19082da4e6e51695dce23dc4e98f5463bb7361e34614286ff8d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [2.1.4.3] - 2023-03-02
2
+
3
+ - [CVE-2023-27530] Introduce multipart_total_part_limit to limit total parts
4
+
1
5
  ## [2.1.4.2] - 2022-01-17
2
6
 
3
7
  - [CVE-2022-44571] Fix ReDoS vulnerability in multipart parser
data/README.rdoc CHANGED
@@ -166,16 +166,30 @@ This helps prevent a rogue client from flooding a Request.
166
166
 
167
167
  Default to 65536 characters (4 kiB in worst case).
168
168
 
169
- === multipart_part_limit
169
+ === multipart_file_limit
170
170
 
171
- The maximum number of parts a request can contain.
171
+ The maximum number of parts with a filename a request can contain.
172
172
  Accepting too many part can lead to the server running out of file handles.
173
173
 
174
174
  The default is 128, which means that a single request can't upload more than 128 files at once.
175
175
 
176
176
  Set to 0 for no limit.
177
177
 
178
- Can also be set via the +RACK_MULTIPART_PART_LIMIT+ environment variable.
178
+ Can also be set via the +RACK_MULTIPART_FILE_LIMIT+ environment variable.
179
+
180
+ (This is also aliased as +multipart_part_limit+ and +RACK_MULTIPART_PART_LIMIT+ for compatibility)
181
+
182
+ === multipart_total_part_limit
183
+
184
+ The maximum total number of parts a request can contain of any type, including
185
+ both file and non-file form fields.
186
+
187
+ The default is 4096, which means that a single request can't contain more than
188
+ 4096 parts.
189
+
190
+ Set to 0 for no limit.
191
+
192
+ Can also be set via the +RACK_MULTIPART_TOTAL_PART_LIMIT+ environment variable.
179
193
 
180
194
  == Changelog
181
195
 
@@ -7,6 +7,7 @@ require 'rack/core_ext/regexp'
7
7
  module Rack
8
8
  module Multipart
9
9
  class MultipartPartLimitError < Errno::EMFILE; end
10
+ class MultipartTotalPartLimitError < StandardError; end
10
11
 
11
12
  class Parser
12
13
  using ::Rack::RegexpExtensions
@@ -148,7 +149,7 @@ module Rack
148
149
 
149
150
  @mime_parts[mime_index] = klass.new(body, head, filename, content_type, name)
150
151
 
151
- check_open_files
152
+ check_part_limits
152
153
  end
153
154
 
154
155
  def on_mime_body mime_index, content
@@ -160,13 +161,23 @@ module Rack
160
161
 
161
162
  private
162
163
 
163
- def check_open_files
164
- if Utils.multipart_part_limit > 0
165
- if @open_files >= Utils.multipart_part_limit
164
+ def check_part_limits
165
+ file_limit = Utils.multipart_file_limit
166
+ part_limit = Utils.multipart_total_part_limit
167
+
168
+ if file_limit && file_limit > 0
169
+ if @open_files >= file_limit
166
170
  @mime_parts.each(&:close)
167
171
  raise MultipartPartLimitError, 'Maximum file multiparts in content reached'
168
172
  end
169
173
  end
174
+
175
+ if part_limit && part_limit > 0
176
+ if @mime_parts.size >= part_limit
177
+ @mime_parts.each(&:close)
178
+ raise MultipartTotalPartLimitError, 'Maximum total multiparts in content reached'
179
+ end
180
+ end
170
181
  end
171
182
  end
172
183
 
data/lib/rack/utils.rb CHANGED
@@ -59,13 +59,24 @@ module Rack
59
59
  module_function :unescape
60
60
 
61
61
  class << self
62
- attr_accessor :multipart_part_limit
62
+ attr_accessor :multipart_total_part_limit
63
+
64
+ attr_accessor :multipart_file_limit
65
+
66
+ # multipart_part_limit is the original name of multipart_file_limit, but
67
+ # the limit only counts parts with filenames.
68
+ alias multipart_part_limit multipart_file_limit
69
+ alias multipart_part_limit= multipart_file_limit=
63
70
  end
64
71
 
65
- # The maximum number of parts a request can contain. Accepting too many part
66
- # can lead to the server running out of file handles.
72
+ # The maximum number of file parts a request can contain. Accepting too
73
+ # many parts can lead to the server running out of file handles.
67
74
  # Set to `0` for no limit.
68
- self.multipart_part_limit = (ENV['RACK_MULTIPART_PART_LIMIT'] || 128).to_i
75
+ self.multipart_file_limit = (ENV['RACK_MULTIPART_PART_LIMIT'] || ENV['RACK_MULTIPART_FILE_LIMIT'] || 128).to_i
76
+
77
+ # The maximum total number of parts a request can contain. Accepting too
78
+ # many can lead to excessive memory use and parsing time.
79
+ self.multipart_total_part_limit = (ENV['RACK_MULTIPART_TOTAL_PART_LIMIT'] || 4096).to_i
69
80
 
70
81
  def self.param_depth_limit
71
82
  default_query_parser.param_depth_limit
data/lib/rack.rb CHANGED
@@ -20,7 +20,7 @@ module Rack
20
20
  VERSION.join(".")
21
21
  end
22
22
 
23
- RELEASE = "2.1.4.2"
23
+ RELEASE = "2.1.4.3"
24
24
 
25
25
  # Return the Rack release as a dotted string.
26
26
  def self.release
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4.2
4
+ version: 2.1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leah Neukirchen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-17 00:00:00.000000000 Z
11
+ date: 2023-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  requirements: []
188
- rubygems_version: 3.1.6
188
+ rubygems_version: 3.4.1
189
189
  signing_key:
190
190
  specification_version: 4
191
191
  summary: a modular Ruby webserver interface