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

Fix logging of failed logins & unknown users #62

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

axllent
Copy link
Contributor

@axllent axllent commented Dec 19, 2023

Fixes the authenticationFailed() method to correctly return the login email, and adds authenticationFailedUnknownUser() method to log unknown user login attempts.

Issue

@GuySartorelli
Copy link
Member

GuySartorelli commented Dec 19, 2023

Thank you for submitting this fix.
Can you please add a unit test for this?
Please also create or link to an associated issue as per the contribution guide.

@axllent
Copy link
Contributor Author

axllent commented Dec 20, 2023

@GuySartorelli - My apologies, I have created #63 to explain the issue in greater detail referencing this PR.

As for the unit tests however, I haven't a clue where to begin as both of these presumably require an actual failed login attempt via the form, unlike all the other unit tests which assume an identity using $this->logInWithPermission() (which may be why there were never any unit tests for these to start with).

@GuySartorelli GuySartorelli changed the base branch from 3 to 2.6 December 20, 2023 03:22
@GuySartorelli
Copy link
Member

GuySartorelli commented Dec 20, 2023

No worries.

I've added a test. I also noticed that this affects the 2.x line, so I've retargetted this PR to the current patch release branch for that release line.

@GuySartorelli
Copy link
Member

GuySartorelli commented Dec 20, 2023

I also took the liberty to remove the authenticationFailedUnknownUser() method you were adding - it doesn't seem related to fixing the actual bug, so if you want to introduce that new API please raise a new PR for it, and make a good case for it being needed. It doesn't seem needed to me though.

@GuySartorelli GuySartorelli force-pushed the failed-logins branch 2 times, most recently from 164f93f to 6cc27ef Compare December 20, 2023 03:28
@axllent
Copy link
Contributor Author

axllent commented Dec 20, 2023

Thanks @GuySartorelli, you're a star. If the auditor module is supposed to include "Login attempts (failed and successful)", then surely that also includes failed logins when no matching Email is found (ie: authenticationFailedUnknownUser())?

@GuySartorelli
Copy link
Member

. If the auditor module is supposed to include "Login attempts (failed and successful)", then surely that also includes failed logins when no matching Email is found (ie: authenticationFailedUnknownUser())?

That scenario covered with the logged warning when no email is present. I couldn't find an easy way to test the warning is logged but the functionality is there.

@axllent
Copy link
Contributor Author

axllent commented Dec 20, 2023

That scenario covered with the logged warning when no email is present. I couldn't find an easy way to test the warning is logged but the functionality is there.

No it's not actually - that is my point. Unless both my understanding and testing is incorrect, according to the logic here, if a member exists with the email (incorrect password though) then authenticationFailed() is called, however if no member with the email exists, then authenticationFailedUnknownUser() is called. This means that currently the only failed logins that are tracked in the audit are those attempts where a member with the email exists, however login attempts using invalid emails (ie: no matching member) are not.

The warning you are referring to in authenticationFailed() is when neither $data['Login'] nor (once patched) $data['Email'] exist - although I don't think that's possible - at least not when called via MemberAuthenticator::class as it requires $data['Email'] (else a InvalidArgumentException is returned before the audit logs ~ potentially redundant logic).

axllent and others added 2 commits December 21, 2023 11:38
Fixes the `authenticationFailed()` method to correctly return the login email
@GuySartorelli
Copy link
Member

Ahhh, I see. I misunderstood what you meant and there was no context until now about what that new method does. Thank you for providing that extra context.

I've added that extension hook method back in and added a test for it.

@axllent
Copy link
Contributor Author

axllent commented Dec 20, 2023

Whew - I was starting to doubt my end-of-year sanity :) Glad it makes sense now!

@emteknetnz emteknetnz merged commit d262afb into silverstripe:2.6 Jan 23, 2024
11 checks passed
@emteknetnz
Copy link
Member

This will be automatically tagged as 2.6.2 shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants