-
Notifications
You must be signed in to change notification settings - Fork 166
Do not 500 when resetting password for account with an unconfirmed email address that has since been confirmed by another account #6042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ def valid_token | |
| # If the user is not saved in the database, that means looking them up by | ||
| # their token failed | ||
| errors.add(:reset_password_token, 'invalid_token', type: :invalid_token) | ||
| elsif !user.reset_password_period_valid? | ||
| elsif !user.reset_password_period_valid? || invalid_account? | ||
| errors.add(:reset_password_token, 'token_expired', type: :token_expired) | ||
| end | ||
| end | ||
|
|
@@ -56,6 +56,21 @@ def mark_profile_inactive | |
| user.proofing_component&.destroy | ||
| end | ||
|
|
||
| # It is possible for an account that is resetting their password to be "invalid". | ||
| # If an unconfirmed account (which must have one unconfirmed email address) resets their | ||
| # password and a different account then adds and confirms that same email address, | ||
| # the initial account is no longer able to confirm their email address and is effectively invalid. | ||
| # | ||
| # They may still have a valid forgot password link for the initial account, which would normally | ||
| # mark their email as confirmed when they set a new password, but we do not want to allow it | ||
| # because we only allow an email address to be confirmed on one account. | ||
mitchellhenke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def invalid_account? | ||
| !user.confirmed? && | ||
| EmailAddress.confirmed.exists?( | ||
| email_fingerprint: user.email_addresses.map(&:email_fingerprint), | ||
| ) | ||
| end | ||
|
||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| user_id: user.uuid, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also worth noting that this should resolve the vast vast majority of cases, but the chance still exists that the two accounts could end up in a race condition where they both try to confirm the email address at the same time in the window of time between the
SELECThere and theUPDATEthat follows.