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
Comment #1
dstolComment #3
dstolComment #5
dstolComment #6
balsamaConfirmed 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.
Cases where a valid username and incorrect password are entered remain unchanged (watchdog message = "Login attempt failed for [username]") as do successful logins.
Comment #7
catchLooks good to me. Committed/pushed to 8.x. Moving back to 7.x for backport.
Comment #8
berdirHm, wondering if this should have a test?
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 ;)
Comment #9
tstoecklerI 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.
Comment #9.0
tstoecklerUpdated issue summary.
Comment #10
berdirPoor forgotten issue is sad.
Comment #11
neclimdulI 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.
Comment #12
balsamaThanks for the tests Berdir - and I like the new comment. Much better explanation of why.
@neclimdul:
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.
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.)
Comment #13
alansaviolobo commentedreroll
Comment #15
alansaviolobo commentedended up exporting a reversed patch.
Comment #22
Patricia Silva commentedShould this issue still be "needs review" , since the patch was already committed?
Comment #23
Patricia Silva commentedThis 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.
Comment #27
Patricia Silva commentedThe patch in #23 no longer applies. I rerolled it.
Comment #29
neclimdulLooks like this part of the test isn't working. Looks like that was also the case in the previous version of the patch though.
Comment #37
quietone commentedThis 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.