rack 1.2.3 → 1.2.4

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.

data/README CHANGED
@@ -341,6 +341,9 @@ run on port 11211) and memcache-client installed.
341
341
  * Pulled in relevant bug fixes from 1.3
342
342
  * Fixed 1.8.6 support
343
343
 
344
+ * September 16, 2011: Eighteenth public release 1.2.4
345
+ * Fix a bug with MRI regex engine to prevent XSS by malformed unicode
346
+
344
347
  == Contact
345
348
 
346
349
  Please post bugs, suggestions and patches to
@@ -365,6 +368,8 @@ The Rack Core Team, consisting of
365
368
  * Michael Fellinger (manveru)
366
369
  * Ryan Tomayko (rtomayko)
367
370
  * Scytrin dai Kinthra (scytrin)
371
+ * Aaron Patterson (tenderlove)
372
+ * Konstantin Haase (rkh)
368
373
 
369
374
  would like to thank:
370
375
 
@@ -46,16 +46,15 @@ module Rack
46
46
  # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
47
47
  #
48
48
  # proxy_set_header X-Sendfile-Type X-Accel-Redirect;
49
- # proxy_set_header X-Accel-Mapping /files/=/var/www/;
49
+ # proxy_set_header X-Accel-Mapping /var/www/=/files/;
50
50
  #
51
51
  # proxy_pass http://127.0.0.1:8080/;
52
52
  # }
53
53
  #
54
54
  # Note that the X-Sendfile-Type header must be set exactly as shown above. The
55
- # X-Accel-Mapping header should specify the name of the private URL pattern,
56
- # followed by an equals sign (=), followed by the location on the file system
57
- # that it maps to. The middleware performs a simple substitution on the
58
- # resulting path.
55
+ # X-Accel-Mapping header should specify the internal URI path, followed by an
56
+ # equals sign (=), followed name of the location in the file system that it maps
57
+ # to. The middleware performs a simple substitution on the resulting path.
59
58
  #
60
59
  # See Also: http://wiki.codemongers.com/NginxXSendfile
61
60
  #
@@ -134,8 +134,15 @@ module Rack
134
134
  ">" => ">",
135
135
  "'" => "'",
