rack-protection 1.3.1 → 1.3.2

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

Potentially problematic release.


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

data/Rakefile CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
3
 
3
4
  begin
@@ -15,12 +16,14 @@ task 'rack-protection.gemspec' do
15
16
  require 'rack/protection/version'
16
17
  content = File.read 'rack-protection.gemspec'
17
18
 
19
+ # fetch data
18
20
  fields = {
19
21
  :authors => `git shortlog -sn`.scan(/[^\d\s].*/),
20
22
  :email => `git shortlog -sne`.scan(/[^<]+@[^>]+/),
21
23
  :files => `git ls-files`.split("\n").reject { |f| f =~ /^(\.|Gemfile)/ }
22
24
  }
23
25
 
26
+ # insert data
24
27
  fields.each do |field, values|
25
28
  updated = " s.#{field} = ["
26
29
  updated << values.map { |v| "\n %p" % v }.join(',')
@@ -28,7 +31,12 @@ task 'rack-protection.gemspec' do
28
31
  content.sub!(/ s\.#{field} = \[\n( .*\n)* \]/, updated)
29
32
  end
30
33
 
34
+ # set version
31
35
  content.sub! /(s\.version.*=\s+).*/, "\\1\"#{Rack::Protection::VERSION}\""
36
+
37
+ # escape unicode
38
+ content.gsub!(/./) { |c| c.bytesize > 1 ? "\\u{#{c.codepoints.first.to_s(16)}}" : c }
39
+
32
40
  File.open('rack-protection.gemspec', 'w') { |f| f << content }
33
41
  end
34
42
 
@@ -11,20 +11,20 @@ module Rack
11
11
  # Does not accept unsafe HTTP requests when value of Origin HTTP request header
12
12
  # does not match default or whitelisted URIs.
13
13
  class HttpOrigin < Base
14
+ DEFAULT_PORTS = { 'http' => 80, 'https' => 443, 'coffee' => 80 }
14
15
  default_reaction :deny
15
16
 
16
- def accepts?(env)
17
- # only for unsafe request methods
18
- safe?(env) and return true
19
- # ignore if origin is not set
20
- origin = env['HTTP_ORIGIN'] or return true
21
-
22
- # check base url
23
- Request.new(env).base_url == origin and return true
17
+ def base_url(env)
18
+ request = Rack::Request.new(env)
19
+ port = ":#{request.port}" unless request.port == DEFAULT_PORTS[request.scheme]
20
+ "#{request.scheme}://#{request.host}#{port}"
21
+ end
24
22
 
25
- # check whitelist
26
- options[:origin_whitelist] or return false
27
- options[:origin_whitelist].include?(origin)
23
+ def accepts?(env)
24
+ return true if safe? env
25
+ return true unless origin = env['HTTP_ORIGIN']
26
+ return true if base_url(env) == origin
27
+ Array(options[:origin_whitelist]).include? origin
28
28
  end
29
29
 
30
30
  end
@@ -4,7 +4,7 @@ module Rack
4
4
  VERSION
5
5
  end
6
6
 
7
- SIGNATURE = [1, 3, 1]
7
+ SIGNATURE = [1, 3, 2]
8
8
  VERSION = SIGNATURE.join('.')
9
9
 
10
10
  VERSION.extend Comparable
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |s|
3
3
  # general infos
4
4
  s.name = "rack-protection"
5
- s.version = "1.3.1"
5
+ s.version = "1.3.2"
6
6
  s.description = "You should use protection!"
7
7
  s.homepage = "http://github.com/rkh/rack-protection"
8
8
  s.summary = s.description
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
23
23
  "Steve Agalloco",
24
24
  "Akzhan Abdulin",
25
25
  "TOBY",
26
- "Bjørge Næss"
26
+ "Bj\u{f8}rge N\u{e6}ss"
27
27
  ]
28
28
 
29
29
  # generated from git shortlog -sne
@@ -1,5 +1,6 @@
1
1
  require 'rack/protection'
2
2
  require 'rack/test'
3
+ require 'rack'
3
4
  require 'forwardable'
4
5
  require 'stringio'
5
6
 
@@ -21,6 +22,10 @@ if version == "1.3"
21
22
  end
22
23
  end
23
24
 
25
+ unless Rack::MockResponse.method_defined? :header
26
+ Rack::MockResponse.send(:alias_method, :header, :headers)
27
+ end
28
+
24
29
  module DummyApp
25
30
  def self.call(env)
26
31
  Thread.current[:last_env] = env
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-protection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,7 +23,7 @@ authors:
23
23
  autorequire:
24
24
  bindir: bin
25
25
  cert_chain: []
26
- date: 2012-12-10 00:00:00.000000000 Z
26
+ date: 2012-12-12 00:00:00.000000000 Z
27
27
  dependencies:
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rack