Skip to content

Commit 6b3b0c5

Browse files
author
José Valim
committed
Remove deprecated token lookups
1 parent dff7891 commit 6b3b0c5

File tree

11 files changed

+21
-85
lines changed

11 files changed

+21
-85
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
== 3.2.0-dev
2+
3+
* enchancements
4+
* Previously deprecated token authenticatable and insecure lookups have been removed
5+
16
== 3.1.0
27

38
Security announcement: http://blog.plataformatec.com.br/2013/08/devise-3-1-now-with-more-secure-defaults/

app/controllers/devise/confirmations_controller.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ def show
2020
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
2121

2222
if resource.errors.empty?
23-
if Devise.allow_insecure_sign_in_after_confirmation
24-
set_flash_message(:notice, :confirmed_and_signed_in) if is_navigational_format?
25-
sign_in(resource_name, resource)
26-
else
27-
set_flash_message(:notice, :confirmed) if is_navigational_format?
28-
end
23+
set_flash_message(:notice, :confirmed) if is_navigational_format?
2924
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
3025
else
3126
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }
@@ -41,10 +36,6 @@ def after_resending_confirmation_instructions_path_for(resource_name)
4136

4237
# The path used after confirmation.
4338
def after_confirmation_path_for(resource_name, resource)
44-
if Devise.allow_insecure_sign_in_after_confirmation
45-
after_sign_in_path_for(resource)
46-
else
47-
new_session_path(resource_name)
48-
end
39+
new_session_path(resource_name)
4940
end
5041
end

config/locales/en.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ en:
44
devise:
55
confirmations:
66
confirmed: "Your account was successfully confirmed. Please sign in."
7-
confirmed_and_signed_in: "Your account was successfully confirmed. You are now signed in."
87
send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
98
send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
109
failure:

lib/devise.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ module Strategies
5050
mattr_accessor :secret_key
5151
@@secret_key = nil
5252

53-
# Allow insecure token lookup. Must be used
54-
# temporarily just for migration.
55-
mattr_accessor :allow_insecure_token_lookup
56-
@@allow_insecure_tokens_lookup = false
53+
[ :allow_insecure_token_lookup,
54+
:allow_insecure_sign_in_after_confirmation,
55+
:token_authentication_key ].each do |method|
56+
class_eval <<-RUBY
57+
def self.#{method}
58+
ActiveSupport::Deprecation.warn "Devise.#{method} is deprecated " \
59+
"and has no effect"
60+
end
5761
58-
# Allow insecure sign in after confirmation. Must be used
59-
# temporarily just for migration.
60-
mattr_accessor :allow_insecure_sign_in_after_confirmation
61-
@@allow_insecure_sign_in_after_confirmation = false
62+
def self.#{method}=(val)
63+
ActiveSupport::Deprecation.warn "Devise.#{method}= is deprecated " \
64+
"and has no effect"
65+
end
66+
RUBY
67+
end
6268

6369
# Custom domain or key for cookies. Not set by default
6470
mattr_accessor :rememberable_options
@@ -195,10 +201,6 @@ module Strategies
195201
mattr_accessor :mailer_sender
196202
@@mailer_sender = nil
197203

198-
# Authentication token params key name of choice. E.g. /users/sign_in?some_key=...
199-
mattr_accessor :token_authentication_key
200-
@@token_authentication_key = :auth_token
201-
202204
# Skip session storage for the following strategies
203205
mattr_accessor :skip_session_storage
204206
@@skip_session_storage = []

lib/devise/models/confirmable.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ def confirm_by_token(confirmation_token)
275275
confirmation_token = Devise.token_generator.digest(self, :confirmation_token, confirmation_token)
276276

277277
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
278-
if !confirmable.persisted? && Devise.allow_insecure_token_lookup
279-
confirmable = find_or_initialize_with_error_by(:confirmation_token, original_token)
280-
end
281-
282278
confirmable.confirm! if confirmable.persisted?
283279
confirmable.confirmation_token = original_token
284280
confirmable

lib/devise/models/lockable.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ def unlock_access_by_token(unlock_token)
165165
unlock_token = Devise.token_generator.digest(self, :unlock_token, unlock_token)
166166

167167
lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)
168-
if !lockable.persisted? && Devise.allow_insecure_token_lookup
169-
lockable = find_or_initialize_with_error_by(:unlock_token, original_token)
170-
end
171-
172168
lockable.unlock_access! if lockable.persisted?
173169
lockable.unlock_token = original_token
174170
lockable

lib/devise/models/recoverable.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ def reset_password_by_token(attributes={})
116116
reset_password_token = Devise.token_generator.digest(self, :reset_password_token, original_token)
117117

118118
recoverable = find_or_initialize_with_error_by(:reset_password_token, reset_password_token)
119-
if !recoverable.persisted? && Devise.allow_insecure_token_lookup
120-
recoverable = find_or_initialize_with_error_by(:reset_password_token, original_token)
121-
end
122119

123120
if recoverable.persisted?
124121
if recoverable.reset_password_period_valid?

test/integration/confirmable_test.rb

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,6 @@ def resend_confirmation
6262
end
6363
end
6464

65-
test 'user should be signed in after confirmation if allow_insecure_sign_in_after_confirmation is enabled' do
66-
swap Devise, :confirm_within => 3.days, :allow_insecure_sign_in_after_confirmation => true do
67-
user = create_user(:confirm => false, :confirmation_sent_at => 2.days.ago)
68-
assert_not user.confirmed?
69-
visit_user_confirmation_with_token(user.raw_confirmation_token)
70-
71-
assert_contain 'Your account was successfully confirmed. You are now signed in.'
72-
assert_current_url root_url
73-
assert user.reload.confirmed?
74-
end
75-
end
76-
77-
test 'user should be redirected to a custom path after confirmation' do
78-
Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns("/?custom=1")
79-
80-
user = create_user(:confirm => false)
81-
visit_user_confirmation_with_token(user.raw_confirmation_token)
82-
83-
assert_current_url "/?custom=1"
84-
end
85-
8665
test 'already confirmed user should not be able to confirm the account again' do
8766
user = create_user(:confirm => false)
8867
user.confirmed_at = Time.now

test/models/confirmable_test.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ def setup
5151
assert_equal "was already confirmed, please try signing in", user.errors[:email].join
5252
end
5353

54-
test 'DEPRECATED: should find and confirm a user automatically' do
55-
swap Devise, allow_insecure_token_lookup: true do
56-
user = create_user
57-
confirmed_user = User.confirm_by_token(user.confirmation_token)
58-
assert_equal confirmed_user, user
59-
assert user.reload.confirmed?
60-
end
61-
end
62-
6354
test 'should find and confirm a user automatically based on the raw token' do
6455
user = create_user
6556
raw = user.raw_confirmation_token

test/models/lockable_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,6 @@ def setup
139139
end
140140
end
141141

142-
test 'DEPRECATED: should find and unlock a user automatically' do
143-
swap Devise, allow_insecure_token_lookup: true do
144-
user = create_user
145-
user.lock_access!
146-
locked_user = User.unlock_access_by_token(user.unlock_token)
147-
assert_equal locked_user, user
148-
assert_not user.reload.access_locked?
149-
end
150-
end
151-
152142
test 'should find and unlock a user automatically based on raw token' do
153143
user = create_user
154144
raw = user.send_unlock_instructions

0 commit comments

Comments
 (0)