rack_csrf 2.4.0 → 2.7.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.
- checksums.yaml +7 -0
- data/.circleci/config.yml +30 -0
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/ci.yml +35 -0
- data/.gitignore +5 -0
- data/Changelog.md +28 -0
- data/Gemfile +2 -12
- data/LICENSE.rdoc +1 -1
- data/README.rdoc +18 -6
- data/Rakefile +11 -33
- data/examples/camping/Gemfile +2 -0
- data/examples/camping/app.rb +1 -3
- data/examples/cuba/Gemfile +1 -0
- data/examples/cuba/app.rb +2 -0
- data/examples/cuba/config-with-raise.ru +1 -2
- data/examples/cuba/config.ru +1 -2
- data/examples/innate/Gemfile +1 -0
- data/examples/innate/start-with-raise.rb +1 -3
- data/examples/innate/start.rb +1 -3
- data/examples/rack/Gemfile +2 -1
- data/examples/rack/app.rb +8 -3
- data/examples/rack/config-with-raise.ru +1 -2
- data/examples/rack/config.ru +1 -2
- data/examples/sinatra/Gemfile +2 -1
- data/examples/sinatra/app.rb +4 -2
- data/examples/sinatra/config-with-raise.ru +1 -4
- data/examples/sinatra/config.ru +1 -4
- data/features/step_definitions/request_steps.rb +7 -7
- data/features/step_definitions/response_steps.rb +5 -5
- data/features/step_definitions/setup_steps.rb +20 -14
- data/features/support/env.rb +2 -0
- data/features/support/fake_session.rb +2 -1
- data/lib/rack/csrf/version.rb +5 -0
- data/lib/rack/csrf.rb +36 -22
- data/rack_csrf.gemspec +39 -112
- data/spec/csrf_spec.rb +90 -43
- data/spec/spec_helper.rb +1 -0
- metadata +150 -142
- data/VERSION +0 -1
- data/lib/rack/vendor/securerandom.rb +0 -256
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5063e661614ec782c33a22dc458d7f6a6d89be5a59c6c08297bc1cdc2f9675aa
|
4
|
+
data.tar.gz: 4b2b7c1208e605a314ddcb581268b32eb214bb791be52d7875bc37e2b1258abf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21e09bf5ee433e1c9feea3ed29de30e7ff05c3a3c9d6bca35b2feeea8c0686e203c4c4f01fdff11eee8029b4094f32f26a9965b6918e03e5137b5db0eaafd61d
|
7
|
+
data.tar.gz: fa1aaa6fa9002de2519566b07aeb542fc91a1f0824030db83f384f182971a36c9b78fbf463a09230f17f116d6d7cd2e1347f97a65102c801cd557dfd404e59f0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
jobs:
|
4
|
+
run_tests:
|
5
|
+
parameters:
|
6
|
+
ruby_version:
|
7
|
+
description: "Version of Ruby to run tests in"
|
8
|
+
type: string
|
9
|
+
rack_version:
|
10
|
+
description: "More or less the Rack version we want to test against"
|
11
|
+
type: string
|
12
|
+
environment:
|
13
|
+
TEST_WITH_RACK: << parameters.rack_version >>
|
14
|
+
docker:
|
15
|
+
- image: ruby:<< parameters.ruby_version >>
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
- run: bundle install
|
19
|
+
- run: bundle exec rake spec
|
20
|
+
- run: bundle exec rake features
|
21
|
+
|
22
|
+
workflows:
|
23
|
+
version: 2
|
24
|
+
test:
|
25
|
+
jobs:
|
26
|
+
- run_tests:
|
27
|
+
matrix:
|
28
|
+
parameters:
|
29
|
+
ruby_version: ["2.7", "3.0", "3.1"]
|
30
|
+
rack_version: ["1.6.0", "2.1.0", "2.2.0", "3.0.0"]
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
- pull_request
|
5
|
+
- push
|
6
|
+
- workflow_dispatch
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
tests:
|
13
|
+
strategy:
|
14
|
+
matrix:
|
15
|
+
ruby_version:
|
16
|
+
- "2.7"
|
17
|
+
- "3.0"
|
18
|
+
- "3.1"
|
19
|
+
rack_version:
|
20
|
+
- "1.6.0"
|
21
|
+
- "2.1.0"
|
22
|
+
- "2.2.0"
|
23
|
+
- "3.0.0"
|
24
|
+
name: Ruby ~> ${{ matrix.ruby_version }}; Rack ~> ${{ matrix.rack_version }}
|
25
|
+
runs-on: ubuntu-latest
|
26
|
+
env:
|
27
|
+
TEST_WITH_RACK: ${{ matrix.rack_version }}
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v3
|
30
|
+
- uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby_version }}
|
33
|
+
bundler-cache: true
|
34
|
+
- run: bundle exec rake spec
|
35
|
+
- run: bundle exec rake features
|
data/Changelog.md
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
# v2.7.0 (2022-09-10)
|
2
|
+
|
3
|
+
Many little, negligible, changes, plus support for Rake 3 (courtesy of
|
4
|
+
[jeremyevans](https://github.com/jeremyevans) :trophy:)
|
5
|
+
|
6
|
+
# v2.6.0 (2016-12-31)
|
7
|
+
|
8
|
+
Many little, internal, changes; the important ones are:
|
9
|
+
|
10
|
+
* switched to use SecureRandom.urlsafe_base64 to make the token URL-friendly
|
11
|
+
(courtesy of [steved](https://github.com/steved));
|
12
|
+
* code is tested against Rack 1.4, 1.5, 1.6 and 2.0;
|
13
|
+
* code is tested only on Ruby 2.0.0 and later.
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
# v2.5.0 (2014-06-15)
|
18
|
+
|
19
|
+
* Fixed/improved the examples.
|
20
|
+
* Added basic Travis setup.
|
21
|
+
* Dropped support for Rack versions older than 1.1.0.
|
22
|
+
* Lazy generation of the CSRF token.
|
23
|
+
* Left Jeweler; totally embraced Bundler.
|
24
|
+
* Dropped support for Ruby 1.8.6.
|
25
|
+
* Fixed Cucumber's step for Ruby 1.8.*.
|
26
|
+
|
27
|
+
|
28
|
+
|
1
29
|
# v2.4.0 (2012-02-28)
|
2
30
|
|
3
31
|
* Updated examples' Gemfiles.
|
data/Gemfile
CHANGED
@@ -1,12 +1,2 @@
|
|
1
|
-
source '
|
2
|
-
|
3
|
-
gem 'rack', '>= 0.9'
|
4
|
-
|
5
|
-
group :development do
|
6
|
-
gem 'bundler', '>= 1.0.0'
|
7
|
-
gem 'cucumber', '>= 1.1.1'
|
8
|
-
gem 'rack-test'
|
9
|
-
gem 'rspec', '>= 2.0.0'
|
10
|
-
gem 'rdoc', '>= 2.4.2'
|
11
|
-
gem 'jeweler'
|
12
|
-
end
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
gemspec
|
data/LICENSE.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
(The MIT License)
|
4
4
|
|
5
|
-
Copyright (c) 2009, 2010, 2011, 2012 Emanuele Vicentini
|
5
|
+
Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016, 2022 Emanuele Vicentini
|
6
6
|
|
7
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
8
|
of this software and associated documentation files (the 'Software'), to deal
|
data/README.rdoc
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Rack::Csrf
|
1
|
+
= Rack::Csrf {<img src="https://circleci.com/gh/baldowl/rack_csrf.svg?style=svg" alt="CircleCI" />}[https://circleci.com/gh/baldowl/rack_csrf] {<img src="https://github.com/baldowl/rack_csrf/actions/workflows/ci.yml/badge.svg?branch=master" alt="Actions Status: CI" />}[https://github.com/baldowl/rack_csrf/actions?query=workflow%3ACI+branch%3Amaster] {<img src="https://badge.fury.io/rb/rack_csrf.svg" alt="Gem Version" />}[http://badge.fury.io/rb/rack_csrf]
|
2
2
|
|
3
3
|
This is just a small Rack middleware whose only goal is to lessen the hazards
|
4
4
|
posed by CSRF attacks by trying to ensure that all requests of particular
|
@@ -20,9 +20,6 @@ immediately replies with an empty response.
|
|
20
20
|
|
21
21
|
The anti-forging token can be passed as a request parameter or a header.
|
22
22
|
|
23
|
-
I have not tested Rack::Csrf with Rack 0.4.0 or earlier versions, but it could
|
24
|
-
possibly work.
|
25
|
-
|
26
23
|
== Options
|
27
24
|
|
28
25
|
The following options allow you to tweak Rack::Csrf.
|
@@ -79,6 +76,9 @@ The following options allow you to tweak Rack::Csrf.
|
|
79
76
|
This option is useful if a guarded resource can be accessed by clients who
|
80
77
|
support CSRF token (e.g. browsers) and by ones who don't (e.g. API clients).
|
81
78
|
|
79
|
+
Don't try to check the CSRF token: it could exist or not at this stage and
|
80
|
+
you should always let it alone.
|
81
|
+
|
82
82
|
Default value: empty.
|
83
83
|
|
84
84
|
[<tt>:field</tt>]
|
@@ -154,6 +154,10 @@ token.
|
|
154
154
|
Returns the name of the key used to store/retrieve the token from the Rack
|
155
155
|
session.
|
156
156
|
|
157
|
+
Despite this class method, you should never try to retrieve the token with
|
158
|
+
code like <tt>env['rack.session'][Rack::Csrf.key]</tt>. See the `token`
|
159
|
+
method below.
|
160
|
+
|
157
161
|
[<tt>Rack::Csrf.field</tt> (also <tt>Rack::Csrf.csrf_field</tt>)]
|
158
162
|
Returns the name of the field that must be present in the request.
|
159
163
|
|
@@ -186,6 +190,14 @@ In the +examples+ directory there are some small, working web applications
|
|
186
190
|
written with different Rack-based frameworks. They are named after the used
|
187
191
|
framework; see the various README files for other details.
|
188
192
|
|
193
|
+
== Supported Rubies and Racks
|
194
|
+
|
195
|
+
The gemspec shows the minimum Ruby and Rack versions, but Rack::Csrf is
|
196
|
+
tested only with the Rubies and Racks you can see in
|
197
|
+
<tt>.circleci/config.yml</tt> and/or <tt>.github/workflows/ci.yml</tt>. It
|
198
|
+
could work also with older versions, but I decided not to test it against
|
199
|
+
unsupported Rubies and Racks.
|
200
|
+
|
189
201
|
== Contributing
|
190
202
|
|
191
203
|
If you want to help:
|
@@ -208,5 +220,5 @@ forgo responsibilities for keeping your application as safe as possible.
|
|
208
220
|
|
209
221
|
== Copyright
|
210
222
|
|
211
|
-
Copyright (c) 2009, 2010, 2011, 2012 Emanuele Vicentini.
|
212
|
-
details.
|
223
|
+
Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016, 2022 Emanuele Vicentini.
|
224
|
+
See LICENSE.rdoc for details.
|
data/Rakefile
CHANGED
@@ -1,62 +1,40 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
2
|
+
require 'bundler/setup'
|
10
3
|
|
11
4
|
require 'rake/clean'
|
12
|
-
require 'cucumber/rake/task'
|
13
|
-
require 'rspec/core/rake_task'
|
14
|
-
require 'rdoc/task'
|
15
|
-
require 'jeweler'
|
16
5
|
|
6
|
+
require 'cucumber/rake/task'
|
17
7
|
Cucumber::Rake::Task.new :features
|
18
8
|
task :default => :features
|
19
9
|
|
10
|
+
require 'rspec/core/rake_task'
|
20
11
|
RSpec::Core::RakeTask.new :spec
|
21
12
|
task :default => :spec
|
22
13
|
|
23
|
-
|
14
|
+
require 'rack/csrf/version'
|
24
15
|
|
16
|
+
require 'rdoc/task'
|
25
17
|
RDoc::Task.new :doc do |rdoc|
|
26
18
|
rdoc.rdoc_dir = 'doc'
|
27
|
-
rdoc.title = "Rack::Csrf #{
|
19
|
+
rdoc.title = "Rack::Csrf #{Rack::Csrf::VERSION}"
|
28
20
|
rdoc.main = 'README.rdoc'
|
29
21
|
rdoc.rdoc_files.include('README.rdoc', 'LICENSE.rdoc')
|
30
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
31
23
|
end
|
32
24
|
|
33
|
-
|
34
|
-
gem.name = 'rack_csrf'
|
35
|
-
gem.summary = 'Anti-CSRF Rack middleware'
|
36
|
-
gem.description = 'Anti-CSRF Rack middleware'
|
37
|
-
gem.license = 'MIT'
|
38
|
-
gem.authors = 'Emanuele Vicentini'
|
39
|
-
gem.email = 'emanuele.vicentini@gmail.com'
|
40
|
-
gem.homepage = 'https://github.com/baldowl/rack_csrf'
|
41
|
-
gem.rubyforge_project = 'rackcsrf'
|
42
|
-
# dependencies defined in Gemfile
|
43
|
-
gem.rdoc_options << '--line-numbers' << '--inline-source' << '--title' <<
|
44
|
-
"Rack::Csrf #{version}" << '--main' << 'README.rdoc'
|
45
|
-
gem.test_files.clear
|
46
|
-
end
|
47
|
-
|
48
|
-
Jeweler::GemcutterTasks.new
|
25
|
+
require 'bundler/gem_tasks'
|
49
26
|
|
27
|
+
require 'git'
|
50
28
|
desc <<-EOD
|
51
29
|
Shows the changelog in Git between the given points.
|
52
30
|
|
53
31
|
start -- defaults to the current version tag
|
54
32
|
end -- defaults to HEAD
|
55
33
|
EOD
|
56
|
-
task :changes, [:start, :end] do |
|
57
|
-
args.with_defaults :start => "v#{
|
34
|
+
task :changes, [:start, :end] do |_, args|
|
35
|
+
args.with_defaults :start => "v#{Rack::Csrf::VERSION}",
|
58
36
|
:end => 'HEAD'
|
59
|
-
repo = Git.open
|
37
|
+
repo = Git.open Dir.pwd
|
60
38
|
repo.log(nil).between(args.start, args.end).each do |c|
|
61
39
|
puts c.message.split($/).first
|
62
40
|
end
|
data/examples/camping/Gemfile
CHANGED
data/examples/camping/app.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
require 'camping'
|
2
2
|
require 'camping/session'
|
3
|
-
|
4
|
-
$: << File.join(File.dirname(__FILE__), '../../lib')
|
5
3
|
require 'rack/csrf'
|
6
4
|
|
7
5
|
Camping.goes :LittleApp
|
8
6
|
|
9
7
|
module LittleApp
|
10
8
|
use Rack::Csrf # This has to come BEFORE 'include Camping::Session',
|
11
|
-
# otherwise you get the 'Rack::Csrf depends on session
|
9
|
+
# otherwise you get the 'Rack::Csrf depends on session
|
12
10
|
# middleware' exception. Weird...
|
13
11
|
include Camping::Session
|
14
12
|
|
data/examples/cuba/Gemfile
CHANGED
data/examples/cuba/app.rb
CHANGED
data/examples/cuba/config.ru
CHANGED
data/examples/innate/Gemfile
CHANGED
data/examples/innate/start.rb
CHANGED
data/examples/rack/Gemfile
CHANGED
data/examples/rack/app.rb
CHANGED
@@ -30,16 +30,21 @@ class LittleApp
|
|
30
30
|
|
31
31
|
def self.call env
|
32
32
|
req = Rack::Request.new env
|
33
|
+
res = Rack::Response.new
|
34
|
+
|
33
35
|
if req.get?
|
34
36
|
if req.path_info == '/notworking'
|
35
|
-
|
37
|
+
res.write @form_not_working.result(binding)
|
36
38
|
else
|
37
|
-
|
39
|
+
res.write @form.result(binding)
|
38
40
|
end
|
39
41
|
elsif req.post?
|
40
42
|
utterance = req['utterance']
|
41
43
|
csrf = req[Rack::Csrf.field]
|
42
|
-
|
44
|
+
res.write @response.result(binding)
|
43
45
|
end
|
46
|
+
|
47
|
+
res['Content-Type'] = 'text/html'
|
48
|
+
res.finish
|
44
49
|
end
|
45
50
|
end
|
data/examples/rack/config.ru
CHANGED
data/examples/sinatra/Gemfile
CHANGED
data/examples/sinatra/app.rb
CHANGED
@@ -7,6 +7,8 @@ get '/notworking' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
post '/response' do
|
10
|
-
erb :response, :locals => {
|
11
|
-
:
|
10
|
+
erb :response, :locals => {
|
11
|
+
:utterance => params[:utterance],
|
12
|
+
:csrf => params[Rack::Csrf.field]
|
13
|
+
}
|
12
14
|
end
|
@@ -1,14 +1,11 @@
|
|
1
1
|
require 'sinatra'
|
2
|
-
$: << File.join(File.dirname(__FILE__), '../../lib')
|
3
2
|
require 'rack/csrf'
|
4
3
|
|
5
4
|
require 'erb'
|
6
|
-
require 'app'
|
5
|
+
require './app'
|
7
6
|
|
8
7
|
use Rack::ShowExceptions
|
9
8
|
use Rack::Session::Cookie
|
10
9
|
use Rack::Csrf, :raise => true
|
11
10
|
|
12
|
-
set :app_file, 'app.rb'
|
13
|
-
|
14
11
|
run Sinatra::Application
|
data/examples/sinatra/config.ru
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'sinatra'
|
2
|
-
$: << File.join(File.dirname(__FILE__), '../../lib')
|
3
2
|
require 'rack/csrf'
|
4
3
|
|
5
4
|
require 'erb'
|
6
|
-
require 'app'
|
5
|
+
require './app'
|
7
6
|
|
8
7
|
use Rack::Session::Cookie
|
9
8
|
use Rack::Csrf
|
10
9
|
|
11
|
-
set :app_file, 'app.rb'
|
12
|
-
|
13
10
|
run Sinatra::Application
|
@@ -4,7 +4,7 @@
|
|
4
4
|
When /^it receives a (.*) request without the CSRF (?:token|header)$/ do |http_method|
|
5
5
|
begin
|
6
6
|
@browser.request '/', :method => http_method
|
7
|
-
rescue
|
7
|
+
rescue StandardError => e
|
8
8
|
@exception = e
|
9
9
|
end
|
10
10
|
end
|
@@ -12,7 +12,7 @@ end
|
|
12
12
|
When /^it receives a (.*) request for (.+) without the CSRF (?:token|header|token or header)$/ do |http_method, path|
|
13
13
|
begin
|
14
14
|
@browser.request path, :method => http_method
|
15
|
-
rescue
|
15
|
+
rescue StandardError => e
|
16
16
|
@exception = e
|
17
17
|
end
|
18
18
|
end
|
@@ -34,7 +34,7 @@ When /^it receives a (.*) request with the wrong CSRF token$/ do |http_method|
|
|
34
34
|
@browser.request '/', :method => http_method,
|
35
35
|
'rack.session' => {Rack::Csrf.key => 'right_token'},
|
36
36
|
:params => {Rack::Csrf.field => 'wrong_token'}
|
37
|
-
rescue
|
37
|
+
rescue StandardError => e
|
38
38
|
@exception = e
|
39
39
|
end
|
40
40
|
end
|
@@ -43,7 +43,7 @@ When /^it receives a (.*) request with the wrong CSRF header/ do |http_method|
|
|
43
43
|
begin
|
44
44
|
@browser.request '/', :method => http_method,
|
45
45
|
Rack::Csrf.rackified_header => 'right_token'
|
46
|
-
rescue
|
46
|
+
rescue StandardError => e
|
47
47
|
@exception = e
|
48
48
|
end
|
49
49
|
end
|
@@ -51,7 +51,7 @@ end
|
|
51
51
|
When /^it receives a (.*) request with neither PATH_INFO nor CSRF token or header$/ do |http_method|
|
52
52
|
begin
|
53
53
|
@browser.request '/doesntmatter', :method => http_method, 'PATH_INFO' => ''
|
54
|
-
rescue
|
54
|
+
rescue StandardError => e
|
55
55
|
@exception = e
|
56
56
|
end
|
57
57
|
end
|
@@ -59,7 +59,7 @@ end
|
|
59
59
|
When /^it receives a request with headers (.+) = ([^ ]+) without the CSRF token or header$/ do |name, value|
|
60
60
|
begin
|
61
61
|
@browser.request '/', Hash[:method, 'POST', name, value]
|
62
|
-
rescue
|
62
|
+
rescue StandardError => e
|
63
63
|
@exception = e
|
64
64
|
end
|
65
65
|
end
|
@@ -67,7 +67,7 @@ end
|
|
67
67
|
When /^it receives a request with headers (.+) = ([^,]+), (.+), and without the CSRF token or header$/ do |name, value, method|
|
68
68
|
begin
|
69
69
|
@browser.request '/', Hash[:method, method, name, value]
|
70
|
-
rescue
|
70
|
+
rescue StandardError => e
|
71
71
|
@exception = e
|
72
72
|
end
|
73
73
|
end
|
@@ -1,14 +1,14 @@
|
|
1
1
|
Then /^it lets it pass untouched$/ do
|
2
|
-
@browser.last_response.
|
3
|
-
@browser.last_response.
|
2
|
+
expect(@browser.last_response).to be_ok
|
3
|
+
expect(@browser.last_response).to match(/Hello world!/)
|
4
4
|
end
|
5
5
|
|
6
6
|
Then /^it responds with (\d\d\d)$/ do |code|
|
7
|
-
@browser.last_response.status.
|
7
|
+
expect(@browser.last_response.status).to eq(code.to_i)
|
8
8
|
end
|
9
9
|
|
10
10
|
Then /^the response body is empty$/ do
|
11
|
-
@browser.last_response.body.
|
11
|
+
expect(@browser.last_response.body).to be_empty
|
12
12
|
end
|
13
13
|
|
14
14
|
Then /^there is no response$/ do
|
@@ -16,5 +16,5 @@ Then /^there is no response$/ do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
Then /^an exception is climbing up the stack$/ do
|
19
|
-
@exception.
|
19
|
+
expect(@exception).to be_an_instance_of(Rack::Csrf::InvalidCsrfToken)
|
20
20
|
end
|
@@ -73,29 +73,35 @@ When /^I insert the anti\-CSRF middleware with the :raise option$/ do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
When /^I insert the anti\-CSRF middleware with the :skip option$/ do |table|
|
76
|
-
skippable = table.hashes.collect
|
76
|
+
skippable = table.hashes.collect(&:values).flatten
|
77
77
|
@rack_builder.use Rack::Csrf, :skip => skippable
|
78
78
|
@app = toy_app
|
79
79
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
80
80
|
end
|
81
81
|
|
82
82
|
When /^I insert the anti\-CSRF middleware with the :skip_if option$/ do |table|
|
83
|
-
skippable =
|
84
|
-
|
83
|
+
skippable = {}
|
84
|
+
table.hashes.each {|row| skippable[row['name']] = row['value']}
|
85
|
+
skip_logic = Proc.new do |request|
|
85
86
|
skippable.any? { |name, value| request.env[name] == value }
|
86
|
-
|
87
|
+
end
|
88
|
+
@rack_builder.use Rack:: Csrf, :skip_if => skip_logic
|
87
89
|
@app = toy_app
|
88
90
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
89
91
|
end
|
90
92
|
|
91
93
|
When /^I insert the anti\-CSRF middleware with the :skip and :skip_if options$/ do |table|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
skip_option_arguments = []
|
95
|
+
skip_if_option_arguments = {}
|
96
|
+
table.hashes.each do |row|
|
97
|
+
skip_option_arguments << row['path']
|
98
|
+
skip_if_option_arguments[row['name']] = row['value']
|
99
|
+
end
|
100
|
+
skip_if_logic = Proc.new do |request|
|
101
|
+
skip_if_option_arguments.any? { |name, value| request.env[name] == value }
|
102
|
+
end
|
103
|
+
@rack_builder.use Rack::Csrf, :skip => skip_option_arguments,
|
104
|
+
:skip_if => skip_if_logic
|
99
105
|
@app = toy_app
|
100
106
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
101
107
|
end
|
@@ -119,14 +125,14 @@ When /^I insert the anti\-CSRF middleware with the :header option$/ do
|
|
119
125
|
end
|
120
126
|
|
121
127
|
When /^I insert the anti\-CSRF middleware with the :check_also option$/ do |table|
|
122
|
-
check_also = table.hashes.collect
|
128
|
+
check_also = table.hashes.collect(&:values).flatten
|
123
129
|
@rack_builder.use Rack::Csrf, :check_also => check_also
|
124
130
|
@app = toy_app
|
125
131
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
126
132
|
end
|
127
133
|
|
128
134
|
When /^I insert the anti\-CSRF middleware with the :check_only option$/ do |table|
|
129
|
-
must_be_checked = table.hashes.collect
|
135
|
+
must_be_checked = table.hashes.collect(&:values).flatten
|
130
136
|
@rack_builder.use Rack::Csrf, :check_only => must_be_checked
|
131
137
|
@app = toy_app
|
132
138
|
@browser = Rack::Test::Session.new(Rack::MockSession.new(@app))
|
@@ -143,6 +149,6 @@ Then /^I get an error message$/ do
|
|
143
149
|
end
|
144
150
|
|
145
151
|
def toy_app
|
146
|
-
@rack_builder.run(lambda {|
|
152
|
+
@rack_builder.run(lambda {|_| Rack::Response.new('Hello world!').finish})
|
147
153
|
@rack_builder.to_app
|
148
154
|
end
|