rack 1.3.5 → 1.3.6

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.

@@ -373,6 +373,10 @@ run on port 11211) and memcache-client installed.
373
373
  * October 17, 2011: Twentieth public release 1.3.5
374
374
  * Fix annoying warnings caused by the backport in 1.3.4
375
375
 
376
+ * December 28th, 2011: Twenty third public release: 1.3.6
377
+ * Security fix. http://www.ocert.org/advisories/ocert-2011-003.html
378
+ Further information here: http://jruby.org/2011/12/27/jruby-1-6-5-1
379
+
376
380
  == Contact
377
381
 
378
382
  Please post bugs, suggestions and patches to
@@ -14,6 +14,9 @@ module Rack
14
14
 
15
15
  fast_forward_to_first_boundary
16
16
 
17
+ max_key_space = Utils.key_space_limit
18
+ bytes = 0
19
+
17
20
  loop do
18
21
  head, filename, content_type, name, body =
19
22
  get_current_head_and_filename_and_content_type_and_name_and_body
@@ -28,6 +31,13 @@ module Rack
28
31
 
29
32
  filename, data = get_data(filename, body, content_type, name, head)
30
33
 
34
+ if name
35
+ bytes += name.size
36
+ if bytes > max_key_space
37
+ raise RangeError, "exceeded available parameter key space"
38
+ end
39
+ end
40
+
31
41
  Utils.normalize_params(@params, name, data) unless data.nil?
32
42
 
33
43
  # break if we're at the end of a buffer, but not if it is the end of a field
@@ -40,6 +40,14 @@ module Rack
40
40
 
41
41
  DEFAULT_SEP = /[&;] */n
42
42
 
43
+ class << self
44
+ attr_accessor :key_space_limit
45
+ end
46
+
47
+ # The default number of bytes to allow parameter keys to take up.
48
+ # This helps prevent a rogue client from flooding a Request.
49
+ self.key_space_limit = 65536
50
+
43
51
  # Stolen from Mongrel, with some small modifications:
44
52
  # Parses a query string by breaking it up at the '&'
45
53
  # and ';' characters. You can also use this to parse
@@ -48,8 +56,19 @@ module Rack
48
56
  def parse_query(qs, d = nil)
49
57
  params = {}
50
58
 
59
+ max_key_space = Utils.key_space_limit
60
+ bytes = 0
61
+
51
62
  (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
52
63
  k, v = p.split('=', 2).map { |x| unescape(x) }
64
+
65
+ if k
66
+ bytes += k.size
67
+ if bytes > max_key_space
68
+ raise RangeError, "exceeded available parameter key space"
69
+ end
70
+ end
71
+
53
72
  if cur = params[k]
54
73
  if cur.class == Array
55
74
  params[k] << v
@@ -68,8 +87,19 @@ module Rack
68
87
  def parse_nested_query(qs, d = nil)
69
88
  params = {}
70
89
 
90
+ max_key_space = Utils.key_space_limit
91
+ bytes = 0
92
+
71
93
  (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
72
94
  k, v = p.split('=', 2).map { |s| unescape(s) }
95
+
96
+ if k
97
+ bytes += k.size
98
+ if bytes > max_key_space
99
+ raise RangeError, "exceeded available parameter key space"
100
+ end
101
+ end
102
+
73
103
  normalize_params(params, k, v)
74
104
  end
75
105
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack"
3
- s.version = "1.3.5"
3
+ s.version = "1.3.6"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "a modular Ruby webserver interface"
6
6
 
@@ -30,6 +30,17 @@ describe Rack::Multipart do
30
30
  params["text"].should.equal "contents"
31
31
  end
32
32
 
33
+ should "raise RangeError if the key space is exhausted" do
34
+ env = Rack::MockRequest.env_for("/", multipart_fixture(:content_type_and_no_filename))
35
+
36
+ old, Rack::Utils.key_space_limit = Rack::Utils.key_space_limit, 1
37
+ begin
38
+ lambda { Rack::Multipart.parse_multipart(env) }.should.raise(RangeError)
39
+ ensure
40
+ Rack::Utils.key_space_limit = old
41
+ end
42
+ end
43
+
33
44
  should "parse multipart form webkit style" do
34
45
  env = Rack::MockRequest.env_for '/', multipart_fixture(:webkit)
35
46
  env['CONTENT_TYPE'] = "multipart/form-data; boundary=----WebKitFormBoundaryWLHCs9qmcJJoyjKR"
@@ -125,6 +125,18 @@ describe Rack::Request do
125
125
  req.params.should.equal "foo" => "bar", "quux" => "bla"
126
126
  end
127
127
 
128
+ should "limit the keys from the GET query string" do
129
+ env = Rack::MockRequest.env_for("/?foo=bar")
130
+
131
+ old, Rack::Utils.key_space_limit = Rack::Utils.key_space_limit, 1
132
+ begin
133
+ req = Rack::Request.new(env)
134
+ lambda { req.GET }.should.raise(RangeError)
135
+ ensure
136
+ Rack::Utils.key_space_limit = old
137
+ end
138
+ end
139
+
128
140
  should "not unify GET and POST when calling params" do
129
141
  mr = Rack::MockRequest.env_for("/?foo=quux",
130
142
  "REQUEST_METHOD" => 'POST',
@@ -157,6 +169,20 @@ describe Rack::Request do
157
169
  req.params.should.equal "foo" => "bar", "quux" => "bla"
158
170
  end
159
171
 
172
+ should "limit the keys from the POST form data" do
173
+ env = Rack::MockRequest.env_for("",
174
+ "REQUEST_METHOD" => 'POST',
175
+ :input => "foo=bar&quux=bla")
176
+
177
+ old, Rack::Utils.key_space_limit = Rack::Utils.key_space_limit, 1
178
+ begin
179
+ req = Rack::Request.new(env)
180
+ lambda { req.POST }.should.raise(RangeError)
181
+ ensure
182
+ Rack::Utils.key_space_limit = old
183
+ end
184
+ end
185
+
160
186
  should "parse POST data with explicit content type regardless of method" do
161
187
  req = Rack::Request.new \
162
188
  Rack::MockRequest.env_for("/",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 5
10
- version: 1.3.5
9
+ - 6
10
+ version: 1.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Neukirchen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-18 00:00:00 Z
18
+ date: 2011-12-28 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bacon
@@ -306,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
306
  requirements: []
307
307
 
308
308
  rubyforge_project: rack
309
- rubygems_version: 1.8.11
309
+ rubygems_version: 1.8.12
310
310
  signing_key:
311
311
  specification_version: 3
312
312
  summary: a modular Ruby webserver interface