Repository navigation
fix(core): dispatch BeforeUserLoggedInEvent once for app password logins - #66945
Conversation
|
/backport to stable35 |
|
/backport to stable34 |
|
/backport to stable33 |
| // Token logins dispatch this event in loginWithToken() | ||
| if (!$isTokenPassword) { | ||
| $this->dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($user, $password)); | ||
| } | ||
|
|
There was a problem hiding this comment.
loginWithToken is private and only called in one place, so why not remove the emit in loginWithToken instead?
There was a problem hiding this comment.
loginWithToken() is also called by tryTokenLogin() for Bearer tokens and session-cookie logins. If we remove the dispatch there, we'd lose BeforeUserLoggedInEvent for those logins.
I could move it to tryTokenLogin() instead, but that would mean either decrypting the token password again or dispatching the event with a null password. Would you prefer that over the current approach?
It would also preserve the attempt event for app-password logins that fail before reaching loginWithToken().
There was a problem hiding this comment.
Hmm.
I would like to avoid the spaghetti code that is getting worse with this conditional event.
So I do not know the details but if you can find a way to refactor without changing the public API and while making the code easier to read and more logical in its behavior that would be good.
Because otherwise this kind of issue with double-event will happen again in another code path.
There was a problem hiding this comment.
We can make the following changes to achieve this:
login() dispatches the event and then calls a new protected method, loginWithCredentials(), which contains the existing login logic.
logClientIn() dispatches the event once at the beginning, as it does on master, and calls loginWithCredentials() instead of login() to avoid dispatching the event twice.
loginWithToken() no longer dispatches the event.
tryTokenLogin() dispatches the event itself, passing null as the password.
However, implementing this approach will introduce the following behavioural changes, which we should discuss and agree on beforehand:
Password logins: login() will now dispatch the event for password-based logins as well. This affects the installer and the globalsiteselector's slave login.
Bearer and cookie-token logins: These will pass null as the password instead of the decrypted password.
App-password logins: Only the event containing the raw app password will be dispatched.
So, while this approach is technically feasible, we should first consider whether these behavioural changes are acceptable and whether they could affect existing integrations.
There was a problem hiding this comment.
It would feel safer to keep the password in the event.
That said, I cannot find any use of getPassword on BeforeUserLoggedInEvent in our code, and I’m unsure what would be the usecase anyway…
There was a problem hiding this comment.
Agreed. I'll keep the password: I'll move the token decryption out of loginWithToken() so tryTokenLogin() can dispatch with the decrypted password, without decrypting twice. The only remaining behaviour change is that login() also dispatches the event for password logins. I'll push the refactor shortly.
c098927 to
e4e0386
Compare
e4e0386 to
f32b3ea
Compare
f32b3ea to
d514cdc
Compare
Only the public login entry points dispatch the event, never the private helpers they share, so no login path can report the same attempt twice. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
d514cdc to
990ca06
Compare
logClientIn() dispatched the event before checking whether the password is an app token, and loginWithToken() dispatched it again, so every request authenticated with an app password produced two login attempt entries in the audit log. Leave token logins to loginWithToken().
Assisted-by: ClaudeCode:claude-opus-5-5
Summary
TODO
Checklist
3. to review, feature component)stable32)AI (if applicable)