Repository navigation
fix(email): save the recovery password only after the mail is sent - #3185
Open
rishabhvenu wants to merge 1 commit into
Open
rishabhvenu wants to merge 1 commit into
rishabhvenu wants to merge 1 commit into
Conversation
With recovery codes disabled, /email recover wrote the new password to the database before sending it. When the mail could not be sent the player got "The email could not be sent", but the old password had already been replaced by one they never received, so they could no longer log in. Send the mail first and only save the new password once it went out. If saving fails after the mail was sent, report an error instead of the success message, since the mailed password would not work. Fixes AuthMe#3153
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With recovery codes disabled (
Security.recoveryCode.length: 0),PasswordRecoveryService.generateAndSendNewPasswordsaves the new password withdataSource.updatePasswordand only then sends the mail. If sending fails, the player gets "The email could not be sent. Please contact an administrator.", but the old password has already been replaced by one they never received, so they cannot log in any more (#3153).The mail is now sent first, and the new hash is only saved once
sendPasswordMailreturns true. On a send failure nothing is written and the player gets the sameemail.send_failuremessage as before. The return value ofupdatePasswordwas ignored until now; if saving fails after the mail went out, the mailed password would not work, so the player getserror.unexpected_errorinstead of the success message, a warning is logged, and the cooldown is not started. The mailed password becomes valid one database write after the SMTP server accepts the mail, which is far shorter than the time it takes the player to read it.Testing:
PasswordRecoveryServiceTest: on success the mail is sent before the password is saved, and with the password from the mail; on a send failureupdatePasswordis never called; when saving fails the player gets the error message. All three fail on master and pass with the change.mvn -V -B clean packageon JDK 21: build passes, 1507 tests in authme-core.PurgeServiceTest.shouldRunAutoPurgefailed in two earlier runs on a loaded machine (601 ms and 107 ms against its 100 ms tolerance) and passed alone and in the third full run; it is unrelated.127.0.0.1:25without TLS. An offline-mode bot registers, gets an email set with/authme setemail, rejoins, runs/email recover <email>, then rejoins and logs in:/login <old password>is kicked with "Wrong password!". With the change, on both: same message, and/login <old password>succeeds.Not tested: a failing database write after a successful send (only covered by the unit test), MySQL and PostgreSQL, and the pre-join dialog recovery path in
AsynchronousJoin, which calls the same method.Fixes #3153