136
136
  '"' => """,
137
+ "/" => "/"
137
138
  }
138
- ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)
139
+ if //.respond_to?(:encoding)
140
+ ESCAPE_HTML_PATTERN = Regexp.union(*ESCAPE_HTML.keys)
141
+ else
142
+ # On 1.8, there is a kcode = 'u' bug that allows for XSS otherwhise
143
+ # TODO doesn't apply to jruby, so a better condition above might be preferable?
144
+ ESCAPE_HTML_PATTERN = /#{Regexp.union(*ESCAPE_HTML.keys)}/n
145
+ end
139
146
 
140
147
  # Escape ampersands, brackets and quotes to their HTML/XML entities.
141
148
  def escape_html(string)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rack"
3
- s.version = "1.2.3"
3
+ s.version = "1.2.4"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = "a modular Ruby webserver interface"
6
6
 
@@ -2,6 +2,14 @@ require 'rack/utils'
2
2
  require 'rack/mock'
3
3
 
4
4
  describe Rack::Utils do
5
+ def kcodeu
6
+ one8 = RUBY_VERSION.to_f < 1.9
7
+ default_kcode, $KCODE = $KCODE, 'U' if one8
8
+ yield
9
+ ensure
10
+ $KCODE = default_kcode if one8
11
+ end
12
+
5
13
  should "escape correctly" do
6
14
  Rack::Utils.escape("fo<o>bar").should.equal "fo%3Co%3Ebar"
7
15
  Rack::Utils.escape("a space").should.equal "a+space"
@@ -18,6 +26,38 @@ describe Rack::Utils do
18
26
  Rack::Utils.escape(matz_name_sep).should.equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8'
19
27
  end
20
28
 
29
+ if RUBY_VERSION[/^\d+\.\d+/] == '1.8'
30
+ should "escape correctly for multibyte characters if $KCODE is set to 'U'" do
31
+ kcodeu do
32
+ matz_name = "\xE3\x81\xBE\xE3\x81\xA4\xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsumoto
33
+ matz_name.force_encoding("UTF-8") if matz_name.respond_to? :force_encoding
34
+ Rack::Utils.escape(matz_name).should.equal '%E3%81%BE%E3%81%A4%E3%82%82%E3%81%A8'
35
+ matz_name_sep = "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0] # Matsu moto
36
+ matz_name_sep.force_encoding("UTF-8") if matz_name_sep.respond_to? :force_encoding
37
+ Rack::Utils.escape(matz_name_sep).should.equal '%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8'
38
+ end
39
+ end
40
+
41
+ should "unescape multibyte characters correctly if $KCODE is set to 'U'" do
42
+ kcodeu do
43
+ Rack::Utils.unescape('%E3%81%BE%E3%81%A4+%E3%82%82%E3%81%A8').should.equal(
44
+ "\xE3\x81\xBE\xE3\x81\xA4 \xE3\x82\x82\xE3\x81\xA8".unpack("a*")[0])
45
+ end
46
+ end
47
+ end
48
+
49
+ should "escape objects that responds to to_s" do
50
+ kcodeu do
51
+ Rack::Utils.escape(:id).should.equal "id"
52
+ end
53
+ end
54
+
55
+ if "".respond_to?(:encode)
56
+ should "escape non-UTF8 strings" do
57
+ Rack::Utils.escape("ø".encode("ISO-8859-1")).should.equal "%F8"
58
+ end
59
+ end
60
+
21
61
  should "unescape correctly" do
22
62
  Rack::Utils.unescape("fo%3Co%3Ebar").should.equal "fo<o>bar"
23
63
  Rack::Utils.unescape("a+space").should.equal "a space"
@@ -175,6 +215,38 @@ describe Rack::Utils do
175
215
  message.should.equal "value must be a Hash"
176
216
  end
177
217
 
218
+ should "escape html entities [&><'\"/]" do
219
+ Rack::Utils.escape_html("foo").should.equal "foo"
220
+ Rack::Utils.escape_html("f&o").should.equal "f&amp;o"
221
+ Rack::Utils.escape_html("f<o").should.equal "f&lt;o"
222
+ Rack::Utils.escape_html("f>o").should.equal "f&gt;o"
223
+ Rack::Utils.escape_html("f'o").should.equal "f&#39;o"
224
+ Rack::Utils.escape_html('f"o').should.equal "f&quot;o"
225
+ Rack::Utils.escape_html("f/o").should.equal "f&#47;o"
226
+ Rack::Utils.escape_html("<foo></foo>").should.equal "&lt;foo&gt;&lt;&#47;foo&gt;"
227
+ end
228
+
229
+ should "escape html entities even on MRI when it's bugged" do
230
+ test_escape = lambda do
231
+ kcodeu do
232
+ Rack::Utils.escape_html("\300<").should.equal "\300&lt;"
233
+ end
234
+ end
235
+
236
+ if RUBY_VERSION.to_f < 1.9
237
+ test_escape.call
238
+ else
239
+ test_escape.should.raise(ArgumentError)
240
+ end
241
+ end
242
+
243
+ if "".respond_to?(:encode)
244
+ should "escape html entities in unicode strings" do
245
+ # the following will cause warnings if the regex is poorly encoded:
246
+ Rack::Utils.escape_html("☃").should.equal "☃"
247
+ end
248
+ end
249
+
178
250
  should "figure out which encodings are acceptable" do
179
251
  helper = lambda do |a, b|
180
252
  request = Rack::Request.new(Rack::MockRequest.env_for("", "HTTP_ACCEPT_ENCODING" => a))
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 2
9
- - 3
10
- version: 1.2.3
9
+ - 4
10
+ version: 1.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Neukirchen
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-23 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-09-16 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: bacon
@@ -256,7 +255,6 @@ files:
256
255
  - Rakefile
257
256
  - README
258
257
  - SPEC
259
- has_rdoc: true
260
258
  homepage: http://rack.rubyforge.org
261
259
  licenses: []
262
260
 
@@ -286,7 +284,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
284
  requirements: []
287
285
 
288
286
  rubyforge_project: rack
289
- rubygems_version: 1.5.2
287
+ rubygems_version: 1.8.10
290
288
  signing_key:
291
289
  specification_version: 3
292
290
  summary: a modular Ruby webserver interface