angular_rails_csrf 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/lib/angular_rails_csrf/concern.rb +2 -1
- data/lib/angular_rails_csrf/version.rb +1 -1
- data/test/angular_rails_csrf_test.rb +19 -2
- data/test/dummy/log/test.log +74 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23f8e3de78f91c8563e49d21563888ab0f9c78a42d7cffa09f54c52f24df018f
|
4
|
+
data.tar.gz: 23f75e27ec3de7cea6979085ef82eebd2d07e54eb5e83801cfdb9ce40cbdec46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8c1eb3dcb33b1df34435106c723639916a3acb0761b21e3551c15af7fecc19bf0a9debb6d36cdcf8d8f23973e65dd790c2b78e471546862341a7ba0e658d234
|
7
|
+
data.tar.gz: 4742c340abc02322ed6cfd5687d77f2461cfbc0b36e3d6c431ac168abad7bb02a893b6a474e019f0b6d6de879cb07564151e0fec53582730eded5798fa88cfd7
|
data/README.md
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/angular_rails_csrf.svg)](https://badge.fury.io/rb/angular_rails_csrf)
|
4
4
|
[![Build Status](https://travis-ci.org/jsanders/angular_rails_csrf.png)](https://travis-ci.org/jsanders/angular_rails_csrf)
|
5
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/jsanders/angular_rails_csrf.svg)](https://gemnasium.com/github.com/jsanders/angular_rails_csrf)
|
6
5
|
|
7
6
|
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.
|
8
7
|
|
@@ -25,6 +24,19 @@ And then execute:
|
|
25
24
|
That's it!
|
26
25
|
|
27
26
|
## Configuration
|
27
|
+
|
28
|
+
### Cookie Name
|
29
|
+
|
30
|
+
The default cookie's name is `XSRF-TOKEN` but it can be configured with the `angular_rails_csrf_cookie_name` setting:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# application.rb
|
34
|
+
class Application < Rails::Application
|
35
|
+
#...
|
36
|
+
config.angular_rails_csrf_cookie_name = 'CUSTOM_NAME'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
28
40
|
### Cookie Domain
|
29
41
|
|
30
42
|
Starting from version 3, you may set domain for the XSRF cookie:
|
@@ -67,4 +79,4 @@ $ rake test
|
|
67
79
|
|
68
80
|
## License
|
69
81
|
|
70
|
-
Licensed under the [MIT License](https://github.com/jsanders/angular_rails_csrf/blob/master/LICENSE).
|
82
|
+
Licensed under the [MIT License](https://github.com/jsanders/angular_rails_csrf/blob/master/LICENSE).
|
@@ -10,7 +10,8 @@ module AngularRailsCsrf
|
|
10
10
|
if protect_against_forgery? && !respond_to?(:__exclude_xsrf_token_cookie?)
|
11
11
|
config = Rails.application.config
|
12
12
|
domain = config.respond_to?(:angular_rails_csrf_domain) ? config.angular_rails_csrf_domain : nil
|
13
|
-
|
13
|
+
cookie_name = config.respond_to?(:angular_rails_csrf_cookie_name) ? config.angular_rails_csrf_cookie_name : 'XSRF-TOKEN'
|
14
|
+
cookies[cookie_name] = { value: form_authenticity_token, domain: domain }
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -39,6 +39,15 @@ class AngularRailsCsrfTest < ActionController::TestCase
|
|
39
39
|
assert_response :success
|
40
40
|
end
|
41
41
|
|
42
|
+
test "a custom name is used if present" do
|
43
|
+
use_custom_cookie_name do
|
44
|
+
get :index
|
45
|
+
assert @response.headers['Set-Cookie'].include?('CUSTOM-COOKIE-NAME')
|
46
|
+
assert_valid_cookie('CUSTOM-COOKIE-NAME')
|
47
|
+
assert_response :success
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
42
51
|
private
|
43
52
|
|
44
53
|
# Helpers
|
@@ -47,11 +56,19 @@ class AngularRailsCsrfTest < ActionController::TestCase
|
|
47
56
|
@request.headers['X-XSRF-TOKEN'] = value
|
48
57
|
end
|
49
58
|
|
50
|
-
def assert_valid_cookie
|
59
|
+
def assert_valid_cookie(name = 'XSRF-TOKEN')
|
51
60
|
if @controller.respond_to?(:valid_authenticity_token?, true)
|
52
|
-
assert @controller.send(:valid_authenticity_token?, session, cookies[
|
61
|
+
assert @controller.send(:valid_authenticity_token?, session, cookies[name])
|
53
62
|
else
|
54
63
|
assert_equal @controller.send(:form_authenticity_token), cookies['XSRF-TOKEN']
|
55
64
|
end
|
56
65
|
end
|
66
|
+
|
67
|
+
def use_custom_cookie_name
|
68
|
+
config = Rails.application.config
|
69
|
+
def config.angular_rails_csrf_cookie_name; 'CUSTOM-COOKIE-NAME'; end
|
70
|
+
yield
|
71
|
+
ensure
|
72
|
+
config.instance_eval('undef :angular_rails_csrf_cookie_name')
|
73
|
+
end
|
57
74
|
end
|
data/test/dummy/log/test.log
CHANGED
@@ -405,3 +405,77 @@ AngularRailsCsrfTest: test_a_post_is_accepted_if_X-XSRF-TOKEN_is_set_properly
|
|
405
405
|
-----------------------------------------------------------------------------
|
406
406
|
Processing by ApplicationController#create as HTML
|
407
407
|
Completed 200 OK in 0ms
|
408
|
+
-------------------------------------------------------------------------------------
|
409
|
+
AngularRailsCsrfTest: test_a_post_raises_an_error_without_the_X-XSRF-TOKEN_header_set
|
410
|
+
-------------------------------------------------------------------------------------
|
411
|
+
Processing by ApplicationController#create as HTML
|
412
|
+
Can't verify CSRF token authenticity.
|
413
|
+
Completed 422 Unprocessable Entity in 0ms
|
414
|
+
--------------------------------------------------------
|
415
|
+
AngularRailsCsrfTest: test_the_domain_is_used_if_present
|
416
|
+
--------------------------------------------------------
|
417
|
+
Processing by ApplicationController#index as HTML
|
418
|
+
Completed 200 OK in 0ms
|
419
|
+
-----------------------------------------------------------------------------------------------------
|
420
|
+
AngularRailsCsrfTest: test_a_post_raises_an_error_with_the_X-XSRF-TOKEN_header_set_to_the_wrong_value
|
421
|
+
-----------------------------------------------------------------------------------------------------
|
422
|
+
Processing by ApplicationController#create as HTML
|
423
|
+
Can't verify CSRF token authenticity.
|
424
|
+
Completed 422 Unprocessable Entity in 0ms
|
425
|
+
-----------------------------------------------------------
|
426
|
+
AngularRailsCsrfTest: test_a_custom_name_is_used_if_present
|
427
|
+
-----------------------------------------------------------
|
428
|
+
Processing by ApplicationController#index as HTML
|
429
|
+
Completed 200 OK in 1ms
|
430
|
+
-----------------------------------------------------------------------------
|
431
|
+
AngularRailsCsrfTest: test_a_post_is_accepted_if_X-XSRF-TOKEN_is_set_properly
|
432
|
+
-----------------------------------------------------------------------------
|
433
|
+
Processing by ApplicationController#create as HTML
|
434
|
+
Completed 200 OK in 0ms
|
435
|
+
--------------------------------------------------------------------------------------------------------
|
436
|
+
AngularRailsCsrfTest: test_a_get_sets_the_XSRF-TOKEN_cookie_but_does_not_require_the_X-XSRF-TOKEN_header
|
437
|
+
--------------------------------------------------------------------------------------------------------
|
438
|
+
Processing by ApplicationController#index as HTML
|
439
|
+
Completed 200 OK in 0ms
|
440
|
+
----------------------------------------------------------------------------
|
441
|
+
AngularRailsCsrfExceptionTest: test_a_get_does_not_set_the_XSRF-TOKEN_cookie
|
442
|
+
----------------------------------------------------------------------------
|
443
|
+
Processing by ExclusionsController#index as HTML
|
444
|
+
Completed 200 OK in 0ms
|
445
|
+
--------------------------------------------------------------------------------------------------------
|
446
|
+
AngularRailsCsrfTest: test_a_get_sets_the_XSRF-TOKEN_cookie_but_does_not_require_the_X-XSRF-TOKEN_header
|
447
|
+
--------------------------------------------------------------------------------------------------------
|
448
|
+
Processing by ApplicationController#index as HTML
|
449
|
+
Completed 200 OK in 0ms
|
450
|
+
-----------------------------------------------------------------------------------------------------
|
451
|
+
AngularRailsCsrfTest: test_a_post_raises_an_error_with_the_X-XSRF-TOKEN_header_set_to_the_wrong_value
|
452
|
+
-----------------------------------------------------------------------------------------------------
|
453
|
+
Processing by ApplicationController#create as HTML
|
454
|
+
Can't verify CSRF token authenticity.
|
455
|
+
Completed 422 Unprocessable Entity in 0ms
|
456
|
+
-----------------------------------------------------------------------------
|
457
|
+
AngularRailsCsrfTest: test_a_post_is_accepted_if_X-XSRF-TOKEN_is_set_properly
|
458
|
+
-----------------------------------------------------------------------------
|
459
|
+
Processing by ApplicationController#create as HTML
|
460
|
+
Completed 200 OK in 0ms
|
461
|
+
-----------------------------------------------------------
|
462
|
+
AngularRailsCsrfTest: test_a_custom_name_is_used_if_present
|
463
|
+
-----------------------------------------------------------
|
464
|
+
Processing by ApplicationController#index as HTML
|
465
|
+
Completed 200 OK in 0ms
|
466
|
+
--------------------------------------------------------
|
467
|
+
AngularRailsCsrfTest: test_the_domain_is_used_if_present
|
468
|
+
--------------------------------------------------------
|
469
|
+
Processing by ApplicationController#index as HTML
|
470
|
+
Completed 200 OK in 0ms
|
471
|
+
-------------------------------------------------------------------------------------
|
472
|
+
AngularRailsCsrfTest: test_a_post_raises_an_error_without_the_X-XSRF-TOKEN_header_set
|
473
|
+
-------------------------------------------------------------------------------------
|
474
|
+
Processing by ApplicationController#create as HTML
|
475
|
+
Can't verify CSRF token authenticity.
|
476
|
+
Completed 422 Unprocessable Entity in 0ms
|
477
|
+
----------------------------------------------------------------------------
|
478
|
+
AngularRailsCsrfExceptionTest: test_a_get_does_not_set_the_XSRF-TOKEN_cookie
|
479
|
+
----------------------------------------------------------------------------
|
480
|
+
Processing by ExclusionsController#index as HTML
|
481
|
+
Completed 200 OK in 0ms
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: angular_rails_csrf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Sanders
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2018-
|
12
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|