Created
March 7, 2016 04:33
-
-
Save iconnor/793f2991fe420f23e412 to your computer and use it in GitHub Desktop.
Stop password reset tokens being used more than once (so to with any domain referrer leakage)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# new file app/controllers/users/passwords_controller.rb | |
class Users::PasswordsController < Devise::PasswordsController | |
def edit | |
super | |
raw, enc = Devise.token_generator.generate(User, :reset_password_token) | |
original_enc = Devise.token_generator.digest(User, :reset_password_token, params[:reset_password_token]) | |
EncoreBackend::User.where(reset_password_token: original_enc).update_all(reset_password_token: enc) | |
@user.reset_password_token = raw | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# changes to config/routes.rb | |
devise_for :users, class_name: 'User', controllers: { passwords: 'users/passwords' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment