authenticate 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba37abc88aa432eb70096681623f51de2ccac5fb
4
- data.tar.gz: d836124e6f702044bdaa98d4cb46a54967c586b8
3
+ metadata.gz: a77403e50b229de8318c79477ee44062589afb05
4
+ data.tar.gz: c6bf923d8809f923a48cb4211d97dd406b42e03f
5
5
  SHA512:
6
- metadata.gz: d2e1fe07144aee9fb948d4f8b6b0932785ba2ce0dc00ca927d17a9e5dc1529cecbd121ccdf985388176e62c7315723ec78f5b956e2f29d4fd6a1c0b88fa980c9
7
- data.tar.gz: 95b8c5be797479eb243ba7b45f3833033aafab28f54a0f7579127387754d5a40018356c39f0f9411f86a0ee4dfc9e38e6acf1e9088dde16eae679926d19d396b
6
+ metadata.gz: 55cd9cb2b412bb87ebe3d6e6a46ce89eebd23147946aaa31b0f7e3fbf566f24bdf237a010be18eb6b1cb785d424821df3e9a55ad798b18b420246d6a18cfa963
7
+ data.tar.gz: 5f5f9aeaf98ce47c9ce16d90c7ebcc7930fc58a2013c909fdec27c18979e4fe3b0821a6075eecab22d5433fc7dd21d9071d28cc7493f53116d4fbf18f9000a74
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ spec/dummy/log/test.log
10
10
  spec/dummy/log/development.log
11
11
  /.idea
12
12
  Gemfile.lock
13
+ *.gemfile.lock
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.0
1
+ 2.4.1
data/.travis.yml CHANGED
@@ -1,17 +1,24 @@
1
- language: ruby
1
+ cache: bundler
2
+
3
+ language:
4
+ - ruby
2
5
 
3
6
  rvm:
4
7
  - 2.1.8
5
8
  - 2.2.4
6
- - 2.3.0
9
+ - 2.3.3
7
10
 
8
11
  gemfile:
9
- - gemfiles/rails42.gemfile
12
+ - gemfiles/4.2.gemfile
13
+ - gemfiles/5.0.gemfile
10
14
 
11
- branches:
12
- only:
13
- - master
14
15
 
15
- sudo: false
16
+ matrix:
17
+ exclude:
18
+ - rvm: 2.1.8
19
+ gemfile: gemfiles/5.0.gemfile
16
20
 
17
- script: bundle exec rspec --color --format documentation
21
+ install:
22
+ - "bin/setup"
23
+
24
+ sudo: false
data/Appraisals ADDED
@@ -0,0 +1,10 @@
1
+ appraise "4.2" do
2
+ gem "rails", "~> 4.2.0"
3
+ end
4
+
5
+ if RUBY_VERSION >= "2.2.0"
6
+ appraise "5.0" do
7
+ gem "rails", "~> 5.0.0"
8
+ end
9
+ end
10
+
data/CHANGELOG.md CHANGED
@@ -1,8 +1,40 @@
1
1
  # Authenticate Changelog
2
2
 
3
+
4
+ ## [0.6.0] - May 16, 2017
5
+
6
+ ### Security
7
+ - Prevent [password reset token leakage] through HTTP referrer across domains. password#edit removes the password
8
+ reset token from the url, sets it into the user's session (typically a cookie), and redirects to password#url
9
+ without the token in the url.
10
+
11
+ - Prevent [session fixation] attacks by rotating CSRF tokens on sign-in by setting
12
+ `Authentication.configuration.rotate_csrf_on_sign_in` to `true`. This is recommended for
13
+ all applications. The setting defaults to `false` in this release, but will default to `true`
14
+ in a future release.
15
+
16
+ ### Fixed
17
+ - Location to return to after login is now written to session. Was previously written explicitly to a cookie.
18
+ - Most controller tests rewritten as feature and request tests.
19
+
20
+ [password reset token leakage]: https://security.stackexchange.com/questions/69074/how-to-implement-password-reset-functionality-without-becoming-susceptible-to-cr
21
+ [session fixation]: http://guides.rubyonrails.org/security.html#session-fixation
22
+ [0.6.0]: https://github.com/tomichj/authenticate/compare/v0.5.0...v0.6.0
23
+
24
+
25
+
26
+ ## [0.5.0] - March 26, 2017
27
+
28
+ ### Support for rails 5.1.
29
+
30
+ [0.5.0]: https://github.com/tomichj/authenticate/compare/v0.4.0...v0.5.0
31
+
32
+
33
+
3
34
  ## [0.4.0] - June 2, 2016
