Skip to content

Commit b40626a

Browse files
committed
Version 4.2.0
1 parent 8746e96 commit b40626a

File tree

7 files changed

+43
-16
lines changed

7 files changed

+43
-16
lines changed

.rubocop.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ Layout/LineLength:
2121

2222
Metrics/MethodLength:
2323
CountComments: false
24-
Max: 10
24+
Max: 15
2525

2626
Metrics/ModuleLength:
27-
Max: 100
27+
Max: 150
28+
29+
Metrics/ClassLength:
30+
Max: 150
2831

2932
Metrics/ParameterLists:
3033
Max: 5
@@ -63,4 +66,4 @@ Style/HashTransformKeys:
6366
Enabled: false
6467

6568
Style/HashTransformValues:
66-
Enabled: false
69+
Enabled: false

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 4.2.0 (31-Mar-20)
4+
5+
* 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))
6+
+ This option is introduced to comply with the latest changes: https://www.chromium.org/updates/same-site
7+
* Update cops
8+
39
## 4.1.0 (03-Feb-20)
410

511
* Added a new [`angular_rails_csrf_secure` option](https://github.com/jsanders/angular_rails_csrf#secure-cookie) (thanks, [@DougKeller](https://github.com/DougKeller))

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ end
6868

6969
### SameSite
7070

71-
The SameSite attribute now defaults to `:lax`. You can override this in the config:
71+
The SameSite attribute defaults to `:lax`. You can override this in the config:
7272

7373
```ruby
7474
# application.rb
@@ -78,7 +78,7 @@ class Application < Rails::Application
7878
end
7979
```
8080

81-
**NOTE**: When using `SameSite=None`, this gem automatically sets the cookie to `Secure`.
81+
**NOTE**: When using `config.angular_rails_csrf_same_site = :none`, this gem automatically sets the cookie to `Secure` (`config.angular_rails_csrf_secure = true`) to comply with [the specifications](https://tools.ietf.org/html/draft-west-cookie-incrementalism-00).
8282

8383
### Exclusions
8484

angular_rails_csrf.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
2424
s.add_development_dependency 'rake', '~> 13.0'
2525
s.add_development_dependency 'test-unit', '~> 3.2'
2626
if ENV['TEST_RAILS_VERSION'].nil?
27-
s.add_development_dependency 'rails', '6.0.2.1'
27+
s.add_development_dependency 'rails', '6.0.2.2'
2828
else
2929
s.add_development_dependency 'rails', ENV['TEST_RAILS_VERSION'].to_s
3030
end

lib/angular_rails_csrf/concern.rb

+23-5
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ def set_xsrf_token_cookie
1313

1414
config = Rails.application.config
1515

16-
same_site = config.respond_to?(:angular_rails_csrf_same_site) ? config.angular_rails_csrf_same_site : :lax
17-
secure = config.angular_rails_csrf_secure if config.respond_to?(:angular_rails_csrf_secure)
16+
same_site = same_site_from config
17+
secure = secure_from config
1818

1919
cookie_options = {
2020
value: form_authenticity_token,
21-
domain: config.respond_to?(:angular_rails_csrf_domain) ? config.angular_rails_csrf_domain : nil,
21+
domain: domain_from(config),
2222
same_site: same_site,
23-
secure: same_site == :none || secure
23+
secure: same_site.eql?(:none) || secure
2424
}
2525

26-
cookie_name = config.respond_to?(:angular_rails_csrf_cookie_name) ? config.angular_rails_csrf_cookie_name : 'XSRF-TOKEN'
26+
cookie_name = cookie_name_from config
2727
cookies[cookie_name] = cookie_options
2828
end
2929

@@ -35,6 +35,24 @@ def verified_request?
3535
end
3636
end
3737

38+
private
39+
40+
def same_site_from(config)
41+
config.respond_to?(:angular_rails_csrf_same_site) ? config.angular_rails_csrf_same_site : :lax
42+
end
43+
44+
def secure_from(config)
45+
config.angular_rails_csrf_secure if config.respond_to?(:angular_rails_csrf_secure)
46+
end
47+
48+
def domain_from(config)
49+
config.respond_to?(:angular_rails_csrf_domain) ? config.angular_rails_csrf_domain : nil
50+
end
51+
52+
def cookie_name_from(config)
53+
config.respond_to?(:angular_rails_csrf_cookie_name) ? config.angular_rails_csrf_cookie_name : 'XSRF-TOKEN'
54+
end
55+
3856
module ClassMethods
3957
def exclude_xsrf_token_cookie
4058
class_eval do

lib/angular_rails_csrf/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module AngularRailsCsrf
4-
VERSION = '4.1.0'
4+
VERSION = '4.2.0'
55
end

test/angular_rails_csrf_test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def config.angular_rails_csrf_domain
7474
end
7575

7676
test 'same_site is set to Lax by default' do
77-
get :index
78-
assert @response.headers['Set-Cookie'].include?('SameSite=Lax')
79-
assert_valid_cookie
80-
assert_response :success
77+
get :index
78+
assert @response.headers['Set-Cookie'].include?('SameSite=Lax')
79+
assert_valid_cookie
80+
assert_response :success
8181
end
8282

8383
test 'same_site can be configured' do

0 commit comments

Comments
 (0)