omniauth-rails_csrf_protection 1.0.2 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca8b6b6b0f1b3f05b0317c4e0f629529a44158edc57497fee9eec34a1422125d
4
- data.tar.gz: 640c1535d81dea4a56fac9e851dc595f351d05dfc53e11ef3a720aeba1d2b770
3
+ metadata.gz: 156f0458f77fc7be417f9d4080ef3ca1c078b3ec97d2f5a260331f0ca7117ac8
4
+ data.tar.gz: 545b29f8d28c47803f9367bfcaccdcd412afd2d7e78bb571f46ef87b53ef6f14
5
5
  SHA512:
6
- metadata.gz: 9db585b6633c9a06372ed96fd2c4a59502d75f7eb39c69f25c92bd0706ad5d2f0ae03d8471fd8ff19342cf98b01159ed742251eb568b200960eb031956b3976a
7
- data.tar.gz: d6ff32d88319e0072a760853da4a7dca07bfab9ad6a5243552df8eeb7a603ee133f69a38686ce3d591c29b4bb131217348c0a6bc8010c1e45aea3478235e0cb5
6
+ metadata.gz: e23fceeb38d067b51e3a6751b194f9c47bcbb706919aa16024bf4e5f568c2168403c9346f0e4202c3c1dd54db6b4f46e20c70aaa3ac45e74852f5d4e2aaedf53
7
+ data.tar.gz: c4daf8660e73c639a123e8246c3e86583b951d6f6b546590b4467981fc52952e014e08f7092c3a2c3c164f88fdc218c52f2d77331f7d5fd0182f1375a5f2d94c
data/README.md CHANGED
@@ -7,6 +7,21 @@ application) by implementing a CSRF token verifier that directly uses
7
7
 
8
8
  [CVE-2015-9284]: https://nvd.nist.gov/vuln/detail/CVE-2015-9284
9
9
 
10
+ > [!NOTE]
11
+ > [OmniAuth] has provided a built-in solution to mitigate against
12
+ > [CVE-2015-9284] since [version 2.0.0].
13
+ > You should be able to mitigate against this vulnerability
14
+ > by adding this configuration to your application:
15
+ >
16
+ > ```ruby
17
+ > OmniAuth.config.request_validation_phase = OmniAuth::AuthenticityTokenProtection.new(key: :_csrf_token)
18
+ > ```
19
+ >
20
+ > This gem will continued to be maintained as an alternative to the solution above.
21
+
22
+ [OmniAuth]: https://github.com/omniauth/omniauth
23
+ [Version 2.0.0]: https://github.com/omniauth/omniauth/releases/tag/v2.0.0
24
+
10
25
  ## Usage
11
26
 
12
27
  Add this line to your application's Gemfile:
@@ -1,6 +1,10 @@
1
- require "active_support/configurable"
1
+ require "action_pack/version"
2
2
  require "action_controller"
3
3
 
4
+ unless ActionPack.version >= Gem::Version.new("8.1.a")
5
+ require "active_support/configurable"
6
+ end
7
+
4
8
  module OmniAuth
5
9
  module RailsCsrfProtection
6
10
  # Provides a callable method that verifies Cross-Site Request Forgery
@@ -13,17 +17,37 @@ module OmniAuth
13
17
  # authenticity token, you can find the source code at
14
18
  # https://github.com/rails/rails/blob/v5.2.2/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L217-L240.
15
19
  class TokenVerifier
