Skip to content

Commit 88823a8

Browse files
committed
Version 4.5.0
1 parent a29bd58 commit 88823a8

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

CHANGELOG.md

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

3+
## 4.5.0 (21-Sep-20)
4+
5+
* Added a new [`HttpOnly` option](https://github.com/jsanders/angular_rails_csrf#httponly-cookie) (thanks, [@Lubo-mir](https://github.com/Lubo-mir))
6+
* Introduced some code refactorings
7+
38
## 4.4.0 (04-Aug-20)
49

510
* 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))

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Please note that [Safari is known to have issues](https://bugs.webkit.org/show_b
8484

8585
### HttpOnly Cookie
8686

87-
To set a "httponly" flag for the cookie, set the `angular_rails_csrf_httponly` option to `true`:
87+
To set the ["httponly" flag](https://owasp.org/www-community/HttpOnly) for your cookie, set the `angular_rails_csrf_httponly` option to `true`:
8888

8989
```ruby
9090
# application.rb

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.3.2'
27+
s.add_development_dependency 'rails', '6.0.3.3'
2828
else
2929
s.add_development_dependency 'rails', ENV['TEST_RAILS_VERSION'].to_s
3030
end

lib/angular_rails_csrf/concern.rb

+11-24
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@ def set_xsrf_token_cookie
1313

1414
config = Rails.application.config
1515

16-
same_site = same_site_from config
17-
httponly = httponly_from config
18-
secure = secure_from config
16+
secure = option_from config, :angular_rails_csrf_secure
17+
same_site = option_from config, :angular_rails_csrf_same_site, :lax
1918

2019
cookie_options = {
2120
value: form_authenticity_token,
22-
domain: domain_from(config),
21+
domain: option_from(config, :angular_rails_csrf_domain),
2322
same_site: same_site,
24-
httponly: httponly,
23+
httponly: option_from(config, :angular_rails_csrf_httponly, false),
2524
secure: same_site.eql?(:none) || secure
2625
}
2726

28-
cookie_name = cookie_name_from config
27+
cookie_name = option_from(config,
28+
:angular_rails_csrf_cookie_name,
29+
'XSRF-TOKEN')
2930
cookies[cookie_name] = cookie_options
3031
end
3132

@@ -35,24 +36,10 @@ def verified_request?
3536

3637
private
3738

38-
def same_site_from(config)
39-
config.respond_to?(:angular_rails_csrf_same_site) ? config.angular_rails_csrf_same_site : :lax
40-
end
41-
42-
def httponly_from(config)
43-
config.respond_to?(:angular_rails_csrf_httponly) ? config.angular_rails_csrf_httponly : false
44-
end
45-
46-
def secure_from(config)
47-
config.angular_rails_csrf_secure if config.respond_to?(:angular_rails_csrf_secure)
48-
end
49-
50-
def domain_from(config)
51-
config.respond_to?(:angular_rails_csrf_domain) ? config.angular_rails_csrf_domain : nil
52-
end
53-
54-
def cookie_name_from(config)
55-
config.respond_to?(:angular_rails_csrf_cookie_name) ? config.angular_rails_csrf_cookie_name : 'XSRF-TOKEN'
39+
# Fetches the given option from config
40+
# If the option is not set, return a default value
41+
def option_from(config, option, default = nil)
42+
config.respond_to?(option) ? config.send(option) : default
5643
end
5744

5845
module ClassMethods

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.4.0'
4+
VERSION = '4.5.0'
55
end

0 commit comments

Comments
 (0)