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

Skip to content

[Security] Exclude remember_me from default login authenticators #60266

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
May 14, 2025

Conversation

santysisi
Copy link
Contributor

@santysisi santysisi commented Apr 25, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #60221
License MIT

πŸ› Bugfix Description:
This fix addresses an issue where the remember_me authenticator was incorrectly included in the list of authenticators used during the security login process. When only one authenticator was configured and it was remember_me, the login flow could break or behave unexpectedly, as remember_me is not intended to be used as a primary authenticator. The login() method has been updated to exclude remember_me from the list, ensuring proper handling of login attempts and avoiding unintended authentication behavior.

@santysisi
Copy link
Contributor Author

I think (though I could be wrong) that the test failures are due to flaky tests.

@chalasr
Copy link
Member

chalasr commented Apr 27, 2025

Thanks for the PR. As said in the linked issue, I'm rather πŸ‘Ž on this as the proposed default_authenticator option doesn't have any effect outside the context of a Security::login() call and its name doesn't convey this which makes it confusing to me. Even if we make it obvious in the option name, I feel like a global option is not appropriate here as the usage of login() is usually marginal in an app.

@santysisi
Copy link
Contributor Author

Thanks for your feedback @chalasr , and you're right, I should have consulted you before proceeding with the implementation. I understand your concerns about approach

Do you think there's a different approach that might still address the underlying need, or would it make more sense to close this pull request?

@chalasr
Copy link
Member

chalasr commented Apr 27, 2025

If you agree to work on the suggested alternative which is to patch the login() method to basically make it exclude remember_me from the retrieved list of authenticators so it works seamlessly in case there's only one authenticator with rememberme configured, I'm fine with repurposing this very PR.

@santysisi
Copy link
Contributor Author

Yeah, I'm fine with that alternative, so I'll go ahead and make the change next weekend.
Thank you for your suggestion.

@santysisi santysisi force-pushed the feature/default-authenticator branch from ed18bb4 to 9d20d21 Compare April 29, 2025 00:17
@santysisi santysisi changed the base branch from 7.3 to 6.4 April 29, 2025 00:18
@santysisi santysisi changed the title [Security] allow configuring a default authenticator [Security] Exclude remember_me from default login authenticators Apr 29, 2025
@santysisi
Copy link
Contributor Author

santysisi commented Apr 29, 2025

Hi @chalasr! πŸ‘‹

I've updated the branch with the patch to the login() method. Since this is a patch to the login behavior, I changed the base branch from 7.3 to 6.4, and also updated the title and description of the PR to reflect the changes.

If there's anything else I need to address, please let me know!

Thanks ❀️

Edit: I was also thinking about adding a new condition here to check if the passed authenticatorName is remember_me. If so, it could trigger a deprecation notice in 7.4, and throw an error in version 8.0. What do you think about that approach?

For Symfony 7.4:
We could trigger a deprecation when an excluded authenticator (like remember_me) is passed:

if (in_array($authenticatorName, self::SECURITY_LOGIN_EXCLUSIONS)) {
     trigger_deprecation('symfony/security-bundle', '7.4', 'The "%s" authenticator is not allowed to be used with the "%s" method. Use a different authenticator.', $authenticatorName, __METHOD__));
}

For Symfony 8.0:
We can escalate this to a logic error to prevent usage entirely

if (in_array($authenticatorName, self::SECURITY_LOGIN_EXCLUSIONS)) {
     throw new LogicException(sprintf('The "%s" authenticator is not allowed to be used with the "%s" method. Use a different authenticator.', $authenticatorName, __METHOD__));
}

@santysisi santysisi force-pushed the feature/default-authenticator branch 3 times, most recently from 2248bb8 to 4f93320 Compare April 29, 2025 01:14
@rosier
Copy link
Contributor

rosier commented May 7, 2025

Would it be an option to always pick the first authenticator from the retrieved list of authenticators and not just when there is only one authenticator configured? (Basically remove these lines https://github.com/symfony/symfony/blob/7.3/src/Symfony/Bundle/SecurityBundle/Security.php#L179-L181)

@chalasr
Copy link
Member

chalasr commented May 9, 2025

Would it be an option to always pick the first authenticator from the retrieved list of authenticators and not just when there is only one authenticator configured? (Basically remove these lines https://github.com/symfony/symfony/blob/7.3/src/Symfony/Bundle/SecurityBundle/Security.php#L179-L181)

Required explicitness is desired in this domain IMHO, better get a good error message than a security hole.

@chalasr
Copy link
Member

chalasr commented May 9, 2025

I was also thinking about adding a new condition here to check if the passed authenticatorName is remember_me. If so, it could trigger a deprecation notice in 7.4, and throw an error in version 8.0. What do you think about that approach?

I get your point but I don't think it is worth it right now, we can rethink about it the day it happens

@santysisi santysisi force-pushed the feature/default-authenticator branch from 4f93320 to fabc0e3 Compare May 9, 2025 21:01
@santysisi santysisi force-pushed the feature/default-authenticator branch from fabc0e3 to 6ea76ca Compare May 9, 2025 21:27
Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

Authenticating through the remember_me authenticator was never meant to work at it's a very special one. πŸ‘ to remove the ambiguity as a bugfix

@fabpot fabpot modified the milestones: 7.3, 6.4 May 14, 2025
@fabpot
Copy link
Member

fabpot commented May 14, 2025

Thank you @santysisi.

@fabpot fabpot merged commit e417f12 into symfony:6.4 May 14, 2025
11 checks passed
This was referenced May 25, 2025
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