I had a user access rule set up such that usernames would be denied that contained the "@" symbol (because I didn't want people creating usernames that were email addresses). I also have LoginToboggan v1.3 installed. I recently upgraded to drupal v5.12. Now, any user who requests a new password by entering their email address into the "Username or e-mail address" field gets an error message stating: " is not allowed to request a new password". It appears that the user access rules are being run against this field. I am not sure if this is a drupal bug or a LoginToboggan bug. I removed the "@"-related user access rule and now people are able to request new passwords again.

Comments

hunmonk’s picture

Project: LoginToboggan » Drupal core
Version: 5.x-1.3 » 5.12
Component: Code » user system

logintoboggan has nothing to do with the request new password feature.

hajo’s picture

Confirmed. We have tight access rules on e-mail adresses on our site and when onetry ies to get a new password by entering the username this is refused because the username is checked against the e-mail rules.

This bug has been introduced in version 1.745.2.35 (tagged since DRUPAL-5-11) of /drupal/modules/user/user.module.
In user_pass_validate():

  // Blocked accounts cannot request a new password,
  // check provided username and email against access rules.
  if (drupal_is_denied('user', $name) || drupal_is_denied('mail', $name)) {
    form_set_error('name', t('%name is not allowed to request a new password.', array('%name' => $name)));
  }

There is a logical error in the if condition.

Please feel free to submit a patch. You can get the revision history of user.module at http://cvs.drupal.org/viewvc.py/drupal/drupal/modules/user/user.module?v...

Regards,
hajo

hajo’s picture

Status: Active » Needs review
StatusFileSize
new1.24 KB

New code is

  $is_denied = FALSE;

  if ($account = user_load(array('mail' => $name, 'status' => 1))) {
    if (drupal_is_denied('mail', $name)) {
      $is_denied = TRUE;
    }
  }
  elseif ($account = user_load(array('name' => $name, 'status' => 1))) {
    if (drupal_is_denied('user', $name)) {
      $is_denied = TRUE;
    }
  }

  if ($is_denied) {
  	form_set_error('name', t('%name is not allowed to request a new password.', array('%name' => $name)));
  }

This way drupal_is_denied is only called with parameters matching the way the account was loaded.

hajo’s picture

Version: 5.12 » 6.x-dev

The bug is present in Drupal 5 and 6 in the latest version. In Drupal 5 it is in file user.module, in Drupal 6 it is in user.pages.inc. The bug is not present in Drupal 7.

damien tournoud’s picture

Version: 6.x-dev » 7.x-dev
Status: Needs review » Needs work

D7 is still missing parts of SA-2008-060. Bumping to 7 so that we can fix that too.

The correct logic should be:

  // Try to load by email.
  $account = user_load(array('mail' => $name, 'status' => 1));
  if (!$account) {
    // No success, try to load by name.
    $account = user_load(array('name' => $name, 'status' => 1));
  }
  if ($account) {
    // Blocked accounts cannot request a new password,
    // check provided username and email against access rules.
    if (drupal_is_denied('user', $account->name) || drupal_is_denied('mail', $account->mail)) {
      form_set_error('name', t('%name is not allowed to request a new password.', array('%name' => $name)));
    }
  }
  if (isset($account->uid)) {
    form_set_value(array('#parents' => array('account')), $account, $form_state);
  }
  else {
    form_set_error('name', t('Sorry, %name is not recognized as a user name or an e-mail address.', array('%name' => $name)));
  }
vesapalmu’s picture

We have a problem with this in few different live 6.x sites. IF SA-2008-060 is not an issue in 6.x any longer is there any chance this patch would get included in 6.12?

gpk’s picture

Priority: Normal » Critical

If D7 is still missing parts of SA-2008-060 then this is critical for 7.x...

sun.core’s picture

Any updates?

alberto56’s picture

Where can one define access rules in D7? (admin/user/rules/list doesn't work for me)

catch’s picture

It doesn't exist in D7. This probably needs to move to the not-yet-functioning-needs-another-co-maintainer replacement http://drupal.org/project/user_restrictions

hajo’s picture

StatusFileSize
new1.2 KB

Because the access rules functionality was taken out of D7, I submit a patch against D6, namely version 1.11.2.2 of modules/user/user.pages.inc.
Wrong file: Please see file from comment #12.

hajo’s picture

Version: 7.x-dev » 6.x-dev
Priority: Critical » Normal
Status: Needs work » Needs review
StatusFileSize
new1.22 KB

Wrong patch-file in comment #11

seanburlington’s picture

Title: User access rules are run against new password requests » Username is validated against email access rules (and vice versa) for new password requests
Status: Needs review » Reviewed & tested by the community

The patch in #12 is a good minimal patch to fix the bug

It just moves the test to after the account user_load is performed and then ensures that the username is validated against the username rules and the email is validated against the email rules

I've tested the patch and it works for me.

thanks hajo

gpk’s picture

Status: Reviewed & tested by the community » Needs work

Patch at #11 is basically the same as at duplicate issue #386138-6: Can't request new password using email address.

However the one at #11 is not in the correct format - diff needs to be run from the Drupal root, not the user module's folder. Also one of the blank lines next to the removed block of code should also be removed.

seanburlington’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new1.37 KB

patch from drupal root attached

chawl’s picture

This should be committed to next release, very annoying indeed.

Patch works flawlessly on 6.16 BTW. Tx.

frankcarey’s picture

worked well, code seems logical

jaydubb181’s picture

This patch fixed this issue on my site as well. Thank you seanburlington.

seanburlington’s picture

credit where it's due - the patch belongs to hajo - I just reviewed it and tweaked the format

It'd be good to get it into the next release :-)

hajo’s picture

Actually, the code is written by Damien Tournoud since my first proposal wasn't correct. As you wrote: credit where it's due ;-)

jaydubb181’s picture

Thank you Damien!

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Great, committed, thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

adrianpintilie’s picture

Status: Closed (fixed) » Active

the patch is not correct.

users who are BLOCKED are excluded from the search due to restriction in the rule:
$account = user_load(array('name' => $name, 'status' => 1));

status-> 1

the correct search should be:
$account = user_load(array('name' => $name));

hajo’s picture

That's the way it is meant to be, isn't it? See the comment "// Blocked accounts cannot request a new password" in Damiens code (Comment No. 5).

hajo’s picture

Status: Active » Closed (fixed)
joseph.chambers’s picture

Post 5 solved the issue for me and seems to be secure. Will this be put into the source for version 6?

hajo’s picture

It is, at least in version 6.20.