Skip to content

Commit daf7157

Browse files
authored
Fix password change/reset not immediately invalidating other sessions (#12928)
While making browser requests in the other sessions after a password change or reset does not allow you to be logged in and correctly invalidates the session making the request, sessions have API tokens associated with them, which can still be used until that session is invalidated. This is a security issue for accounts that were already compromised some other way because it makes it harder to throw out the hijacker.
1 parent ce1dee8 commit daf7157

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

app/controllers/auth/passwords_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ class Auth::PasswordsController < Devise::PasswordsController
66

77
layout 'auth'
88

9+
def update
10+
super do |resource|
11+
resource.session_activations.destroy_all if resource.errors.empty?
12+
end
13+
end
14+
915
private
1016

1117
def check_validity_of_reset_password_token

app/controllers/auth/registrations_controller.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,17 @@ def destroy
2222
not_found
2323
end
2424

25+
def update
26+
super do |resource|
27+
resource.clear_other_sessions(current_session.session_id) if resource.saved_change_to_encrypted_password?
28+
end
29+
end
30+
2531
protected
2632

2733
def update_resource(resource, params)
2834
params[:password] = nil if Devise.pam_authentication && resource.encrypted_password.blank?
35+
2936
super
3037
end
3138

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def activate_session(request)
247247
ip: request.remote_ip).session_id
248248
end
249249

250-
def exclusive_session(id)
250+
def clear_other_sessions(id)
251251
session_activations.exclusive(id)
252252
end
253253

0 commit comments

Comments
 (0)