angular_rails_csrf 5.0.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +119 -0
- data/LICENSE.md +20 -0
- data/README.md +1 -2
- data/lib/angular_rails_csrf/concern.rb +24 -13
- data/lib/angular_rails_csrf/version.rb +1 -1
- metadata +10 -134
- data/test/angular_rails_csrf_exception_test.rb +0 -18
- data/test/angular_rails_csrf_skip_test.rb +0 -14
- data/test/angular_rails_csrf_test.rb +0 -152
- data/test/dummy/app/assets/config/manifest.js +0 -4
- data/test/dummy/app/controllers/api_controller.rb +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -13
- data/test/dummy/app/controllers/exclusions_controller.rb +0 -9
- data/test/dummy/config/application.rb +0 -16
- data/test/dummy/config/boot.rb +0 -6
- data/test/dummy/config/environment.rb +0 -7
- data/test/dummy/config/routes.rb +0 -10
- data/test/dummy/config.ru +0 -6
- data/test/dummy/log/test.log +0 -144
- data/test/test_helper.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d0b9c0281d924d679f0a9b8b71f5d1b4842a4bc9b78ede13f848c3e91479668
|
4
|
+
data.tar.gz: 4efbd91eb24c813ceb2553e2834e5db627cdc4b23c4dedac37ec89e7f5465d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cbc548f3e81540ba29b5ca46fa331899337eabd34422e70777e96cbc5ee2443aa962b63bed1ae779f62667389bc761c8bbe1ae2adc2e998426c94290074588b
|
7
|
+
data.tar.gz: '08e800161939ca9a70f9007ba818d4f9d094dea85241329d99d4310e099034e4eaf95254dc08606c4d26be2b98d231d74ef9e80e970a382df0a6cc73945ad5fb'
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 7.0.0 (12-Nov-24)
|
4
|
+
|
5
|
+
* **Breaking change**: require Ruby 3.2+. If you need support for older Rubies, stay on version 6
|
6
|
+
* Set Railties dependency to `< 9`
|
7
|
+
* Test with Rails 8
|
8
|
+
* Do not test with Ruby 3.0 and 3.1
|
9
|
+
|
10
|
+
## 6.0.0 (14-Nov-23)
|
11
|
+
|
12
|
+
* **Breaking change**: drop support for Ruby < 3. If you need to support older Rubies, stay on v5. If you'd like to support *even older stuff*, v4.5.0 is your choice as it plays nicely with Rails 5.1 and Ruby 2.5.
|
13
|
+
* Test only with Rails 7
|
14
|
+
* Fix some failing tests, minor tweaks
|
15
|
+
|
16
|
+
## 5.0.0 (14-Dec-21)
|
17
|
+
|
18
|
+
* Add support for Rails 7.
|
19
|
+
* Test against Rails 6.1 and Rails 7.0.
|
20
|
+
* Test against Ruby 3.0.
|
21
|
+
* Rails 5.1 is not supported officially anymore (but should still work fine).
|
22
|
+
* Ruby < 2.7 is not supported anymore (has reached end of life) but should still work.
|
23
|
+
|
24
|
+
## 4.5.0 (21-Sep-20)
|
25
|
+
|
26
|
+
* Added a new [`HttpOnly` option](https://github.com/jsanders/angular_rails_csrf#httponly-cookie) (thanks, [@Lubo-mir](https://github.com/Lubo-mir))
|
27
|
+
* Introduced some code refactorings
|
28
|
+
|
29
|
+
## 4.4.0 (04-Aug-20)
|
30
|
+
|
31
|
+
* Make the gem play nicely with controllers that do not have `protect_against_forgery?` method defined — for example, certain Doorkeeper controllers (thanks, [@amenz](https://github.com/amenz))
|
32
|
+
* Updated dependencies and cops
|
33
|
+
|
34
|
+
## 4.3.0 (18-May-20)
|
35
|
+
|
36
|
+
* Ruby version 2.4 is no longer officially supported (though it still should work) - this is also due to the fact that [v2.4 is abanoded by Ruby core team as well](https://www.ruby-lang.org/en/news/2020/04/05/support-of-ruby-2-4-has-ended/). Required Ruby version is now 2.5+ according to [version compatibility](https://github.com/jsanders/angular_rails_csrf/wiki/Version-Compatibility).
|
37
|
+
* Dropped backwards compatibility with older versions of Rails (v4 and below). [If you require Rails 4 support, use angular_rails_csrf v3]((https://github.com/jsanders/angular_rails_csrf/wiki/Version-Compatibility)).
|
38
|
+
* Increased test coverage up to 100%.
|
39
|
+
|
40
|
+
## 4.2.0 (31-Mar-20)
|
41
|
+
|
42
|
+
* Added a new [`angular_rails_csrf_same_site` option](https://github.com/jsanders/angular_rails_csrf#samesite) which defaults to `:lax` (thanks, [@timobleeker](https://github.com/timobleeker))
|
43
|
+
+ This option is introduced to comply with the latest changes: https://www.chromium.org/updates/same-site
|
44
|
+
* Update cops
|
45
|
+
|
46
|
+
## 4.1.0 (03-Feb-20)
|
47
|
+
|
48
|
+
* Added a new [`angular_rails_csrf_secure` option](https://github.com/jsanders/angular_rails_csrf#secure-cookie) (thanks, [@DougKeller](https://github.com/DougKeller))
|
49
|
+
* Tested against Ruby 2.7
|
50
|
+
|
51
|
+
## 4.0.1 (23-Dec-19)
|
52
|
+
|
53
|
+
* Updated dependencies, tested against more recent Rubies and Rails
|
54
|
+
* Updated Gemfile for Bundler 2
|
55
|
+
* Added Rubocop and SimpleCov
|
56
|
+
|
57
|
+
## 4.0.0 (20-Aug-19)
|
58
|
+
|
59
|
+
Updated:
|
60
|
+
* Added support for Rails 6.0
|
61
|
+
* Drop support for Rails 4
|
62
|
+
|
63
|
+
## 3.2.0
|
64
|
+
|
65
|
+
New feature:
|
66
|
+
* Allow cookie's name to be customized (thanks, [@timobleeker](https://github.com/timobleeker))
|
67
|
+
|
68
|
+
## 3.1.0
|
69
|
+
|
70
|
+
Updated:
|
71
|
+
* Added support for Rails 5.2.0
|
72
|
+
|
73
|
+
Testing:
|
74
|
+
* Tested against more recent Ruby/Rails versions
|
75
|
+
|
76
|
+
## 3.0.0
|
77
|
+
|
78
|
+
New feature:
|
79
|
+
* Allow cookie domain to be set via `Rails.application.config` (thanks, [@gingermusketeer](https://github.com/gingermusketeer))
|
80
|
+
|
81
|
+
Updated:
|
82
|
+
* Dropped support for Rails < 4
|
83
|
+
* Dropped official support for Ruby 2.2 though it should still work
|
84
|
+
|
85
|
+
Testing:
|
86
|
+
* Test against more recent versions of Ruby and Rails
|
87
|
+
|
88
|
+
## 2.1.1
|
89
|
+
|
90
|
+
Updated:
|
91
|
+
* Added support for Rails 5.1.1
|
92
|
+
|
93
|
+
Testing:
|
94
|
+
* Test against more recent versions of Ruby
|
95
|
+
* Test against Rails 5.1.1
|
96
|
+
|
97
|
+
## 2.1.0
|
98
|
+
|
99
|
+
Updated:
|
100
|
+
* Added support for Rails 5.1
|
101
|
+
|
102
|
+
Testing improvements:
|
103
|
+
* Tested against Rails 5.1
|
104
|
+
* Tested against Ruby 2.4.0
|
105
|
+
* We are no longer testing against Rails < 4.2
|
106
|
+
|
107
|
+
## 2.0.0
|
108
|
+
|
109
|
+
**Breaking changes:**
|
110
|
+
* Revert to `after_action` again (fixes [issues with Devise](https://github.com/jsanders/angular_rails_csrf/issues/17) and similar solutions)
|
111
|
+
* Introduced a new `exclude_xsrf_token_cookie` class method to exclude setting CSRF token for certain controllers. This is done to take care of [problems with streaming](https://github.com/jsanders/angular_rails_csrf/issues/7).
|
112
|
+
|
113
|
+
Updated:
|
114
|
+
* Added support for Rails 5
|
115
|
+
* `rails` dependency changed to `railties`
|
116
|
+
|
117
|
+
Testing improvements:
|
118
|
+
* Tested against Rails 5
|
119
|
+
* Tested against Ruby 2.2.5 and 2.3.0
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2024 James Sanders, Ilya Krukowski
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
## AngularJS-style CSRF Protection for Rails
|
2
2
|
|
3
3
|
![Gem](https://img.shields.io/gem/v/angular_rails_csrf)
|
4
|
-
|
5
|
-
[![Test Coverage](https://codecov.io/gh/jsanders/angular_rails_csrf/graph/badge.svg)](https://codecov.io/gh/jsanders/angular_rails_csrf)
|
4
|
+
![CI](https://github.com/jsanders/angular_rails_csrf/actions/workflows/ci.yml/badge.svg)
|
6
5
|
![Downloads total](https://img.shields.io/gem/dt/angular_rails_csrf)
|
7
6
|
|
8
7
|
The AngularJS [ng.$http](http://docs.angularjs.org/api/ng.$http) service has built-in CSRF protection. By default, it looks for a cookie named `XSRF-TOKEN` and, if found, writes its value into an `X-XSRF-TOKEN` header, which the server compares with the CSRF token saved in the user's session.
|
@@ -9,25 +9,15 @@ module AngularRailsCsrf
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def set_xsrf_token_cookie
|
12
|
-
return unless
|
12
|
+
return unless forgery_protection_enabled?
|
13
13
|
|
14
14
|
config = Rails.application.config
|
15
15
|
|
16
|
-
secure = option_from config, :angular_rails_csrf_secure
|
17
|
-
same_site = option_from config, :angular_rails_csrf_same_site, :lax
|
18
|
-
|
19
|
-
cookie_options = {
|
20
|
-
value: form_authenticity_token,
|
21
|
-
domain: option_from(config, :angular_rails_csrf_domain),
|
22
|
-
same_site: same_site,
|
23
|
-
httponly: option_from(config, :angular_rails_csrf_httponly, false),
|
24
|
-
secure: same_site.eql?(:none) || secure
|
25
|
-
}
|
26
|
-
|
27
16
|
cookie_name = option_from(config,
|
28
17
|
:angular_rails_csrf_cookie_name,
|
29
18
|
'XSRF-TOKEN')
|
30
|
-
|
19
|
+
|
20
|
+
cookies[cookie_name] = cookie_options_from(config)
|
31
21
|
end
|
32
22
|
|
33
23
|
def verified_request?
|
@@ -36,12 +26,33 @@ module AngularRailsCsrf
|
|
36
26
|
|
37
27
|
private
|
38
28
|
|
29
|
+
def cookie_options_from(config)
|
30
|
+
secure = option_from config, :angular_rails_csrf_secure
|
31
|
+
same_site = option_from config, :angular_rails_csrf_same_site, :lax
|
32
|
+
|
33
|
+
{
|
34
|
+
value: form_authenticity_token,
|
35
|
+
domain: option_from(config, :angular_rails_csrf_domain),
|
36
|
+
same_site: same_site,
|
37
|
+
httponly: option_from(config, :angular_rails_csrf_httponly, false),
|
38
|
+
secure: same_site.eql?(:none) || secure
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
39
42
|
# Fetches the given option from config
|
40
43
|
# If the option is not set, return a default value
|
41
44
|
def option_from(config, option, default = nil)
|
45
|
+
return default if config.nil?
|
46
|
+
|
42
47
|
config.respond_to?(option) ? config.send(option) : default
|
43
48
|
end
|
44
49
|
|
50
|
+
def forgery_protection_enabled?
|
51
|
+
defined?(protect_against_forgery?) &&
|
52
|
+
protect_against_forgery? &&
|
53
|
+
!respond_to?(:__exclude_xsrf_token_cookie?)
|
54
|
+
end
|
55
|
+
|
45
56
|
module ClassMethods
|
46
57
|
def exclude_xsrf_token_cookie
|
47
58
|
class_eval do
|
metadata
CHANGED
@@ -1,58 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular_rails_csrf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 7.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Sanders
|
8
|
-
- Ilya
|
8
|
+
- Ilya Krukowski
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '13.0'
|
21
|
-
type: :development
|
22
|
-
prerelease: false
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - "~>"
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
version: '13.0'
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
name: test-unit
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
-
requirements:
|
32
|
-
- - "~>"
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '3.2'
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: '3.2'
|
42
|
-
- !ruby/object:Gem::Dependency
|
43
|
-
name: rails
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
45
|
-
requirements:
|
46
|
-
- - '='
|
47
|
-
- !ruby/object:Gem::Version
|
48
|
-
version: 7.0.0.rc1
|
49
|
-
type: :development
|
50
|
-
prerelease: false
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
52
|
-
requirements:
|
53
|
-
- - '='
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
version: 7.0.0.rc1
|
56
14
|
- !ruby/object:Gem::Dependency
|
57
15
|
name: railties
|
58
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,7 +20,7 @@ dependencies:
|
|
62
20
|
version: '3'
|
63
21
|
- - "<"
|
64
22
|
- !ruby/object:Gem::Version
|
65
|
-
version: '
|
23
|
+
version: '9'
|
66
24
|
type: :runtime
|
67
25
|
prerelease: false
|
68
26
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,63 +30,7 @@ dependencies:
|
|
72
30
|
version: '3'
|
73
31
|
- - "<"
|
74
32
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
76
|
-
- !ruby/object:Gem::Dependency
|
77
|
-
name: codecov
|
78
|
-
requirement: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.2'
|
83
|
-
type: :development
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.2'
|
90
|
-
- !ruby/object:Gem::Dependency
|
91
|
-
name: rubocop
|
92
|
-
requirement: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.0'
|
97
|
-
type: :development
|
98
|
-
prerelease: false
|
99
|
-
version_requirements: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '1.0'
|
104
|
-
- !ruby/object:Gem::Dependency
|
105
|
-
name: rubocop-performance
|
106
|
-
requirement: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '1.5'
|
111
|
-
type: :development
|
112
|
-
prerelease: false
|
113
|
-
version_requirements: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '1.5'
|
118
|
-
- !ruby/object:Gem::Dependency
|
119
|
-
name: simplecov
|
120
|
-
requirement: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.16'
|
125
|
-
type: :development
|
126
|
-
prerelease: false
|
127
|
-
version_requirements: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.16'
|
33
|
+
version: '9'
|
132
34
|
description: AngularJS style CSRF protection for Rails
|
133
35
|
email:
|
134
36
|
- sanderjd@gmail.com
|
@@ -137,26 +39,14 @@ executables: []
|
|
137
39
|
extensions: []
|
138
40
|
extra_rdoc_files: []
|
139
41
|
files:
|
42
|
+
- CHANGELOG.md
|
43
|
+
- LICENSE.md
|
140
44
|
- README.md
|
141
45
|
- Rakefile
|
142
46
|
- lib/angular_rails_csrf.rb
|
143
47
|
- lib/angular_rails_csrf/concern.rb
|
144
48
|
- lib/angular_rails_csrf/railtie.rb
|
145
49
|
- lib/angular_rails_csrf/version.rb
|
146
|
-
- test/angular_rails_csrf_exception_test.rb
|
147
|
-
- test/angular_rails_csrf_skip_test.rb
|
148
|
-
- test/angular_rails_csrf_test.rb
|
149
|
-
- test/dummy/app/assets/config/manifest.js
|
150
|
-
- test/dummy/app/controllers/api_controller.rb
|
151
|
-
- test/dummy/app/controllers/application_controller.rb
|
152
|
-
- test/dummy/app/controllers/exclusions_controller.rb
|
153
|
-
- test/dummy/config.ru
|
154
|
-
- test/dummy/config/application.rb
|
155
|
-
- test/dummy/config/boot.rb
|
156
|
-
- test/dummy/config/environment.rb
|
157
|
-
- test/dummy/config/routes.rb
|
158
|
-
- test/dummy/log/test.log
|
159
|
-
- test/test_helper.rb
|
160
50
|
homepage: https://github.com/jsanders/angular_rails_csrf
|
161
51
|
licenses:
|
162
52
|
- MIT
|
@@ -170,29 +60,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
60
|
requirements:
|
171
61
|
- - ">="
|
172
62
|
- !ruby/object:Gem::Version
|
173
|
-
version: 2
|
63
|
+
version: '3.2'
|
174
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
65
|
requirements:
|
176
66
|
- - ">="
|
177
67
|
- !ruby/object:Gem::Version
|
178
68
|
version: '0'
|
179
69
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
70
|
+
rubygems_version: 3.5.23
|
181
71
|
signing_key:
|
182
72
|
specification_version: 4
|
183
73
|
summary: Support for AngularJS $http service style CSRF protection in Rails
|
184
|
-
test_files:
|
185
|
-
- test/angular_rails_csrf_exception_test.rb
|
186
|
-
- test/angular_rails_csrf_skip_test.rb
|
187
|
-
- test/angular_rails_csrf_test.rb
|
188
|
-
- test/dummy/app/assets/config/manifest.js
|
189
|
-
- test/dummy/app/controllers/api_controller.rb
|
190
|
-
- test/dummy/app/controllers/application_controller.rb
|
191
|
-
- test/dummy/app/controllers/exclusions_controller.rb
|
192
|
-
- test/dummy/config/application.rb
|
193
|
-
- test/dummy/config/boot.rb
|
194
|
-
- test/dummy/config/environment.rb
|
195
|
-
- test/dummy/config/routes.rb
|
196
|
-
- test/dummy/config.ru
|
197
|
-
- test/dummy/log/test.log
|
198
|
-
- test/test_helper.rb
|
74
|
+
test_files: []
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class AngularRailsCsrfExceptionTest < ActionController::TestCase
|
6
|
-
tests ExclusionsController
|
7
|
-
|
8
|
-
setup do
|
9
|
-
@controller.allow_forgery_protection = true
|
10
|
-
@correct_token = @controller.send(:form_authenticity_token)
|
11
|
-
end
|
12
|
-
|
13
|
-
test 'a get does not set the XSRF-TOKEN cookie' do
|
14
|
-
get :index
|
15
|
-
assert_not_equal @correct_token, cookies['XSRF-TOKEN']
|
16
|
-
assert_response :success
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class AngularRailsCsrfSkipTest < ActionController::TestCase
|
6
|
-
tests ApiController
|
7
|
-
|
8
|
-
test 'csrf-cookie is not set and no error if protect_against_forgery? is not defined' do
|
9
|
-
refute @controller.respond_to?(:protect_against_forgery?)
|
10
|
-
get :index
|
11
|
-
assert_nil cookies['XSRF-TOKEN']
|
12
|
-
assert_response :success
|
13
|
-
end
|
14
|
-
end
|
@@ -1,152 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class AngularRailsCsrfTest < ActionController::TestCase
|
6
|
-
tests ApplicationController
|
7
|
-
|
8
|
-
test 'a get sets the XSRF-TOKEN cookie but does not require the X-XSRF-TOKEN header' do
|
9
|
-
get :index
|
10
|
-
assert_valid_cookie
|
11
|
-
assert_response :success
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'a post raises an error without the X-XSRF-TOKEN header set' do
|
15
|
-
assert_raises ActionController::InvalidAuthenticityToken do
|
16
|
-
post :create
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'a post raises an error with the X-XSRF-TOKEN header set to the wrong value' do
|
21
|
-
header_to 'garbage'
|
22
|
-
assert_raises ActionController::InvalidAuthenticityToken do
|
23
|
-
post :create
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'a post is accepted if X-XSRF-TOKEN is set properly' do
|
28
|
-
header_to @controller.send(:form_authenticity_token)
|
29
|
-
post :create
|
30
|
-
assert_valid_cookie
|
31
|
-
assert_response :success
|
32
|
-
end
|
33
|
-
|
34
|
-
test 'csrf-cookie is not set if exclusion is enabled' do
|
35
|
-
refute @controller.respond_to?(:__exclude_xsrf_token_cookie?)
|
36
|
-
@controller.class_eval { exclude_xsrf_token_cookie }
|
37
|
-
get :index
|
38
|
-
assert_valid_cookie present: false
|
39
|
-
assert @controller.__exclude_xsrf_token_cookie?
|
40
|
-
assert_response :success
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'the domain is used if present' do
|
44
|
-
config = Rails.application.config
|
45
|
-
def config.angular_rails_csrf_domain
|
46
|
-
:all
|
47
|
-
end
|
48
|
-
|
49
|
-
get :index
|
50
|
-
assert @response.headers['Set-Cookie'].include?('.test.host')
|
51
|
-
assert_valid_cookie
|
52
|
-
assert_response :success
|
53
|
-
ensure
|
54
|
-
config.instance_eval('undef :angular_rails_csrf_domain', __FILE__, __LINE__)
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'the secure flag is set if configured' do
|
58
|
-
@request.headers['HTTPS'] = 'on'
|
59
|
-
|
60
|
-
config = Rails.application.config
|
61
|
-
config.define_singleton_method(:angular_rails_csrf_secure) { true }
|
62
|
-
|
63
|
-
get :index
|
64
|
-
assert @response.headers['Set-Cookie'].include?('secure')
|
65
|
-
assert_valid_cookie
|
66
|
-
assert_response :success
|
67
|
-
ensure
|
68
|
-
@request.headers['HTTPS'] = nil
|
69
|
-
config.instance_eval('undef :angular_rails_csrf_secure', __FILE__, __LINE__)
|
70
|
-
end
|
71
|
-
|
72
|
-
test 'a custom name is used if present' do
|
73
|
-
use_custom_cookie_name do
|
74
|
-
get :index
|
75
|
-
assert @response.headers['Set-Cookie'].include?('CUSTOM-COOKIE-NAME')
|
76
|
-
assert_valid_cookie name: 'CUSTOM-COOKIE-NAME'
|
77
|
-
assert_response :success
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'the httponly flag is set if configured' do
|
82
|
-
config = Rails.application.config
|
83
|
-
config.define_singleton_method(:angular_rails_csrf_httponly) { true }
|
84
|
-
|
85
|
-
get :index
|
86
|
-
assert @response.headers['Set-Cookie'].include?('HttpOnly')
|
87
|
-
assert_valid_cookie
|
88
|
-
assert_response :success
|
89
|
-
ensure
|
90
|
-
config.instance_eval('undef :angular_rails_csrf_httponly', __FILE__, __LINE__)
|
91
|
-
end
|
92
|
-
|
93
|
-
test 'same_site is set to Lax by default' do
|
94
|
-
get :index
|
95
|
-
assert @response.headers['Set-Cookie'].include?('SameSite=Lax')
|
96
|
-
assert_valid_cookie
|
97
|
-
assert_response :success
|
98
|
-
end
|
99
|
-
|
100
|
-
test 'same_site can be configured' do
|
101
|
-
config = Rails.application.config
|
102
|
-
config.define_singleton_method(:angular_rails_csrf_same_site) { :strict }
|
103
|
-
|
104
|
-
get :index
|
105
|
-
assert @response.headers['Set-Cookie'].include?('SameSite=Strict')
|
106
|
-
assert_valid_cookie
|
107
|
-
assert_response :success
|
108
|
-
ensure
|
109
|
-
config.instance_eval('undef :angular_rails_csrf_same_site', __FILE__, __LINE__)
|
110
|
-
end
|
111
|
-
|
112
|
-
test 'secure is set automatically when same_site is set to none' do
|
113
|
-
@request.headers['HTTPS'] = 'on'
|
114
|
-
|
115
|
-
config = Rails.application.config
|
116
|
-
config.define_singleton_method(:angular_rails_csrf_same_site) { :none }
|
117
|
-
|
118
|
-
get :index
|
119
|
-
assert @response.headers['Set-Cookie'].include?('SameSite=None')
|
120
|
-
assert @response.headers['Set-Cookie'].include?('secure')
|
121
|
-
assert_valid_cookie
|
122
|
-
assert_response :success
|
123
|
-
ensure
|
124
|
-
config.instance_eval('undef :angular_rails_csrf_same_site', __FILE__, __LINE__)
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
# Helpers
|
130
|
-
|
131
|
-
def header_to(value)
|
132
|
-
@request.headers['X-XSRF-TOKEN'] = value
|
133
|
-
end
|
134
|
-
|
135
|
-
def assert_valid_cookie(name: 'XSRF-TOKEN', present: true)
|
136
|
-
cookie_valid = @controller.send(:valid_authenticity_token?, session, cookies[name])
|
137
|
-
cookie_valid = !cookie_valid unless present
|
138
|
-
assert cookie_valid
|
139
|
-
end
|
140
|
-
|
141
|
-
def use_custom_cookie_name
|
142
|
-
config = Rails.application.config
|
143
|
-
def config.angular_rails_csrf_cookie_name
|
144
|
-
'CUSTOM-COOKIE-NAME'
|
145
|
-
end
|
146
|
-
yield
|
147
|
-
ensure
|
148
|
-
eval <<-RUBY, binding, __FILE__, __LINE__ + 1
|
149
|
-
config.instance_eval('undef :angular_rails_csrf_cookie_name')
|
150
|
-
RUBY
|
151
|
-
end
|
152
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('boot', __dir__)
|
4
|
-
|
5
|
-
require 'action_controller/railtie'
|
6
|
-
|
7
|
-
Bundler.require(:default, Rails.env)
|
8
|
-
require 'angular_rails_csrf'
|
9
|
-
|
10
|
-
module Dummy
|
11
|
-
class Application < Rails::Application
|
12
|
-
config.secret_key_base = '5e6b6d2bd7bf26d02679ac958b520adf41b211eb0b8f33742abc5437711d0ad314baf13efc0d35d7568d2e469668a7021cf5e945c667bd16507777aedb770f83'
|
13
|
-
config.eager_load = false # You get yelled at if you don't set this
|
14
|
-
config.active_support.test_order = :random
|
15
|
-
end
|
16
|
-
end
|
data/test/dummy/config/boot.rb
DELETED
data/test/dummy/config/routes.rb
DELETED
data/test/dummy/config.ru
DELETED
data/test/dummy/log/test.log
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
----------------------------------------------------------------------------
|
2
|
-
AngularRailsCsrfExceptionTest: test_a_get_does_not_set_the_XSRF-TOKEN_cookie
|
3
|
-
----------------------------------------------------------------------------
|
4
|
-
Processing by ExclusionsController#index as HTML
|
5
|
-
Completed 200 OK in 0ms (Allocations: 214)
|
6
|
-
-------------------------------------------------------------------------------------------------------------
|
7
|
-
AngularRailsCsrfSkipTest: test_csrf-cookie_is_not_set_and_no_error_if_protect_against_forgery?_is_not_defined
|
8
|
-
-------------------------------------------------------------------------------------------------------------
|
9
|
-
Processing by ApiController#index as HTML
|
10
|
-
Completed 200 OK in 0ms (Allocations: 106)
|
11
|
-
--------------------------------------------------------
|
12
|
-
AngularRailsCsrfTest: test_the_domain_is_used_if_present
|
13
|
-
--------------------------------------------------------
|
14
|
-
Processing by ApplicationController#index as HTML
|
15
|
-
Completed 200 OK in 0ms (Allocations: 195)
|
16
|
-
------------------------------------------------------
|
17
|
-
AngularRailsCsrfTest: test_same_site_can_be_configured
|
18
|
-
------------------------------------------------------
|
19
|
-
Processing by ApplicationController#index as HTML
|
20
|
-
Completed 200 OK in 0ms (Allocations: 94)
|
21
|
-
-------------------------------------------------------------------------
|
22
|
-
AngularRailsCsrfTest: test_csrf-cookie_is_not_set_if_exclusion_is_enabled
|
23
|
-
-------------------------------------------------------------------------
|
24
|
-
Processing by ApplicationController#index as HTML
|
25
|
-
Completed 200 OK in 0ms (Allocations: 91)
|
26
|
-
-------------------------------------------------------------------------------------
|
27
|
-
AngularRailsCsrfTest: test_a_post_raises_an_error_without_the_X-XSRF-TOKEN_header_set
|
28
|
-
-------------------------------------------------------------------------------------
|
29
|
-
Processing by ApplicationController#create as HTML
|
30
|
-
Can't verify CSRF token authenticity.
|
31
|
-
Completed 422 Unprocessable Entity in 0ms (Allocations: 182)
|
32
|
-
-----------------------------------------------------------
|
33
|
-
AngularRailsCsrfTest: test_a_custom_name_is_used_if_present
|
34
|
-
-----------------------------------------------------------
|
35
|
-
Processing by ApplicationController#index as HTML
|
36
|
-
Completed 200 OK in 0ms (Allocations: 114)
|
37
|
-
-----------------------------------------------------------------------------
|
38
|
-
AngularRailsCsrfTest: test_a_post_is_accepted_if_X-XSRF-TOKEN_is_set_properly
|
39
|
-
-----------------------------------------------------------------------------
|
40
|
-
Processing by ApplicationController#create as HTML
|
41
|
-
Completed 200 OK in 0ms (Allocations: 105)
|
42
|
-
------------------------------------------------------------------------------------
|
43
|
-
AngularRailsCsrfTest: test_secure_is_set_automatically_when_same_site_is_set_to_none
|
44
|
-
------------------------------------------------------------------------------------
|
45
|
-
Processing by ApplicationController#index as HTML
|
46
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
47
|
-
--------------------------------------------------------------------------------------------------------
|
48
|
-
AngularRailsCsrfTest: test_a_get_sets_the_XSRF-TOKEN_cookie_but_does_not_require_the_X-XSRF-TOKEN_header
|
49
|
-
--------------------------------------------------------------------------------------------------------
|
50
|
-
Processing by ApplicationController#index as HTML
|
51
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
52
|
-
-------------------------------------------------------------
|
53
|
-
AngularRailsCsrfTest: test_same_site_is_set_to_Lax_by_default
|
54
|
-
-------------------------------------------------------------
|
55
|
-
Processing by ApplicationController#index as HTML
|
56
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
57
|
-
---------------------------------------------------------------
|
58
|
-
AngularRailsCsrfTest: test_the_secure_flag_is_set_if_configured
|
59
|
-
---------------------------------------------------------------
|
60
|
-
Processing by ApplicationController#index as HTML
|
61
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
62
|
-
-----------------------------------------------------------------------------------------------------
|
63
|
-
AngularRailsCsrfTest: test_a_post_raises_an_error_with_the_X-XSRF-TOKEN_header_set_to_the_wrong_value
|
64
|
-
-----------------------------------------------------------------------------------------------------
|
65
|
-
Processing by ApplicationController#create as HTML
|
66
|
-
Can't verify CSRF token authenticity.
|
67
|
-
Completed 422 Unprocessable Entity in 0ms (Allocations: 110)
|
68
|
-
-----------------------------------------------------------------
|
69
|
-
AngularRailsCsrfTest: test_the_httponly_flag_is_set_if_configured
|
70
|
-
-----------------------------------------------------------------
|
71
|
-
Processing by ApplicationController#index as HTML
|
72
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
73
|
-
------------------------------------------------------------------------------------
|
74
|
-
AngularRailsCsrfTest: test_secure_is_set_automatically_when_same_site_is_set_to_none
|
75
|
-
------------------------------------------------------------------------------------
|
76
|
-
Processing by ApplicationController#index as HTML
|
77
|
-
Completed 200 OK in 0ms (Allocations: 342)
|
78
|
-
-----------------------------------------------------------------------------------------------------
|
79
|
-
AngularRailsCsrfTest: test_a_post_raises_an_error_with_the_X-XSRF-TOKEN_header_set_to_the_wrong_value
|
80
|
-
-----------------------------------------------------------------------------------------------------
|
81
|
-
Processing by ApplicationController#create as HTML
|
82
|
-
Can't verify CSRF token authenticity.
|
83
|
-
Completed 422 Unprocessable Entity in 0ms (Allocations: 200)
|
84
|
-
-----------------------------------------------------------
|
85
|
-
AngularRailsCsrfTest: test_a_custom_name_is_used_if_present
|
86
|
-
-----------------------------------------------------------
|
87
|
-
Processing by ApplicationController#index as HTML
|
88
|
-
Completed 200 OK in 0ms (Allocations: 113)
|
89
|
-
-----------------------------------------------------------------------------
|
90
|
-
AngularRailsCsrfTest: test_a_post_is_accepted_if_X-XSRF-TOKEN_is_set_properly
|
91
|
-
-----------------------------------------------------------------------------
|
92
|
-
Processing by ApplicationController#create as HTML
|
93
|
-
Completed 200 OK in 0ms (Allocations: 105)
|
94
|
-
-------------------------------------------------------------
|
95
|
-
AngularRailsCsrfTest: test_same_site_is_set_to_Lax_by_default
|
96
|
-
-------------------------------------------------------------
|
97
|
-
Processing by ApplicationController#index as HTML
|
98
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
99
|
-
------------------------------------------------------
|
100
|
-
AngularRailsCsrfTest: test_same_site_can_be_configured
|
101
|
-
------------------------------------------------------
|
102
|
-
Processing by ApplicationController#index as HTML
|
103
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
104
|
-
-------------------------------------------------------------------------
|
105
|
-
AngularRailsCsrfTest: test_csrf-cookie_is_not_set_if_exclusion_is_enabled
|
106
|
-
-------------------------------------------------------------------------
|
107
|
-
Processing by ApplicationController#index as HTML
|
108
|
-
Completed 200 OK in 0ms (Allocations: 91)
|
109
|
-
--------------------------------------------------------
|
110
|
-
AngularRailsCsrfTest: test_the_domain_is_used_if_present
|
111
|
-
--------------------------------------------------------
|
112
|
-
Processing by ApplicationController#index as HTML
|
113
|
-
Completed 200 OK in 0ms (Allocations: 112)
|
114
|
-
---------------------------------------------------------------
|
115
|
-
AngularRailsCsrfTest: test_the_secure_flag_is_set_if_configured
|
116
|
-
---------------------------------------------------------------
|
117
|
-
Processing by ApplicationController#index as HTML
|
118
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
119
|
-
--------------------------------------------------------------------------------------------------------
|
120
|
-
AngularRailsCsrfTest: test_a_get_sets_the_XSRF-TOKEN_cookie_but_does_not_require_the_X-XSRF-TOKEN_header
|
121
|
-
--------------------------------------------------------------------------------------------------------
|
122
|
-
Processing by ApplicationController#index as HTML
|
123
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
124
|
-
-----------------------------------------------------------------
|
125
|
-
AngularRailsCsrfTest: test_the_httponly_flag_is_set_if_configured
|
126
|
-
-----------------------------------------------------------------
|
127
|
-
Processing by ApplicationController#index as HTML
|
128
|
-
Completed 200 OK in 0ms (Allocations: 93)
|
129
|
-
-------------------------------------------------------------------------------------
|
130
|
-
AngularRailsCsrfTest: test_a_post_raises_an_error_without_the_X-XSRF-TOKEN_header_set
|
131
|
-
-------------------------------------------------------------------------------------
|
132
|
-
Processing by ApplicationController#create as HTML
|
133
|
-
Can't verify CSRF token authenticity.
|
134
|
-
Completed 422 Unprocessable Entity in 0ms (Allocations: 90)
|
135
|
-
-------------------------------------------------------------------------------------------------------------
|
136
|
-
AngularRailsCsrfSkipTest: test_csrf-cookie_is_not_set_and_no_error_if_protect_against_forgery?_is_not_defined
|
137
|
-
-------------------------------------------------------------------------------------------------------------
|
138
|
-
Processing by ApiController#index as HTML
|
139
|
-
Completed 200 OK in 0ms (Allocations: 100)
|
140
|
-
----------------------------------------------------------------------------
|
141
|
-
AngularRailsCsrfExceptionTest: test_a_get_does_not_set_the_XSRF-TOKEN_cookie
|
142
|
-
----------------------------------------------------------------------------
|
143
|
-
Processing by ExclusionsController#index as HTML
|
144
|
-
Completed 200 OK in 0ms (Allocations: 87)
|
data/test/test_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Configure Rails Environment
|
4
|
-
ENV['RAILS_ENV'] = 'test'
|
5
|
-
|
6
|
-
require 'simplecov'
|
7
|
-
SimpleCov.start do
|
8
|
-
add_filter 'test/'
|
9
|
-
add_filter '.github/'
|
10
|
-
end
|
11
|
-
|
12
|
-
if ENV['CI'] == 'true'
|
13
|
-
require 'codecov'
|
14
|
-
SimpleCov.formatter = SimpleCov::Formatter::Codecov
|
15
|
-
end
|
16
|
-
|
17
|
-
require File.expand_path('dummy/config/environment.rb', __dir__)
|
18
|
-
require 'rails/test_help'
|