Making public from issue reported on s.d.o against 7.x

"Drupal logs unsuccessful login attempts via watchdog in to following format:
Login attempt failed for [contents of username field]

Anecdotal evidence shows that a users commonly make the mistake of entering both their usernames and passwords in the username field. For example, this is common among keyboard navigators who focus first on the username field and then (unsuccessfully) tab to the password field, enter their password and press enter.

The result is Drupal storing the user's password in plaintext. If the database is compromised, it would be easy for an attacker to determine passwords.

I suggest adding a check to user_login_final_validate() that ensures what has been entered in the username field is indeed a valid user before logging it to watchdog. If it is not a valid user, log it IP address instead."

Comments

dstol’s picture

Status: Active » Needs review
StatusFileSize
new1018 bytes

Status: Needs review » Needs work

The last submitted patch, user_pass_db.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review
StatusFileSize
new1.45 KB

Status: Needs review » Needs work

The last submitted patch, 1982606-3-user-watchdog.patch, failed testing.

dstol’s picture

Status: Needs work » Needs review
StatusFileSize
new1.47 KB
balsama’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new18.92 KB

Confirmed that the patch in #5 applies cleanly and prevents user passwords from being stored in the watchdog table if a user accidentally enters their username in the password field.

Case:
User accidentally enters password in User Login form username field.

Result before patch:
Users with "access site reports" permission are able to see password on Recent log messages page.

Result after patch:
IP address from which failed login attempt was made is displayed on Recent log messages page.

screenshot-patch-1982606-5

Cases where a valid username and incorrect password are entered remain unchanged (watchdog message = "Login attempt failed for [username]") as do successful logins.

catch’s picture

Version: 8.x-dev » 7.x-dev
Category: feature » task
Status: Reviewed & tested by the community » Patch (to be ported)

Looks good to me. Committed/pushed to 8.x. Moving back to 7.x for backport.

berdir’s picture

Hm, wondering if this should have a test?

+++ b/core/modules/user/user.moduleundefined
@@ -1373,7 +1373,14 @@ function user_login_final_validate($form, &$form_state) {
+        // If the username entered is not a valid user,
+        // only store the IP address.

The comment should be formatted to use as much of 80 characters as possible.

Also, I can see that the code is doing that, would be more useful to comment why. Because someone might consider to remove this again if not seeing the reason. Especially without having tests for it ;)

tstoeckler’s picture

Title: Routine user error can lead to plaintext passwords in the database » [follow-up: comment + tests] Routine user error can lead to plaintext passwords in the database
Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Needs work

I agree with #8. I only saw this in the commit log and tried very hard to see how a password would end up in the DB with the previous code.
A comment would be great. Tests, as well. Re-titling for that.

tstoeckler’s picture

Issue summary: View changes

Updated issue summary.

berdir’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3.57 KB

Poor forgotten issue is sad.

neclimdul’s picture

I hate to point this out so long after being committed but IP address is already stored on the watchdog. Also, as a site administrator, username was helpful in helping people trouble shoot logging in. But between tech savviness and proxies, IP addresses are pretty worthless for this message.

balsama’s picture

Thanks for the tests Berdir - and I like the new comment. Much better explanation of why.

@neclimdul:

IP address is already stored on the watchdog

Where else is the IP address written to watchdog for failed logins? I can confirm that it is only written once and that it comes from the original patch in this issue.

username was helpful in helping people trouble shoot logging in

I can see where this might be useful, but if a user is entering a valid username, it will still appear in watchdog. If you see that their IP is being stored instead, you know that they're entering an invalid user name, so that's a great place to start troubleshooting.

One other thing that was discussed when I first reported this to the security team, but that hasn't been brought up yet in this thread is that Viewing the database logs only requires "access site reports" permission, which is a low-level administrative permission; that is, not one of the ones listed at http://drupal.org/security-advisory-policy. (Just one more reason to keep this is - along with Berdir's improvements.)

alansaviolobo’s picture

StatusFileSize
new3.4 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 13: follow_up_comment_-1982606-13.patch, failed testing.

alansaviolobo’s picture

Status: Needs work » Needs review
StatusFileSize
new3.4 KB

ended up exporting a reversed patch.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • catch committed 3d1da5a on 8.3.x
    Issue #1982606 by dstol: Added Routine user error can lead to plaintext...

  • catch committed 3d1da5a on 8.3.x
    Issue #1982606 by dstol: Added Routine user error can lead to plaintext...

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • catch committed 3d1da5a on 8.4.x
    Issue #1982606 by dstol: Added Routine user error can lead to plaintext...

  • catch committed 3d1da5a on 8.4.x
    Issue #1982606 by dstol: Added Routine user error can lead to plaintext...
Patricia Silva’s picture

Should this issue still be "needs review" , since the patch was already committed?

Patricia Silva’s picture

Version: 8.2.x-dev » 8.4.x-dev
StatusFileSize
new3.4 KB

This issue is still needs review because there have been follow up issues reported since the last commit. The follow up issues were: 1) needs a test and 2) a more descriptive comment. These things were done in #15 but that patch no longer applies. I updated the comment to be clearer and rerolled the patch.

Status: Needs review » Needs work

The last submitted patch, 23: follow_up_comment_-1982606-23.patch, failed testing.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Patricia Silva’s picture

Status: Needs work » Needs review
StatusFileSize
new3.47 KB

The patch in #23 no longer applies. I rerolled it.

Status: Needs review » Needs work

The last submitted patch, 27: follow_up_comment_1982606-27.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

neclimdul’s picture

Issue tags: +hardening
+++ b/core/modules/user/tests/src/Functional/UserLoginTest.php
@@ -29,6 +35,44 @@ public function testLoginCacheTagsAndDestination() {
+    \Drupal::config('user.flood')
+      ->set('ip_limit', 10)
+      // Set a high per-user limit out so that it is not relevant in the test.
+      ->set('user_limit', 4000)
+      ->save();

Looks like this part of the test isn't working. Looks like that was also the case in the previous version of the patch though.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Title: [follow-up: comment + tests] Routine user error can lead to plaintext passwords in the database » Routine user error can lead to plaintext passwords in the database
Version: 9.4.x-dev » 9.1.x-dev
Status: Needs work » Fixed
Related issues: +#2983395: user module's flood controls should do better logging

This issue was committed to Drupal 8.x and re-opened to add tests. Between then and now that work was done in #2983395: user module's flood controls should do better logging. If further work is needed regarding the UserLogin form it would be best to create a new issue.

Closing this as fixed and changing the version to when the other issue was fixed.

Status: Fixed » Closed (fixed)

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