Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Security] json auth listener should not produce a 500 response on bad request format#22034
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Member
dunglas commentedMar 21, 2017
Indeed, it looks reasonable. 👍 |
Member
fabpot commentedMar 22, 2017
Thank you@ogizanagi. |
fabpot added a commit that referenced this pull requestMar 22, 2017
…ponse on bad request format (ogizanagi)This PR was merged into the 3.3-dev branch.Discussion----------[Security] json auth listener should not produce a 500 response on bad request format| Q | A| ------------- | ---| Branch? | master| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | N/A| License | MIT| Doc PR | N/ATo 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 similar `BadCredentialsException` 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=1BTW, should we have another exception type like `BadCredentialsFormatException` or whatever in order to distinct a proper `BadCredentialsException` from a format issue in a failure listener?Commits-------cb175a4 [Security] json auth listener should not produce a 500 response on bad request format
fabpot added a commit that referenced this pull requestApr 29, 2017
… (ogizanagi)This PR was merged into the 3.3-dev branch.Discussion----------[Security] Handle bad request format in json auth listener| Q | A| ------------- | ---| Branch? | master (3.3)| Bug fix? | yesish| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | N/A| License | MIT| Doc PR | N/AIn#22034, I wondered myself if we shouldn't throw a dedicated exception to handle bad formatted requests and give more inputs to the client by returning a 400 response with an explicit message.~~Here is a suggestion, introducing a new `BadRequestFormatException` and using it in `UsernamePasswordJsonAuthenticationListener` whenever there is no custom failure handler set (but someone using its own handler should be able to treat the failure properly too).~~As discussed with@chalasr , it seems better to directly throw a `BadRequestHttpException` as it's actually out of the whole security process. PR updated.Commits-------93a8cb9 [Security] Handle bad request format in json auth listener
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because 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.
Uh oh!
There was an error while loading.Please reload this page.
To me, it looks wrong to simply throw a
BadCredentialsExceptionin 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
UsernamePasswordFormAuthenticationListeneralso throws a similarBadCredentialsExceptionon 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
BadCredentialsFormatExceptionor whatever in order to distinct a properBadCredentialsExceptionfrom a format issue in a failure listener?