Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(core): dispatch BeforeUserLoggedInEvent once for app password logins - #66945

Merged
artonge merged 1 commit into
masterfrom
fix/login-event-dispatched-twice
Dec 1, 2026
Merged

artonge merged 1 commit into
masterfrom
fix/login-event-dispatched-twice

Conversation

@GhassenKefi

Copy link
Copy Markdown
Contributor

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

  • Resolves: #

Summary

TODO

  • ...

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@GhassenKefi GhassenKefi self-assigned this Nov 22, 2026
@GhassenKefi
GhassenKefi requested review from a team as code owners November 22, 2026 20:31
@GhassenKefi
GhassenKefi requested review from Altahrim and come-nc and removed request for a team November 22, 2026 20:31
@GhassenKefi GhassenKefi added 3. to review Waiting for reviews AI assisted labels Nov 22, 2026
@GhassenKefi

Copy link
Copy Markdown
Contributor Author

/backport to stable35

@GhassenKefi

Copy link
Copy Markdown
Contributor Author

/backport to stable34

@GhassenKefi

Copy link
Copy Markdown
Contributor Author

/backport to stable33

Comment thread lib/private/User/Session.php Outdated
Comment on lines +430 to +434
// Token logins dispatch this event in loginWithToken()
if (!$isTokenPassword) {
$this->dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($user, $password));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loginWithToken is private and only called in one place, so why not remove the emit in loginWithToken instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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…

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@artonge
artonge requested a review from pringelmann November 24, 2026 11:57
@GhassenKefi
GhassenKefi force-pushed the fix/login-event-dispatched-twice branch from c098927 to e4e0386 Compare November 26, 2026 10:46

@come-nc come-nc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks way better now.
I would like #64203 to get merged first and you will have conflicts to fix I think.

Comment thread lib/private/User/Session.php Resolved
Comment thread lib/private/User/Session.php Resolved
@GhassenKefi
GhassenKefi force-pushed the fix/login-event-dispatched-twice branch from e4e0386 to f32b3ea Compare November 29, 2026 12:31
@GhassenKefi
GhassenKefi requested a review from come-nc November 29, 2026 12:35
@come-nc
come-nc force-pushed the fix/login-event-dispatched-twice branch from f32b3ea to d514cdc Compare November 30, 2026 11:10
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>
@GhassenKefi
GhassenKefi force-pushed the fix/login-event-dispatched-twice branch from d514cdc to 990ca06 Compare December 1, 2026 09:17
@come-nc
come-nc enabled auto-merge December 1, 2026 10:28
@artonge
artonge disabled auto-merge December 1, 2026 11:42
@artonge
artonge merged commit 6d28b97 into master Dec 1, 2026
158 of 166 checks passed
@artonge
artonge deleted the fix/login-event-dispatched-twice branch December 1, 2026 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants