-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
checkCredentials() force it to be an affirmative yes! #16395
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
Conversation
…s(): you now *must* return true in order for authentication to pass. This was a suggestion at symfony_live to make things more secure: you must opt *into* authentication passing - you can't do nothing in this method and make authentication pass.
$guardAuthenticator->checkCredentials($token->getCredentials(), $user); | ||
if (true !== $guardAuthenticator->checkCredentials($token->getCredentials(), $user)) { | ||
throw new BadCredentialsException(sprintf('Authentication failed because %s::checkCredentials() did not return true', get_class($guardAuthenticator))); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only }
, it's standard
updated! |
👍 for this change. |
Thank you @weaverryan. |
I disagree with this PR, I understand the issue but this is really a user error and returning a boolean won't improve security here. You'd have to keep track of any errors thrown and you cannot do Result:
With the above stated, I consider this change to be useless as it only adds an additional requirement which makes it more complex to get it working in the first place. If a developer really makes a mistake, his (unti)test should catch that and fail. Could this be reverted perhaps? |
As the person who brought it up, I thank you for considering and making this change. |
@iltar this looks like defensive programming. Of course it's not required, defensive programming is never required. But still, it allows one to write safer code by default. I see the benefit of it. If the downside is adding/managing a |
The current check is If the check were to be changed to It also works differently than the usercheckers now. |
The return statement is meaningful: you return
Why would you need to keep track of the state? If you know access should be denied, return |
This changes
GuardAuthenticatorInterface::checkCredentials()
: you now must return true in order for authentication to pass.Before: You could do nothing (i.e. return null) and authentication would pass. You threw an AuthenticationException to cause a failure.
New: You must return
true
for authentication to pass. If you do nothing, we will throw aBadCredentialsException
on your behalf. You can still throw your own exception.This was a suggestion at symfony_live to make things more secure. I think it makes sense.