[Security] json auth listener should not produce a 500 response on bad request format #22034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because
30A5
no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To me, it looks wrong to simply throw a
BadCredentialsException
in the wild, which produces a 500 (unless an entrypoint handles it, which you probably don't have on a json login firewall). There isn't any server error, the client request originated the error due to a wrong format.Instead, the listener should give a chance to the failure handler to resolve it, and return a proper 4XX response. (BTW, the
UsernamePasswordFormAuthenticationListener
also throws a similarBadCredentialsException
on a too long submitted username, which is caught and forwarded to the failure handler)Better diff: https://github.com/symfony/symfony/pull/22034/files?w=1
BTW, should we have another exception type like
BadCredentialsFormatException
or whatever in order to distinct a properBadCredentialsException
from a format issue in a failure listener?