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
Unclean exception handling in PasswordEncoderInterface::encodePassword() #29650
Comments
Well, that one is not an exception you are meant to catch in places using the encoder, as they are related to a bad configuration of the project. Adding BadCredentialsException might make sense. |
OK, so one question is yet open: What to do with the InvalidArgumentException thrown in The easiest (and actually fitting) solution is to also declare it for both methods. |
… implementations (umulmrum) This PR was merged into the 3.4 branch. Discussion ---------- [Security] Declare exceptions that are already thrown by implementations | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #29650 | License | MIT | Doc PR | Adding exception declarations for PasswordEncoderInterface. I think it's a matter of opinion whether this change is a BC break. The BC promise doesn't cover such a case; I'd see it as a BC break to add exceptions in general, but in this case it's more of a "documentation" issue, as most implementations of the interface have been throwing those exceptions for years. Commits ------- f4cc30b Declare exceptions that are already thrown by implementations
Symfony version(s) affected: 2.4+
Description
PasswordEncoderInterface::encodePassword() doesn't declare any exceptions, yet implementations do throw some.
All built-in implementations throw BadCredentialsException if the password is excessively long.
Some implementations also throw LogicExceptions, e.g. Argon2iPasswordEncoder throws it if Argon2i isn't available).
PlaintextPasswordEncoder also throws an InvalidArgumentException if the passed salt contains invalid characters.
Possible Solution
The interface should declare all exceptions implementations are allowed to throw. I think it's safe to say that BadCredentialsException should be added.
Not sure about the others, though. Maybe ignore the fact that LogicExceptions are thrown (if we are quite sure that these exceptions only occur at dev time) and throw BadCredentialsException instead of InvalidArgumentException?
The text was updated successfully, but these errors were encountered: