Skip to content
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

[Security] Fixed: Strengthen one-time login links. #6420

Closed
herbdool opened this issue Mar 10, 2024 · 11 comments · Fixed by backdrop/backdrop#4673
Closed

[Security] Fixed: Strengthen one-time login links. #6420

herbdool opened this issue Mar 10, 2024 · 11 comments · Fixed by backdrop/backdrop#4673

Comments

@herbdool
Copy link

herbdool commented Mar 10, 2024

This will address two Drupal 7 improvements:

  • Changing email address should invalidate one-time login links
  • Increase entropy in the one-time login links (especially in the cases where there's an empty password in the database, if a site uses SSO).

In https://www.drupal.org/project/drupal/issues/3306390:

Problem/Motivation
Assume I change email provider or leave a job. I or an attacker requests a password reset link.

I now change the email address on my drupal account, which I've been logged into on my home computer

My former employer or someone with access to my old email account can use the pre-existing one-time login link to gain access to my account (or the whole site if I'm an admin).

Proposed resolution
Invalidate one-time login links if the email address is changed. The easiest fix is to include the current email address as part of the data in user_pass_rehash

From Drupal 7.100: https://www.drupal.org/node/3409960, https://www.drupal.org/node/3409043 (backport from Drupal 10):

The problem is that there is significantly less entropy in the inputs to user_pass_rehash() if the user has an empty password field in the database.

Users may have empty passwords if - for example - a site uses a Single Sign On integration to offload authentication.

Improvements could be made to the implementation to reduce the likelihood that an attacker could brute force e.g. a password reset URL if the user has no password stored in Drupal.

It may also be advisable for sites / projects that do not use Drupal's passwords for authentication to avoid leaving the password field empty in the database, but that can be looked at in a (public) follow-up. It wouldn't help much to set the password field to the same value for all users.

@herbdool herbdool changed the title Hardening of user_pass_rehash Hardening of user_pass_rehash (d.o 3409043) Mar 14, 2024
@herbdool
Copy link
Author

herbdool commented Mar 14, 2024

Related commits (will see if these are necessary):

There were some big changes in this PR which mean the D7 tests need to adapt to different behaviour https://github.com/backdrop/backdrop/pull/122/files

@herbdool herbdool changed the title Hardening of user_pass_rehash (d.o 3409043) Strengthen user_pass_rehash (d.o 3409043 and 3306390) Mar 15, 2024
@herbdool herbdool changed the title Strengthen user_pass_rehash (d.o 3409043 and 3306390) [D7] Strengthen user_pass_rehash (d.o 3409043 and 3306390) Mar 17, 2024
@herbdool herbdool changed the title [D7] Strengthen user_pass_rehash (d.o 3409043 and 3306390) [D7] Strengthen one-time login links (d.o 3409043 and 3306390) Mar 18, 2024
@quicksketch
Copy link
Member

This looks great @herbdool!

@stpaultim
Copy link
Member

Any clear guidance on testing this issue?

Does this make UI changes or is a background thing?

@klonos
Copy link
Member

klonos commented Apr 25, 2024

The respective Drupal issues are either bugs or tasks, so not sure that this is a new feature request. It does need a change record though (same as the one released for D7.100: https://www.drupal.org/node/3409960), so OK if only targeted for 1.28.0 I guess.

@herbdool
Copy link
Author

herbdool commented Apr 25, 2024

@stpaultim you can test it by seeing if changing an email address will expire a one time login for that user.

Let me expand. First create a one time login link for a user. Then in a private window use that URL. The user should be logged in. Log out.

Then create a second one time login link for that user. But before using the URL, change the email address for that user. Then go to the URL in a private window. This time the URL should not work; it should be expired.

@quicksketch
Copy link
Member

I don't see a good reason why this would need to be in a minor release. As a security-hardening, I think this should be allowed in any bug-fix release as well.

@jenlampton
Copy link
Member

Code looks good to me, still needs manual testing. (Failed to test on the sandbox since it won't sent pw reset emails --- needs local testing)

@quicksketch
Copy link
Member

I verified this does not affect existing password-reset tokens or bee uli, both of which call user_pass_reset_url() (which then in turn calls user_pass_rehash(), the changed function). And this PR includes a safety fallback even if $user_mail is not provided, it automatically loads it based on the user name.

This all looks good to me!

backdrop-ci referenced this issue in backdrop/backdrop Apr 27, 2024
By @herbdool, @quicksketch, @stpaultim, @jenlampton, and @klonos.

Port of Drupal issue #3409043 by poker10, catch, Fabianx, pwolanin, rvtraveller.
backdrop-ci referenced this issue in backdrop/backdrop Apr 27, 2024
By @herbdool, @quicksketch, @stpaultim, @jenlampton, and @klonos.

Port of Drupal issue #3409043 by poker10, catch, Fabianx, pwolanin, rvtraveller.
@quicksketch
Copy link
Member

Merged backdrop/backdrop#4673 into 1.x and 1.27.x. Thanks @herbdool, @stpaultim, and @jenlampton!

@klonos
Copy link
Member

klonos commented Apr 27, 2024

Reopening this in order to create a change record. Assigning it to me as well. I'll prepare a draft soon as I get a chance.

@klonos klonos reopened this Apr 27, 2024
@quicksketch
Copy link
Member

@jenlampton jenlampton changed the title [D7] Strengthen one-time login links (d.o 3409043 and 3306390) Fixed: Strengthen one-time login links. May 16, 2024
@jenlampton jenlampton changed the title Fixed: Strengthen one-time login links. [Security] Fixed: Strengthen one-time login links. May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants