rack-protection 1.5.2 → 2.0.0

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.
@@ -3,36 +3,50 @@ require 'rack'
3
3
 
4
4
  module Rack
5
5
  module Protection
6
- autoload :AuthenticityToken, 'rack/protection/authenticity_token'
7
- autoload :Base, 'rack/protection/base'
8
- autoload :EscapedParams, 'rack/protection/escaped_params'
9
- autoload :FormToken, 'rack/protection/form_token'
10
- autoload :FrameOptions, 'rack/protection/frame_options'
11
- autoload :HttpOrigin, 'rack/protection/http_origin'
12
- autoload :IPSpoofing, 'rack/protection/ip_spoofing'
13
- autoload :JsonCsrf, 'rack/protection/json_csrf'
14
- autoload :PathTraversal, 'rack/protection/path_traversal'
15
- autoload :RemoteReferrer, 'rack/protection/remote_referrer'
16
- autoload :RemoteToken, 'rack/protection/remote_token'
17
- autoload :SessionHijacking, 'rack/protection/session_hijacking'
18
- autoload :XSSHeader, 'rack/protection/xss_header'
6
+ autoload :AuthenticityToken, 'rack/protection/authenticity_token'
7
+ autoload :Base, 'rack/protection/base'
8
+ autoload :CookieTossing, 'rack/protection/cookie_tossing'
9
+ autoload :ContentSecurityPolicy, 'rack/protection/content_security_policy'
10
+ autoload :EscapedParams, 'rack/protection/escaped_params'
11
+ autoload :FormToken, 'rack/protection/form_token'
12
+ autoload :FrameOptions, 'rack/protection/frame_options'
13
+ autoload :HttpOrigin, 'rack/protection/http_origin'
14
+ autoload :IPSpoofing, 'rack/protection/ip_spoofing'
15
+ autoload :JsonCsrf, 'rack/protection/json_csrf'
16
+ autoload :PathTraversal, 'rack/protection/path_traversal'
17
+ autoload :RemoteReferrer, 'rack/protection/remote_referrer'
18
+ autoload :RemoteToken, 'rack/protection/remote_token'
19
+ autoload :SessionHijacking, 'rack/protection/session_hijacking'
20
+ autoload :StrictTransport, 'rack/protection/strict_transport'
21
+ autoload :XSSHeader, 'rack/protection/xss_header'
19
22
 
20
23
  def self.new(app, options = {})
21
24
  # does not include: RemoteReferrer, AuthenticityToken and FormToken
22
25
  except = Array options[:except]
23
26
  use_these = Array options[:use]
27
+
28
+ if options.fetch(:without_session, false)
29
+ except += [:session_hijacking, :remote_token]
30
+ end
31
+
24
32
  Rack::Builder.new do
25
- use ::Rack::Protection::RemoteReferrer, options if use_these.include? :remote_referrer
26
- use ::Rack::Protection::AuthenticityToken,options if use_these.include? :authenticity_token
27
- use ::Rack::Protection::FormToken, options if use_these.include? :form_token
28
- use ::Rack::Protection::FrameOptions, options unless except.include? :frame_options
29
- use ::Rack::Protection::HttpOrigin, options unless except.include? :http_origin
30
- use ::Rack::Protection::IPSpoofing, options unless except.include? :ip_spoofing
31
- use ::Rack::Protection::JsonCsrf, options unless except.include? :json_csrf
32
- use ::Rack::Protection::PathTraversal, options unless except.include? :path_traversal
33
- use ::Rack::Protection::RemoteToken, options unless except.include? :remote_token
34
- use ::Rack::Protection::SessionHijacking, options unless except.include? :session_hijacking
35
- use ::Rack::Protection::XSSHeader, options unless except.include? :xss_header
33
+ # Off by default, unless added
34
+ use ::Rack::Protection::AuthenticityToken, options if use_these.include? :authenticity_token
35
+ use ::Rack::Protection::CookieTossing, options if use_these.include? :cookie_tossing
36
+ use ::Rack::Protection::ContentSecurityPolicy, options if use_these.include? :content_security_policy
37
+ use ::Rack::Protection::FormToken, options if use_these.include? :form_token
38
+ use ::Rack::Protection::RemoteReferrer, options if use_these.include? :remote_referrer
39
+ use ::Rack::Protection::StrictTransport, options if use_these.include? :strict_transport
40
+
41
+ # On by default, unless skipped
42
+ use ::Rack::Protection::FrameOptions, options unless except.include? :frame_options
43
+ use ::Rack::Protection::HttpOrigin, options unless except.include? :http_origin
44
+ use ::Rack::Protection::IPSpoofing, options unless except.include? :ip_spoofing
45
+ use ::Rack::Protection::JsonCsrf, options unless except.include? :json_csrf
46
+ use ::Rack::Protection::PathTraversal, options unless except.include? :path_traversal
47
+ use ::Rack::Protection::RemoteToken, options unless except.include? :remote_token
48
+ use ::Rack::Protection::SessionHijacking, options unless except.include? :session_hijacking
49
+ use ::Rack::Protection::XSSHeader, options unless except.include? :xss_header
36
50
  run app
