Problem/Motivation
The existing code to detect a login error of either "invalid username or password" or "inactive or blocked account" is not working correctly. The code is looking for a string that does not match the strings currently provided by Drupal core for these errors.
Steps to reproduce
Configure the module to hide the core errors and then attempt to login with an invalid password, or attempt to login with a block account. The system error messages will be displayed.
Proposed resolution
Change the current search for strings to detection of the error codes.
| Comment | File | Size | Author |
|---|---|---|---|
| #29 | login_security-3292974-test.patch | 2.53 KB | mingsong |
| #28 | 21.patch | 8.76 KB | mingsong |
| #23 | login_security-3292974-21.patch | 5.9 KB | mingsong |
Issue fork login_security-3292974
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
jayelless commentedChange made and pushed.
Comment #5
anybodyMinor fix, please test review.
Comment #6
anybodyWe should have a test to check if this issue still exists and not re-appear in the future.
After that, we should fix this. The MR needs a reroll, but first let's check the current situation.
Generally the fix LGTM, but has to be tested manually and automatically.
Comment #8
grevil commentedDone, please review!
Comment #9
anybodySuper nice, thank you @Grevil and @jlscott! Merged! :)
Comment #10
anybodyComment #13
mingsongThe issue still exists with 2.0.1.
Core version: 9.4.11
Steps to reproduce:
1. Login a user with wrong password for more than 5 times( exceed the threshold).
2. Now the user is blocked. at this point the core error message is still prevented.
3. Login as an admin user to unblock that user.
4. At this stage, if login as that user with wrong password, the login failed message from core is back.
Error message:
Comment #14
anybodyThanks @Mingsong, so reopening this again. Could you find the mistake in the code already?
Comment #15
mingsongHi @Julian,
I debug further and here is what I found.
At the line 208 of login_security.module
https://git.drupalcode.org/project/login_security/-/blob/2.0.1/login_sec...
we check the error message of the user login form to figure out if there is a login failure.
The problem with it is that the Drupal user module (core module) won't give any error back to the user login form in that scenario mentioned in #13.
Instead, Drupal core will response as 403 without giving any error message back to the user login form.
See the following line in Drupal user module.
https://git.drupalcode.org/project/drupal/-/blob/9.4.11/core/modules/use...
Comment #18
anybodyThank you very much @Mingsong!
No idea yet, how we can solve that.
Comment #19
mingsongMeanwhile, I found another problem in which the Banned host or User message never show up.
That problem comes from line 213,
https://git.drupalcode.org/project/login_security/-/blob/2.0.1/login_sec...
Because the block message was cleared by that line.
Instead, there is no any message show up, which is different from previous attempts. That is not good for preventing username enumeration.
Comment #21
mingsongNew MR
The patch to test this MR.
https://git.drupalcode.org/issue/login_security-3292974/-/commit/d3a951b...
Comment #22
mingsongComment #23
mingsongUpload the patch from MR21 for testing convenience.
Comment #24
anybodyThank you @Mingsong, to be sure the issue happened before, but won't happen in the future, it would be best add a test, which implements the steps from #13 and #19 and fails. That should be run as test-only patch.
As part of the MR it should not fail. So we can be sure it works as expected now and in the future.
I understand, if you don't like writing tests, but without it, we can't be sure it works as expected and won't break again. That's worth it.
Comment #25
grevil commentedCan we create a follow-up issue for these problems? It's not recommended to reopen an issue where a fork already got merged. In this context it kinda makes sense, since the problem wasn't properly fixed, but it would still be great to create a second issue, so we can declutter the MRs.
Comment #26
anybodyThanks @Grevil, you're totally right for the future!
As we've already come far here, let's keep this one.
Comment #27
mingsongHi @Julian,
No problem. I will create a new test for it.
Comment #28
mingsongPatch with a new test for messages.
Comment #29
mingsongThe new test only patch.
Obvious, the test will fail as this a test only patch without having the fix providing by MR21.
Test failed:
Comment #31
mingsongComment #32
anybodySuuuper cool @Mingsong thank you for your effort on this!
@Grevil could you review and test this in the next days, please? If everything is fine, please create a MR to merge.
Comment #33
mingsongMR21 is still open.
https://git.drupalcode.org/project/login_security/-/merge_requests/21
Comment #34
grevil commentedI can confirm @Mingsong's problem while reconstructing the problem through #15. Setting this to major as this breaks the functionality of the module.
Comment #35
grevil commentedGreat work @Mingsong! Works as expected!
Not sure what the "not mergeable" notice is about, inside the test output (as it clearly is mergeable), but LGTM!
@Anybody could you check my comment made inside the MR, before we are merging this?
Comment #36
anybody@Grevil thanks! It's fine, I just left a comment :)
Any other points? Otherwise it it works, we can set this RTBC. I just retriggered the tests.
Comment #37
grevil commentedAlright, that's it then! Tests don't run, but let's see once they are merged! RTBC.
Comment #38
grevil commentedQueued a Drupal 9.5 test, to see if that works.
Comment #39
grevil commentedNope, no idea, tests looks fine to me, let's see once it is in dev.
Comment #41
grevil commentedProbably got something todo with having multiple issue forks inside one issue. Oh well.
Fixed! Thanks! :)