16
- include ActiveSupport::Configurable
17
- include ActionController::RequestForgeryProtection
18
-
19
- # `ActionController::RequestForgeryProtection` contains a few
20
- # configurable options. As we want to make sure that our configuration is
21
- # the same as what being set in `ActionController::Base`, we should make
22
- # all out configuration methods to delegate to `ActionController::Base`.
23
- config.each_key do |configuration_name|
24
- undef_method configuration_name
25
- define_method configuration_name do
26
- ActionController::Base.config[configuration_name]
20
+ if ActionPack.version >= Gem::Version.new("8.1.a")
21
+ # `ActiveSupport::Configurable` is deprecated in Rails 8.1 and will be
22
+ # removed in Rails 8.2. As `ActionController::RequestForgeryProtection`
23
+ # directly accesing configurations via `config`, we only need to define
24
+ # these methods and delegate them to `ActionController::Base.config`.
25
+ def self.config
26
+ ActionController::Base.config
27
+ end
28
+
29
+ def config
30
+ self.class.config
31
+ end
32
+
33
+ # For Rails 8.1+, includes this module after `config` is setup.
34
+ include ActionController::RequestForgeryProtection
35
+ else
36
+ include ActiveSupport::Configurable
37
+
38
+ # For Rails < 8.1, includes this module before delegation setup.
39
+ # Otherwise, `config` will be empty, and the delegation will fail.
40
+ include ActionController::RequestForgeryProtection
41
+
42
+ # `ActionController::RequestForgeryProtection` contains a few
43
+ # configurable options. As we want to make sure that our configuration is
44
+ # the same as what being set in `ActionController::Base`, we should make
45
+ # all out configuration methods to delegate to `ActionController::Base`.
46
+ config.each_key do |configuration_name|
47
+ undef_method configuration_name if defined?(configuration_name)
48
+ define_method configuration_name do
49
+ ActionController::Base.config[configuration_name]
50
+ end
27
51
  end
28
52
  end
29
53
 
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module RailsCsrfProtection
3
- VERSION = "1.0.2".freeze
3
+ VERSION = "2.0.1".freeze
4
4
  end
5
5
  end
@@ -13,14 +13,14 @@ class ApplicationTest < Minitest::Test
13
13
  post "/auth/developer"
14
14
  follow_redirect!
15
15
 
16
- assert last_response.not_found?
16
+ assert_equal "ActionController::InvalidAuthenticityToken", last_response.body
17
17
  end
18
18
 
19
19
  def test_request_phrase_with_bad_token_via_post
20
20
  post "/auth/developer", authenticity_token: "BAD_TOKEN"
21
21
  follow_redirect!
22
22
 
23
- assert last_response.not_found?
23
+ assert_equal "ActionController::InvalidAuthenticityToken", last_response.body
24
24
  end
25
25
 
26
26
  def test_request_phrase_with_correct_token_via_post
@@ -0,0 +1,38 @@
1
+ require "test_helper"
2
+ require "capybara/rails"
3
+ require "capybara/minitest"
4
+
5
+ class IntegrationTest < ActionDispatch::IntegrationTest
6
+ include Capybara::DSL
7
+ include Capybara::Minitest::Assertions
8
+
9
+ # We are using this `:per_form_csrf_tokens` as a way to test that we have
10
+ # setup method delegation properly to prevent regression, as Railtie sets
11
+ # this configuration to true afterward and causes them to be out-of-sync.
12
+ setup do
13
+ @original_per_form_csrf_tokens = \
14
+ ActionController::Base.config[:per_form_csrf_tokens]
15
+ ActionController::Base.config[:per_form_csrf_tokens] = true
16
+ end
17
+
18
+ teardown do
19
+ ActionController::Base.config[:per_form_csrf_tokens] = \
20
+ @original_per_form_csrf_tokens
21
+
22
+ Capybara.reset_sessions!
23
+ Capybara.use_default_driver
24
+ end
25
+
26
+ def test_request_phrase
27
+ visit sign_in_path
28
+ click_on "Sign in"
29
+
30
+ refute page.has_content?("ActionController::InvalidAuthenticityToken")
31
+
32
+ fill_in "Name", with: "Kagari Mimi"
33
+ fill_in "Email", with: "mimi@example.com"
34
+ click_on "Sign In"
35
+
36
+ assert page.has_content?("Hello Kagari Mimi (mimi@example.com)!")
37
+ end
38
+ end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
2
2
 
3
3
  # Simple Rails application template, based on Rails issue template
4
- # https://github.com/rails/rails/blob/master/guides/bug_report_templates/action_controller_gem.rb
4
+ # https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller.rb
5
5
 
6
6
  # Helper method to silence warnings from bundler/inline
7
7
  def silence_warnings
@@ -13,6 +13,7 @@ end
13
13
 
14
14
  silence_warnings do
15
15
  require "bundler/inline"
16
+ require "logger"
16
17
 
