Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security]  Move the handleAuthenticationSuccess logic outside try/catch block #39389

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

Merged
merged 1 commit into from
Jan 12, 2021

Conversation

jderusse
Copy link
Member

@jderusse jderusse commented Dec 8, 2020

Q A
Branch? 5.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

The current implementation of AuthenticationManager handle the handleAuthenticationSuccess logic in a try/catch block which triggers the handleAuthenticationFailure in case of failure.

Which could leads to inconsistency and unexpected behavior. The authentication is either successfully or failure, but can't be both in the same request.

@carsonbot carsonbot added this to the 5.1 milestone Dec 8, 2020
@carsonbot carsonbot changed the title [Security] Move the handleAuthenticationSuccess logic outside try/catch block [Security]  Move the handleAuthenticationSuccess logic outside try/catch block Dec 8, 2020
@stof
Copy link
Member

stof commented Dec 8, 2020

shouldn't the $this->eventDispatcher->dispatch(new AuthenticationSuccessEvent($authenticatedToken), AuthenticationEvents::AUTHENTICATION_SUCCESS); be moved as well ?

@wouterj
Copy link
Member

wouterj commented Dec 8, 2020

We should investigate the impact on UserChecker::checkPostAuth here. I'm not sure what happens after this change if it throws an AccountStatusException.

@jderusse
Copy link
Member Author

jderusse commented Dec 8, 2020

Indeed, the UserChecker::checkPostAuth is hooked on LoginSuccessEvent. This break the behavior

@jderusse jderusse force-pushed the fix-auth-success branch 2 times, most recently from 22f6bd9 to c3236ad Compare December 8, 2020 21:15
@jderusse
Copy link
Member Author

jderusse commented Dec 8, 2020

refactor to hook the UserChecker::checkPostAuth method to the AuthenticationSuccessEvent event.

I kept AuthenticationSuccessEvent in the try/catch. This event is not exactly identical to LoginSuccessEvent and does not mean the authentication is completed: An exception thrown between the catch and the LoginSuccessHandler leaves the user neither authenticated, nor get an authentication failure message :/

@jderusse jderusse force-pushed the fix-auth-success branch 2 times, most recently from 9f41c3b to ce370d1 Compare December 11, 2020 16:57
@jderusse
Copy link
Member Author

jderusse commented Jan 3, 2021

hey @wouterj would you mind to have a look?

@wouterj
Copy link
Member

wouterj commented Jan 3, 2021

Hi!

My idea back in 5.1 when introducing LoginSuccessEvent was to deprecate AuthenticationSuccessEvent in 5.4 (we wanted to avoid duplicated class names between the current system and the new one, that's the main reason we called it LoginSuccessEvent).

However, this PR shows that there is a need for an event that doesn't indicate success nor failure, but only indicates that the password was fully checked. Would it make sense to introduce a new PassportValidEvent or the like in 5.3, where the user checker can listen to? Then for 5.1 and 5.2, we can make this change. (we must document this change however, an authentication exception thrown by a LoginSuccessEvent listener will now result in a 500 instead of redirecting back to the login form if I'm correct)

@jderusse
Copy link
Member Author

jderusse commented Jan 3, 2021

Thank you for your input 🤗

However, this PR shows that there is a need for an event that doesn't indicate success nor failure, but only indicates that the password was fully checked. Would it make sense to introduce a new PassportValidEvent or the like in 5.3, where the user checker can listen to? Then for 5.1 and 5.2, we can make this change.

If I understand well, we keep this PR as it (listen to AuthenticationSuccessEvent event), and we open a new PR in 5.3 to add a new event and plug AuthenticationSuccessEvent to this new event.

When this PR will be merged UP, I'll take care of this 👍 .

we must document this change however, an authentication exception thrown by a LoginSuccessEvent listener will now result in a 500 instead of redirecting back to the login form if I'm correct

The current behavior (LoginSuccess leads to a LoginFailure) is a bug (this is the root reason of this PR) and is not documented.
We don't have any documentation about LoginSuccessEvent and LoginFailureEvent
If we want adding a warning about this in the documentation, I don't see where :-(

@wouterj
Copy link
Member

wouterj commented Jan 3, 2021

If we want adding a warning about this in the documentation, I don't see where :-(

Sorry, I thought about CHANGELOG/UPGRADE, not the online docs. I'm not sure though if we do CHANGELOG for patch releases that changed behavior. Otherwise, let's leave it as is, I don't think many are using the experimental stuff in 5.1.

If I understand well, we keep this PR as it (listen to AuthenticationSuccessEvent event), and we open a new PR in 5.3 to add a new event and plug AuthenticationSuccessEvent to this new event.

👍 yes

@fabpot
Copy link
Member

fabpot commented Jan 3, 2021

5.1 goes out of maintenance at the end of the month.

@wouterj
Copy link
Member

wouterj commented Jan 4, 2021

@fabpot I'm not sure I understand what you're trying to say. Are you saying "don't bother about documenting the change" or are you suggesting not to fix this in 5.1? Thanks!

@fabpot
Copy link
Member

fabpot commented Jan 4, 2021

I was suggesting to not patch 5.1 in any way.

@jderusse jderusse changed the base branch from 5.1 to 5.2 January 5, 2021 10:29
@jderusse
Copy link
Member Author

jderusse commented Jan 5, 2021

changed base to 5.2

@jderusse jderusse modified the milestones: 5.1, 5.2 Jan 12, 2021
@jderusse jderusse merged commit 5dff21b into symfony:5.2 Jan 12, 2021
@jderusse jderusse deleted the fix-auth-success branch January 25, 2021 09:20
@fabpot fabpot mentioned this pull request Jan 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants