Give the changing browser a new session rather than keeping its own

Keeping the session the password was changed from also kept any copy of
its cookie working, and a copied cookie is one of the ways someone else
gets into an account. Every session ends now, and the profile page
signs the browser that changed the password back in with a new one.

From #371.

(cherry picked from commit b01bb7a0a7)
This commit is contained in:
Jeremy Daer committed 2026-10-19 10:46:24 -07:00
1 parent 2fb599e21c
commit b1122c7d6d
4 files changed
+23 -17

No files matched your search

@@ -8,6 +8,8 @@ class Users::ProfilesController < ApplicationController
def update
@user.update user_params
start_new_session_for @user if @user.saved_change_to_password_digest?
redirect_to user_profile_url, notice: update_notice
end
+5 -5
View File
@@ -20,7 +20,7 @@ class User < ApplicationRecord
has_secure_password validations: false
after_create_commit :grant_membership_to_open_rooms
after_update :sign_out_other_sessions, if: :saved_change_to_password_digest?
after_update :sign_out_all_sessions, if: :saved_change_to_password_digest?
after_update_commit :disconnect_signed_out_sessions, if: :saved_change_to_password_digest?
scope :ordered, -> { order("LOWER(name)") }
@@ -52,10 +52,10 @@ class User < ApplicationRecord
end
private
# A new password is how someone shuts out whoever else got into their account, so it ends the sessions opened
# with the old one. The session it was changed from, if any, stays.
def sign_out_other_sessions
sessions.excluding(Current.session).delete_all
# A new password is how someone shuts out whoever else got into their account, so it ends every session opened
# with the old one, copies of the changing browser's cookie included. The profile page signs that browser back in.
def sign_out_all_sessions
sessions.delete_all
end
# After commit, so a connection that drops can't come back on a session that's still there. The password is