17
18
  # Define dependencies required by this test app
18
19
  gemfile do
@@ -24,12 +25,19 @@ silence_warnings do
24
25
  gem "rails"
25
26
  end
26
27
 
28
+ if RUBY_VERSION >= "3.4"
29
+ gem "bigdecimal"
30
+ gem "drb"
31
+ gem "mutex_m"
32
+ end
33
+
34
+ gem "capybara"
27
35
  gem "omniauth"
28
36
  gem "omniauth-rails_csrf_protection", path: File.expand_path("..", __dir__)
29
37
  end
30
38
  end
31
39
 
32
- puts "Running test against Rails #{Rails.version}"
40
+ puts "Running test on Ruby #{RUBY_VERSION} against Rails #{Rails.version}"
33
41
 
34
42
  require "rack/test"
35
43
  require "action_controller/railtie"
@@ -57,12 +65,20 @@ class TestApp < Rails::Application
57
65
  provider :developer
58
66
  end
59
67
 
68
+ # Silence the deprecation warning in Rails 8.0.x
69
+ if Gem::Requirement.new("~> 8.0.x").satisfied_by?(Rails.gem_version)
70
+ config.active_support.to_time_preserves_timezone = :zone
71
+ end
72
+
60
73
  # We need to call initialize! to run all railties
61
74
  initialize!
62
75
 
63
76
  # Define our custom routes. This needs to be called after initialize!
64
77
  routes.draw do
78
+ get "sign_in" => "application#sign_in"
65
79
  get "token" => "application#token"
80
+ get "auth/failure" => "application#failure"
81
+ match "auth/developer/callback" => "application#callback", :via => [:get, :post]
66
82
  end
67
83
  end
68
84
 
@@ -71,4 +87,18 @@ class ApplicationController < ActionController::Base
71
87
  def token
72
88
  render plain: form_authenticity_token
73
89
  end
90
+
91
+ def sign_in
92
+ render inline: <<~ERB
93
+ <%= button_to "Sign in", "/auth/developer", method: :post %>
94
+ ERB
95
+ end
96
+
97
+ def failure
98
+ render plain: params[:message]
99
+ end
100
+
101
+ def callback
102
+ render plain: "Hello #{params[:name]} (#{params[:email]})!"
103
+ end
74
104
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-rails_csrf_protection
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cookpad Inc.
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: actionpack
@@ -53,7 +52,7 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '0'
55
54
  - !ruby/object:Gem::Dependency
56
- name: minitest
55
+ name: capybara
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - ">="
@@ -67,7 +66,7 @@ dependencies:
67
66
  - !ruby/object:Gem::Version
68
67
  version: '0'
69
68
  - !ruby/object:Gem::Dependency
70
- name: rails
69
+ name: minitest
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
72
  - - ">="
@@ -80,6 +79,20 @@ dependencies:
80
79
  - - ">="
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rails
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 7.2.0
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 7.2.0
83
96
  - !ruby/object:Gem::Dependency
84
97
  name: rake
85
98
  requirement: !ruby/object:Gem::Requirement
@@ -112,12 +125,12 @@ files:
112
125
  - lib/omniauth/rails_csrf_protection/token_verifier.rb
113
126
  - lib/omniauth/rails_csrf_protection/version.rb
114
127
  - test/application_test.rb
128
+ - test/integration_test.rb
115
129
  - test/test_helper.rb
116
130
  homepage: https://github.com/cookpad/omniauth-rails_csrf_protection
117
131
  licenses:
118
132
  - MIT
119
133
  metadata: {}
120
- post_install_message:
121
134
  rdoc_options: []
122
135
  require_paths:
123
136
  - lib
@@ -132,10 +145,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
145
  - !ruby/object:Gem::Version
133
146
  version: '0'
134
147
  requirements: []
135
- rubygems_version: 3.5.3
136
- signing_key:
148
+ rubygems_version: 3.6.9
137
149
  specification_version: 4
138
150
  summary: Provides CSRF protection on OmniAuth request endpoint on Rails application.
139
151
  test_files:
140
152
  - test/application_test.rb
153
+ - test/integration_test.rb
141
154
  - test/test_helper.rb