37
51
  end.to_app
38
52
  end
@@ -1,112 +1,25 @@
1
- # Run `rake rack-protection.gemspec` to update the gemspec.
1
+ version = File.read(File.expand_path("../../VERSION", __FILE__)).strip
2
+
2
3
  Gem::Specification.new do |s|
3
4
  # general infos
4
5
  s.name = "rack-protection"
5
- s.version = "1.5.2"
6
- s.description = "You should use protection!"
7
- s.homepage = "http://github.com/rkh/rack-protection"
6
+ s.version = version
7
+ s.description = "Protect against typical web attacks, works with all Rack apps, including Rails."
8
+ s.homepage = "http://github.com/sinatra/sinatra/tree/master/rack-protection"
8
9
  s.summary = s.description
9
10
  s.license = 'MIT'
10
-
11
- # generated from git shortlog -sn
12
- s.authors = [
13
- "Konstantin Haase",
14
- "Alex Rodionov",
15
- "Patrick Ellis",
16
- "ITO Nobuaki",
17
- "Matteo Centenaro",
18
- "Jeff Welling",
19
- "David Kellum",
20
- "Egor Homakov",
21
- "Florian Gilcher",
22
- "Fojas",
23
- "Mael Clerambault",
24
- "Martin Mauch",
25
- "Renne Nissinen",
26
- "SAKAI, Kazuaki",
27
- "Stanislav Savulchik",
28
- "Steve Agalloco",
29
- "TOBY",
30
- "Vipul A M",
31
- "Akzhan Abdulin",
32
- "brookemckim",
33
- "Bj\u00F8rge N\u00E6ss",
34
- "Chris Heald",
35
- "Chris Mytton",
36
- "Corey Ward",
37
- "Dario Cravero"
38
- ]
39
-
40
- # generated from git shortlog -sne
41
- s.email = [
42
- "konstantin.mailinglists@googlemail.com",
43
- "p0deje@gmail.com",
44
- "patrick@soundcloud.com",
45
- "jeff.welling@gmail.com",
46
- "daydream.trippers@gmail.com",
47
- "bugant@gmail.com",
48
- "homakov@gmail.com",
49
- "florian.gilcher@asquera.de",
50
- "developer@fojasaur.us",
51
- "mael@clerambault.fr",
52
- "martin.mauch@gmail.com",
53
- "rennex@iki.fi",
54
- "kaz.july.7@gmail.com",
55
- "s.savulchik@gmail.com",
56
- "steve.agalloco@gmail.com",
57
- "toby.net.info.mail+git@gmail.com",
58
- "vipulnsward@gmail.com",
59
- "akzhan.abdulin@gmail.com",
60
- "brooke@digitalocean.com",
61
- "bjoerge@bengler.no",
62
- "cheald@gmail.com",
63
- "self@hecticjeff.net",
64
- "coreyward@me.com",
65
- "dario@uxtemple.com",
66
- "dek-oss@gravitext.com"
67
- ]
68
-
69
- # generated from git ls-files
70
- s.files = [
11
+ s.authors = ["https://github.com/sinatra/sinatra/graphs/contributors"]
12
+ s.email = "sinatrarb@googlegroups.com"
13
+ s.files = Dir["lib/**/*.rb"] + [
71
14
  "License",
72
15
  "README.md",
73
16
  "Rakefile",
74
- "lib/rack-protection.rb",
75
- "lib/rack/protection.rb",
76
- "lib/rack/protection/authenticity_token.rb",
77
- "lib/rack/protection/base.rb",
78
- "lib/rack/protection/escaped_params.rb",
79
- "lib/rack/protection/form_token.rb",
80
- "lib/rack/protection/frame_options.rb",
81
- "lib/rack/protection/http_origin.rb",
82
- "lib/rack/protection/ip_spoofing.rb",
83
- "lib/rack/protection/json_csrf.rb",
84
- "lib/rack/protection/path_traversal.rb",
85
- "lib/rack/protection/remote_referrer.rb",
86
- "lib/rack/protection/remote_token.rb",
87
- "lib/rack/protection/session_hijacking.rb",
88
- "lib/rack/protection/version.rb",
89
- "lib/rack/protection/xss_header.rb",
90
- "rack-protection.gemspec",
91
- "spec/authenticity_token_spec.rb",
92
- "spec/base_spec.rb",
93
- "spec/escaped_params_spec.rb",
94
- "spec/form_token_spec.rb",
95
- "spec/frame_options_spec.rb",
96
- "spec/http_origin_spec.rb",
97
- "spec/ip_spoofing_spec.rb",
98
- "spec/json_csrf_spec.rb",
99
- "spec/path_traversal_spec.rb",
100
- "spec/protection_spec.rb",
101
- "spec/remote_referrer_spec.rb",
102
- "spec/remote_token_spec.rb",
103
- "spec/session_hijacking_spec.rb",
104
- "spec/spec_helper.rb",
105
- "spec/xss_header_spec.rb"
17
+ "Gemfile",
18
+ "rack-protection.gemspec"
106
19
  ]
107
20
 
108
21
  # dependencies
109
22
  s.add_dependency "rack"
110
23
  s.add_development_dependency "rack-test"
111
- s.add_development_dependency "rspec", "~> 2.0"
24
+ s.add_development_dependency "rspec", "~> 3.0.0"
112
25
  end
metadata CHANGED
@@ -1,112 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-protection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Konstantin Haase
8
- - Alex Rodionov
9
- - Patrick Ellis
10
- - ITO Nobuaki
11
- - Matteo Centenaro
12
- - Jeff Welling
13
- - David Kellum
14
- - Egor Homakov
15
- - Florian Gilcher
16
- - Fojas
17
- - Mael Clerambault
18
- - Martin Mauch
19
- - Renne Nissinen
20
- - SAKAI, Kazuaki
21
- - Stanislav Savulchik
22
- - Steve Agalloco
23
- - TOBY
24
- - Vipul A M
25
- - Akzhan Abdulin
26
- - brookemckim
27
- - Bjørge Næss
28
- - Chris Heald
29
- - Chris Mytton
30
- - Corey Ward
31
- - Dario Cravero
7
+ - https://github.com/sinatra/sinatra/graphs/contributors
32
8
  autorequire:
33
9
  bindir: bin
34
10
  cert_chain: []
35
- date: 2014-01-15 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
36
12
  dependencies:
37
13
  - !ruby/object:Gem::Dependency
38
14
  name: rack
39
15
  requirement: !ruby/object:Gem::Requirement
40
16
  requirements:
41
- - - '>='
17
+ - - ">="
42
18
  - !ruby/object:Gem::Version
43
19
  version: '0'
44
20
  type: :runtime
45
21
  prerelease: false
46
22
  version_requirements: !ruby/object:Gem::Requirement
47
23
  requirements:
48
- - - '>='
24
+ - - ">="
49
25
  - !ruby/object:Gem::Version
50
26
  version: '0'
51
27
  - !ruby/object:Gem::Dependency
52
28
  name: rack-test
53
29
  requirement: !ruby/object:Gem::Requirement
54
30
  requirements:
55
- - - '>='
31
+ - - ">="
56
32
  - !ruby/object:Gem::Version
57
33
  version: '0'
58
34
  type: :development
59
35
  prerelease: false
60
36
  version_requirements: !ruby/object:Gem::Requirement
61
37
  requirements:
62
- - - '>='
38
+ - - ">="
63
39
  - !ruby/object:Gem::Version
64
40
  version: '0'
65
41
  - !ruby/object:Gem::Dependency
66
42
  name: rspec
67
43
  requirement: !ruby/object:Gem::Requirement
68
44
  requirements:
69
- - - ~>
45
+ - - "~>"
70
46
  - !ruby/object:Gem::Version
71
- version: '2.0'
47
+ version: 3.0.0
72
48
  type: :development
73
49
  prerelease: false
74
50
  version_requirements: !ruby/object:Gem::Requirement
75
51
  requirements:
76
- - - ~>
52
+ - - "~>"
77
53
  - !ruby/object:Gem::Version
78
- version: '2.0'
79
- description: You should use protection!
80
- email:
81
- - konstantin.mailinglists@googlemail.com
82
- - p0deje@gmail.com
83
- - patrick@soundcloud.com
84
- - jeff.welling@gmail.com
85
- - daydream.trippers@gmail.com
86
- - bugant@gmail.com
87
- - homakov@gmail.com
88
- - florian.gilcher@asquera.de
89
- - developer@fojasaur.us
90
- - mael@clerambault.fr
91
- - martin.mauch@gmail.com
92
- - rennex@iki.fi
93
- - kaz.july.7@gmail.com
94
- - s.savulchik@gmail.com
95
- - steve.agalloco@gmail.com
96
- - toby.net.info.mail+git@gmail.com
97
- - vipulnsward@gmail.com
98
- - akzhan.abdulin@gmail.com
99
- - brooke@digitalocean.com
100
- - bjoerge@bengler.no
101
- - cheald@gmail.com
102
- - self@hecticjeff.net
103
- - coreyward@me.com
104
- - dario@uxtemple.com
105
- - dek-oss@gravitext.com
54
+ version: 3.0.0
55
+ description: Protect against typical web attacks, works with all Rack apps, including
56
+ Rails.
57
+ email: sinatrarb@googlegroups.com
106
58
  executables: []
107
59
  extensions: []
108
60
  extra_rdoc_files: []
109
61
  files:
62
+ - Gemfile
110
63
  - License
111
64
  - README.md
112
65
  - Rakefile
@@ -114,6 +67,8 @@ files:
114
67
  - lib/rack/protection.rb
115
68
  - lib/rack/protection/authenticity_token.rb
116
69
  - lib/rack/protection/base.rb
70
+ - lib/rack/protection/content_security_policy.rb
71
+ - lib/rack/protection/cookie_tossing.rb
117
72
  - lib/rack/protection/escaped_params.rb
118
73
  - lib/rack/protection/form_token.rb
119
74
  - lib/rack/protection/frame_options.rb
@@ -124,25 +79,11 @@ files:
124
79
  - lib/rack/protection/remote_referrer.rb
125
80
  - lib/rack/protection/remote_token.rb
126
81
  - lib/rack/protection/session_hijacking.rb
82
+ - lib/rack/protection/strict_transport.rb
127
83
  - lib/rack/protection/version.rb
128
84
  - lib/rack/protection/xss_header.rb
129
85
  - rack-protection.gemspec
130
- - spec/authenticity_token_spec.rb
131
- - spec/base_spec.rb
132
- - spec/escaped_params_spec.rb
133
- - spec/form_token_spec.rb
134
- - spec/frame_options_spec.rb
135
- - spec/http_origin_spec.rb
136
- - spec/ip_spoofing_spec.rb
137
- - spec/json_csrf_spec.rb
138
- - spec/path_traversal_spec.rb
139
- - spec/protection_spec.rb
140
- - spec/remote_referrer_spec.rb
141
- - spec/remote_token_spec.rb
142
- - spec/session_hijacking_spec.rb
143
- - spec/spec_helper.rb
144
- - spec/xss_header_spec.rb
145
- homepage: http://github.com/rkh/rack-protection
86
+ homepage: http://github.com/sinatra/sinatra/tree/master/rack-protection
146
87
  licenses:
147
88
  - MIT
148
89
  metadata: {}
@@ -152,18 +93,19 @@ require_paths:
152
93
  - lib
153
94
  required_ruby_version: !ruby/object:Gem::Requirement
154
95
  requirements:
155
- - - '>='
96
+ - - ">="
156
97
  - !ruby/object:Gem::Version
157
98
  version: '0'
158
99
  required_rubygems_version: !ruby/object:Gem::Requirement
159
100
  requirements:
160
- - - '>='
101
+ - - ">="
161
102
  - !ruby/object:Gem::Version
162
103
  version: '0'
163
104
  requirements: []
164
105
  rubyforge_project:
165
- rubygems_version: 2.2.0
106
+ rubygems_version: 2.6.11
166
107
  signing_key:
167
108
  specification_version: 4
168
- summary: You should use protection!
109
+ summary: Protect against typical web attacks, works with all Rack apps, including
110
+ Rails.
169
111
  test_files: []
@@ -1,48 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::AuthenticityToken do
4
- it_behaves_like "any rack application"
5
-
6
- it "denies post requests without any token" do
7
- post('/').should_not be_ok
8
- end
9
-
10
- it "accepts post requests with correct X-CSRF-Token header" do
11
- post('/', {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "a")
12
- last_response.should be_ok
13
- end
14
-
15
- it "denies post requests with wrong X-CSRF-Token header" do
16
- post('/', {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "b")
17
- last_response.should_not be_ok
18
- end
19
-
20
- it "accepts post form requests with correct authenticity_token field" do
21
- post('/', {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"})
22
- last_response.should be_ok
23
- end
24
-
25
- it "denies post form requests with wrong authenticity_token field" do
26
- post('/', {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"})
27
- last_response.should_not be_ok
28
- end
29
-
30
- it "prevents ajax requests without a valid token" do
31
- post('/', {}, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest").should_not be_ok
32
- end
33
-
34
- it "allows for a custom authenticity token param" do
35
- mock_app do
36
- use Rack::Protection::AuthenticityToken, :authenticity_param => 'csrf_param'
37
- run proc { |e| [200, {'Content-Type' => 'text/plain'}, ['hi']] }
38
- end
39
-
40
- post('/', {"csrf_param" => "a"}, 'rack.session' => {:csrf => "a"})
41
- last_response.should be_ok
42
- end
43
-
44
- it "sets a new csrf token for the session in env, even after a 'safe' request" do
45
- get('/', {}, {})
46
- env['rack.session'][:csrf].should_not be_nil
47
- end
48
- end
data/spec/base_spec.rb DELETED
@@ -1,9 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::Base do
4
- describe "#random_string" do
5
- it "outputs a string of 32 characters" do
6
- described_class.new(lambda {}).random_string.length.should == 32
7
- end
8
- end
9
- end
@@ -1,43 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::EscapedParams do
4
- it_behaves_like "any rack application"
5
-
6
- context 'escaping' do
7
- it 'escapes html entities' do
8
- mock_app do |env|
9
- request = Rack::Request.new(env)
10
- [200, {'Content-Type' => 'text/plain'}, [request.params['foo']]]
11
- end
12
- get '/', :foo => "<bar>"
13
- body.should == '&lt;bar&gt;'
14
- end
15
-
16
- it 'leaves normal params untouched' do
17
- mock_app do |env|
18
- request = Rack::Request.new(env)
19
- [200, {'Content-Type' => 'text/plain'}, [request.params['foo']]]
20
- end
21
- get '/', :foo => "bar"
22
- body.should == 'bar'
23
- end
24
-
25
- it 'copes with nested arrays' do
26
- mock_app do |env|
27
- request = Rack::Request.new(env)
28
- [200, {'Content-Type' => 'text/plain'}, [request.params['foo']['bar']]]
29
- end
30
- get '/', :foo => {:bar => "<bar>"}
31
- body.should == '&lt;bar&gt;'
32
- end
33
-
34
- it 'leaves cache-breaker params untouched' do
35
- mock_app do |env|
36
- [200, {'Content-Type' => 'text/plain'}, ['hi']]
37
- end
38
-
39
- get '/?95df8d9bf5237ad08df3115ee74dcb10'
40
- body.should == 'hi'
41
- end
42
- end
43
- end
@@ -1,33 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::FormToken do
4
- it_behaves_like "any rack application"
5
-
6
- it "denies post requests without any token" do
7
- post('/').should_not be_ok
8
- end
9
-
10
- it "accepts post requests with correct X-CSRF-Token header" do
11
- post('/', {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "a")
12
- last_response.should be_ok
13
- end
14
-
15
- it "denies post requests with wrong X-CSRF-Token header" do
16
- post('/', {}, 'rack.session' => {:csrf => "a"}, 'HTTP_X_CSRF_TOKEN' => "b")
17
- last_response.should_not be_ok
18
- end
19
-
20
- it "accepts post form requests with correct authenticity_token field" do
21
- post('/', {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"})
22
- last_response.should be_ok
23
- end
24
-
25
- it "denies post form requests with wrong authenticity_token field" do
26
- post('/', {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"})
27
- last_response.should_not be_ok
28
- end
29
-
30
- it "accepts ajax requests without a valid token" do
31
- post('/', {}, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest").should be_ok
32
- end
33
- end
@@ -1,39 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::FrameOptions do
4
- it_behaves_like "any rack application"
5
-
6
- it 'should set the X-Frame-Options' do
7
- get('/', {}, 'wants' => 'text/html').headers["X-Frame-Options"].should == "SAMEORIGIN"
8
- end
9
-
10
- it 'should not set the X-Frame-Options for other content types' do
11
- get('/', {}, 'wants' => 'text/foo').headers["X-Frame-Options"].should be_nil
12
- end
13
-
14
- it 'should allow changing the protection mode' do
15
- # I have no clue what other modes are available
16
- mock_app do
17
- use Rack::Protection::FrameOptions, :frame_options => :deny
18
- run DummyApp
19
- end
20
-
21
- get('/', {}, 'wants' => 'text/html').headers["X-Frame-Options"].should == "DENY"
22
- end
23
-
24
-
25
- it 'should allow changing the protection mode to a string' do
26
- # I have no clue what other modes are available
27
- mock_app do
28
- use Rack::Protection::FrameOptions, :frame_options => "ALLOW-FROM foo"
29
- run DummyApp
30
- end
31
-
32
- get('/', {}, 'wants' => 'text/html').headers["X-Frame-Options"].should == "ALLOW-FROM foo"
33
- end
34
-
35
- it 'should not override the header if already set' do
36
- mock_app with_headers("X-Frame-Options" => "allow")
37
- get('/', {}, 'wants' => 'text/html').headers["X-Frame-Options"].should == "allow"
38
- end
39
- end
@@ -1,38 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::HttpOrigin do
4
- it_behaves_like "any rack application"
5
-
6
- before(:each) do
7
- mock_app do
8
- use Rack::Protection::HttpOrigin
9
- run DummyApp
10
- end
11
- end
12
-
13
- %w(GET HEAD POST PUT DELETE).each do |method|
14
- it "accepts #{method} requests with no Origin" do
15
- send(method.downcase, '/').should be_ok
16
- end
17
- end
18
-
19
- %w(GET HEAD).each do |method|
20
- it "accepts #{method} requests with non-whitelisted Origin" do
21
- send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://malicious.com').should be_ok
22
- end
23
- end
24
-
25
- %w(POST PUT DELETE).each do |method|
26
- it "denies #{method} requests with non-whitelisted Origin" do
27
- send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://malicious.com').should_not be_ok
28
- end
29
-
30
- it "accepts #{method} requests with whitelisted Origin" do
31
- mock_app do
32
- use Rack::Protection::HttpOrigin, :origin_whitelist => ['http://www.friend.com']
33
- run DummyApp
34
- end
35
- send(method.downcase, '/', {}, 'HTTP_ORIGIN' => 'http://www.friend.com').should be_ok
36
- end
37
- end
38
- end
@@ -1,35 +0,0 @@
1
- require File.expand_path('../spec_helper.rb', __FILE__)
2
-
3
- describe Rack::Protection::IPSpoofing do
4
- it_behaves_like "any rack application"
5
-
6
- it 'accepts requests without X-Forward-For header' do
7
- get('/', {}, 'HTTP_CLIENT_IP' => '1.2.3.4', 'HTTP_X_REAL_IP' => '4.3.2.1')
8
- last_response.should be_ok
9
- end
10
-
11
- it 'accepts requests with proper X-Forward-For header' do
12
- get('/', {}, 'HTTP_CLIENT_IP' => '1.2.3.4',
13
- 'HTTP_X_FORWARDED_FOR' => '192.168.1.20, 1.2.3.4, 127.0.0.1')
14
- last_response.should be_ok
15
- end
16
-
17
- it 'denies requests where the client spoofs X-Forward-For but not the IP' do
18
- get('/', {}, 'HTTP_CLIENT_IP' => '1.2.3.4', 'HTTP_X_FORWARDED_FOR' => '1.2.3.5')
19
- last_response.should_not be_ok
20
- end
21
-
22
- it 'denies requests where the client spoofs the IP but not X-Forward-For' do
23
- get('/', {}, 'HTTP_CLIENT_IP' => '1.2.3.5',
24
- 'HTTP_X_FORWARDED_FOR' => '192.168.1.20, 1.2.3.4, 127.0.0.1')
25
- last_response.should_not be_ok
26
- end
27
-
28
- it 'denies requests where IP and X-Forward-For are spoofed but not X-Real-IP' do
29
- get('/', {},
30
- 'HTTP_CLIENT_IP' => '1.2.3.5',
31
- 'HTTP_X_FORWARDED_FOR' => '1.2.3.5',
32
- 'HTTP_X_REAL_IP' => '1.2.3.4')
33
- last_response.should_not be_ok
34
- end
35
- end