rack-protection 1.3.1 → 1.3.2
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.
Potentially problematic release.
This version of rack-protection might be problematic. Click here for more details.
- data/Rakefile +8 -0
- data/lib/rack/protection/http_origin.rb +11 -11
- data/lib/rack/protection/version.rb +1 -1
- data/rack-protection.gemspec +2 -2
- data/spec/spec_helper.rb +5 -0
- metadata +2 -2
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
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
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
|
data/rack-protection.gemspec
CHANGED
@@ -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.
|
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
|
-
"
|
26
|
+
"Bj\u{f8}rge N\u{e6}ss"
|
27
27
|
]
|
28
28
|
|
29
29
|
# generated from git shortlog -sne
|
data/spec/spec_helper.rb
CHANGED
@@ -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.
|
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-
|
26
|
+
date: 2012-12-12 00:00:00.000000000 Z
|
27
27
|
dependencies:
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rack
|