4
35
 
5
- Install generator User: ActiveRecord::Base for Rails 4 apps, ApplicationRecord for rails 5 (issue #2).
36
+ ### Fixed
37
+ - Install generator User: ActiveRecord::Base for Rails 4 apps, ApplicationRecord for rails 5 (issue #2).
6
38
 
7
39
  [0.4.0]: https://github.com/tomichj/authenticate/compare/v0.3.3...v0.4.0
8
40
 
@@ -10,10 +42,10 @@ Install generator User: ActiveRecord::Base for Rails 4 apps, ApplicationRecord
10
42
 
11
43
  ## [0.3.3] - April 29, 2016
12
44
 
13
- Password change uses active record's dirty bit to detect that password was updated.
14
- password_updated attribute removed.
15
- spec_helper now calls ActiveRecord::Migration.maintain_test_schema! (or check_pending!) to handle dummy test db.
16
- Added CodeClimate config.
45
+ - Password change uses active record's dirty bit to detect that password was updated.
46
+ - password_updated attribute removed.
47
+ - spec_helper now calls ActiveRecord::Migration.maintain_test_schema! (or check_pending!) to handle dummy test db.
48
+ - Added CodeClimate config.
17
49
 
18
50
  [0.3.3]: https://github.com/tomichj/authenticate/compare/v0.3.2...v0.3.3
19
51
 
@@ -21,8 +53,8 @@ Added CodeClimate config.
21
53
 
22
54
  ## [0.3.2] - April 28, 2016
23
55
 
24
- Error now raised if User model is missing required attributes.
25
- All code now conforms to a rubocode profile.
56
+ - Error now raised if User model is missing required attributes.
57
+ - All code now conforms to a rubocode profile.
26
58
 
27
59
  [0.3.2]: https://github.com/tomichj/authenticate/compare/v0.3.1...v0.3.2
28
60
 
@@ -30,11 +62,10 @@ All code now conforms to a rubocode profile.
30
62
 
31
63
  ## [0.3.1] - March 10, 2016
32
64
 
33
- User controller now allows arbitrary parameters without having to explicitly declare
34
- them. Still requires email and password.
35
- Mailer now checks for mail.respond_to?(:deliver_later) rather than rails version,
36
- to decide deliver vs deliver_later.
37
- Removed unused user_id_parameter config method.
65
+ - User controller now allows arbitrary parameters without having to explicitly declare
66
+ them. Still requires email and password.
67
+ - Mailer now checks for mail.respond_to?(:deliver_later) rather than rails version, to decide deliver vs deliver_later.
68
+ - Removed unused user_id_parameter config method.
38
69
 
39
70
  [0.3.1]: https://github.com/tomichj/authenticate/compare/v0.3.0...v0.3.1
40
71
 
@@ -42,11 +73,12 @@ Removed unused user_id_parameter config method.
42
73
 
43
74
  ## [0.3.0] - February 24, 2016
44
75
 
45
- Moved normalize_email and find_normalized_email methods to base User module.
46
- Added full suite of controller and feature tests.
47
- Bug fixes:
48
- * failed login count fix was off by one.
49
- * password validation now done only in correct circumstances
76
+ - Moved normalize_email and find_normalized_email methods to base User module.
77
+ - Added full suite of controller and feature tests.
78
+
79
+ ### Fixes
80
+ - failed login count fix was off by one.
81
+ - password validation now done only in correct circumstances
50
82
 
51
83
  [0.3.0]: https://github.com/tomichj/authenticate/compare/v0.2.2...v0.3.0
52
84
 
@@ -54,8 +86,8 @@ Bug fixes:
54
86
 
55
87
  ## [0.2.3] - February 13, 2016
56
88
 
57
- Small bugfix for :username authentication.
58
- Improved documentation, started adding wiki pages.
89
+ - Small bugfix for :username authentication.
90
+ - Improved documentation, started adding wiki pages.
59
91
 
60
92
  [0.2.3]: https://github.com/tomichj/authenticate/compare/v0.2.2...v0.2.3
61
93
 
@@ -63,8 +95,8 @@ Improved documentation, started adding wiki pages.
63
95
 
64
96
  ## [0.2.2] - February 9, 2016
65
97
 
66
- Password length range requirements added, defaults to 8..128.
67
- Generators and app now respect model class more completely, including in routes.
98
+ - Password length range requirements added, defaults to 8..128.
99
+ - Generators and app now respect model class more completely, including in routes.
68
100
 
69
101
  [0.2.2]: https://github.com/tomichj/authenticate/compare/v0.2.1...v0.2.2
70
102
 
@@ -72,9 +104,9 @@ Generators and app now respect model class more completely, including in routes.
72
104
 
73
105
  ## [0.2.1] - February 9, 2016
74
106
 
75
- Fixed potential password_reset nil pointer.
76
- Continued adding I18n support.
77
- Minor documentation improvments.
107
+ - Fixed potential password_reset nil pointer.
108
+ - Continued adding I18n support.
109
+ - Minor documentation improvements.
78
110
 
79
111
  [0.2.1]: https://github.com/tomichj/authenticate/compare/v0.2.0...v0.2.1
80
112
 
@@ -82,7 +114,7 @@ Minor documentation improvments.
82
114
 
83
115
  ## [0.2.0] - February 2, 2016
84
116
 
85
- Added app/ including controllers, views, routes, mailers.
117
+ - Added app/ including controllers, views, routes, mailers.
86
118
 
87
119
  [0.2.0]: https://github.com/tomichj/authenticate/compare/v0.1.0...v0.2.0
88
120
 
@@ -90,5 +122,5 @@ Added app/ including controllers, views, routes, mailers.
90
122
 
91
123
  ## 0.1.0 - January 23, 2016
92
124
 
93
- Initial Release, barely functioning
125
+ - Initial Release, barely functioning
94
126
 
data/Rakefile CHANGED
@@ -1,4 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
1
3
  require 'bundler/gem_tasks'
4
+ require 'appraisal'
5
+
6
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
7
+ load 'rails/tasks/engine.rake'
2
8
  require 'rspec/core/rake_task'
9
+
10
+ namespace :dummy do
11
+ require_relative "spec/dummy/config/application"
12
+ Dummy::Application.load_tasks
13
+ end
14
+
3
15
  RSpec::Core::RakeTask.new(:spec)
16
+
17
+ desc 'Run all specs in spec directory (excluding plugin specs)'
4
18
  task default: :spec
@@ -23,10 +23,19 @@ class Authenticate::PasswordsController < Authenticate::AuthenticateController
23
23
 
24
24
  # Screen to enter your new password.
25
25
  #
26
- # GET /users/passwords/3/edit?token=abcdef
26
+ # A get with the token in the url is expected:
27
+ # GET /users/passwords/3/edit?token=abcdef
28
+ #
29
+ # This results in a redirect with the token removed from the url & copied to the session:
30
+ # GET /users/passwords/3/edit
31
+ #
27
32
  def edit
28
33
  @user = find_user_for_edit
29
- if !@user.reset_password_period_valid?
34
+
35
+ if params[:token]
36
+ session[:password_reset_token] = params[:token]
37
+ redirect_to edit_users_password_url(@user)
38
+ elsif !@user.reset_password_period_valid?
30
39
  redirect_to sign_in_path, notice: flash_failure_token_expired
31
40
  else
32
41
  render template: 'passwords/edit'
@@ -87,7 +96,9 @@ class Authenticate::PasswordsController < Authenticate::AuthenticateController
87
96
  end
88
97
 
89
98
  def find_user_by_id_and_password_reset_token
90
- Authenticate.configuration.user_model_class.where(id: params[:id], password_reset_token: params[:token].to_s).first
99
+ token = session[:password_reset_token] || params[:token]
100
+ # Authenticate.configuration.user_model_class.where(id: params[:id], password_reset_token: token).first
101
+ Authenticate.configuration.user_model_class.find_by_id_and_password_reset_token params[:id], token.to_s
91
102
  end
92
103
 
93
104
  def flash_create_description
data/authenticate.gemspec CHANGED
@@ -21,18 +21,20 @@ Gem::Specification.new do |s|
21
21
  s.extra_rdoc_files = %w(LICENSE README.md CHANGELOG.md)
22
22
  s.rdoc_options = ['--charset=UTF-8']
23
23
 
24
- s.add_dependency 'bcrypt', '~> 3.1'
24
+ s.add_dependency 'bcrypt'
25
25
  s.add_dependency 'email_validator', '~> 1.6'
26
26
  s.add_dependency 'rails', '>= 4.0', '< 5.2'
27
27
 
28
- s.add_development_dependency 'factory_girl', '~> 4.4'
29
- s.add_development_dependency 'rspec-rails', '~> 3.1'
28
+ s.add_development_dependency 'factory_girl', '~> 4.8'
29
+ s.add_development_dependency 'rspec-rails', '~> 3.6'
30
30
  s.add_development_dependency 'pry', '~> 0.10'
31
31
  s.add_development_dependency 'sqlite3', '~> 1.3'
32
32
  s.add_development_dependency 'shoulda-matchers', '~> 2.8'
33
- s.add_development_dependency 'capybara', '~> 2.6'
33
+ s.add_development_dependency 'capybara', '~> 2.14'
34
34
  s.add_development_dependency 'database_cleaner', '~> 1.5'
35
35
  s.add_development_dependency 'timecop', '~> 0.8'
36
+ s.add_development_dependency 'appraisal'
37
+ s.add_development_dependency 'rake'
36
38
 
37
39
  s.required_ruby_version = Gem::Requirement.new('>= 2.0')
38
40
  end
data/bin/setup ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+
3
+ set -e
4
+
5
+ # Install required gems, including Appraisal, which helps us test against
6
+ # multiple Rails versions
7
+ gem install bundler --conservative
8
+ bundle check || bundle install
9
+
10
+ if [ -z "$CI" ]; then
11
+ bundle exec appraisal install
12
+ fi
13
+
14
+ # Set up database for the application that Clearance tests against
15
+ RAILS_ENV=test bundle exec rake dummy:db:reset
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 4.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "~> 5.0.0"
6
+ gem "rails-controller-testing"
7
+
8
+ gemspec path: "../"
@@ -169,7 +169,10 @@ module Authenticate
169
169
  # config.authentication_strategy = :username
170
170
  # end
171
171
  #
172
- # Or, you can plug in your own authentication class, eg:
172
+ # Authenticate is designed to authenticate via :email. Some support for username is included.
173
+ # Username still requires an :email attribute on your User model.
174
+ #
175
+ # Alternatively, you can plug in your own authentication class:
173
176
  #
174
177
  # Configuration.configure do |config|
175
178
  # config.authentication_strategy = MyFunkyAuthClass
@@ -186,6 +189,13 @@ module Authenticate
186
189
  # @return [String]
187
190
  attr_accessor :redirect_url
188
191
 
192
+ # Rotate CSRF token on sign in if true.
193
+ #
194
+ # Defaults to false, but will default to true in 1.0.
195
+ #
196
+ # @return [Boolean]
197
+ attr_accessor :rotate_csrf_on_sign_in
198
+
189
199
  # Controls whether the "sign up" route, allowing creation of users, is enabled.
190
200
  #
191
201
  # Defaults to `true`.
@@ -239,6 +249,7 @@ module Authenticate
239
249
  @cookie_http_only = true
240
250
  @mailer_sender = 'reply@example.com'
241
251
  @redirect_url = '/'
252
+ @rotate_csrf_on_sign_in = false
242
253
  @allow_sign_up = true
243
254
  @routes = true
244
255
  @reset_password_within = 2.days
@@ -277,6 +288,10 @@ module Authenticate
277
288
  @routes
278
289
  end
279
290
 
291
+ def rotate_csrf_on_sign_in?
292
+ rotate_csrf_on_sign_in
293
+ end
294
+
280
295
  # List of symbols naming modules to load.
281
296
  def modules
282
297
  modules = @modules.dup # in case the user pushes any on
@@ -42,6 +42,11 @@ module Authenticate
42
42
  # Runs all valid callbacks and sends the user a session token.
43
43
  def login(user, &block)
44
44
  authenticate_session.login user, &block
45
+
46
+ if authenticated? && Authenticate.configuration.rotate_csrf_on_sign_in?
47
+ session.delete(:_csrf_token)
48
+ form_authenticity_token
49
+ end
45
50
  end
46
51
 
47
52
  # Log the user out. Typically used in session controller.
@@ -158,26 +163,19 @@ module Authenticate
158
163
 
159
164
  private
160
165
 
161
- # Write location to return to in a cookie. This is 12-factor compliant, cloud-safe.
166
+ # Write location to return to in user's session (normally a cookie).
162
167
  def store_location
163
168
  if request.get?
164
- value = {
165
- expires: nil,
166
- httponly: true,
167
- path: nil,
168
- secure: Authenticate.configuration.secure_cookie,
169
- value: request.original_fullpath
170
- }
171
- cookies[:authenticate_return_to] = value
169
+ session[:authenticate_return_to] = request.original_fullpath
172
170
  end
173
171
  end
174
172
 
175
173
  def stored_location
176
- cookies[:authenticate_return_to]
174
+ session[:authenticate_return_to]
177
175
  end
178
176
 
179
177
  def clear_stored_location
180
- cookies.delete :authenticate_return_to
178
+ session[:authenticate_return_to] = nil
181
179
  end
182
180
 
183
181
  def authenticate_session
@@ -1,3 +1,3 @@
1
1
  module Authenticate
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
@@ -1,19 +1,20 @@
1
1
  Authenticate.configure do |config|
2
- # config.user_model = 'User'
2
+ config.rotate_csrf_on_sign_in = true
3
3
 
4
+ # config.user_model = 'User'
4
5
  # config.cookie_name = 'authenticate_session_token'
5
6
  # config.cookie_expiration = { 1.month.from_now.utc }
6
7
  # config.cookie_domain = nil
7
8
  # config.cookie_path = '/'
8
9
  # config.secure_cookie = false # set to true in production https environments
9
10
  # config.cookie_http_only = false # set to true if you can
10
-
11
11
  # config.mailer_sender = 'reply@example.com'
12
12
  # config.crypto_provider = Authenticate::Model::BCrypt
13
13
  # config.timeout_in = 45.minutes
14
14
  # config.max_session_lifetime = 8.hours
15
15
  # config.max_consecutive_bad_logins_allowed = 4
16
16
  # config.bad_login_lockout_period = 10.minutes
17
+ # config.password_length = 8..128
17
18
  # config.authentication_strategy = :email
18
19
  # config.redirect_url = '/'
19
20
  # config.allow_sign_up = true