-
Notifications
You must be signed in to change notification settings - Fork 6k
ExceptionTranslationFilter should not try to handle when response is committed #5273
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
Comments
There's some analysis by Andy in spring-projects/spring-boot#12995 (comment) |
Thanks for the report @andreysaksonov and forwarding it on @philwebb I'm not sure what we can do to improve the user experience. If the response is already committed |
I'm closing this as works as designed. This is not a Spring Security specific issue. Generally speaking, you cannot have an error in the error handling within the container because it is going to produce an If you have better ideas on what to do, please let me know. However, I do not see a better way to solve this problem. |
IMO, letting the |
@wilkinsona Thanks for the response. To me the user should get a 500 as this is a programming error. What is your suggestion on what to do if the response is committed? |
I’d just let the error that’s already been sent and that marked the response as committed make it back to the client. It might not be the ideal response, but I think it’d be better than the current behaviour. |
Thanks for your fast response. I disagree that the suggestion is an improvement. The outlined scenario is a programming error within the application. Specifically, an unauthorized resource was requested and there was no way for the framework to handle the exception because the response was already committed. The developers of the application need to know to fix this and a 500 sent to the client is the appropriate response. Perhaps an alternative is to have Spring Security re-throw the original |
There’s no code in the application that’s catching exceptions or sending an error. It’s Jersey that’s doing so. And, FWIW, what it is doing doesn’t seem unreasonable to me. Jersey has caught an exception and, as a result, has sent an error to the client. The exception’s then re-thrown. Spring Security has caught this exception and assumed that it can and should send an error. It does this without checking that something else hasn’t already done so which is where things are going wrong.
That sounds good to me. If, when it catches an exception, Spring Security determines it can’t do anything because the response is committed, rethrowing the exception seems like a reasonable thing to do as it should make things behave as if Security hadn’t caught the exception in the first place. Oh and I should have said this above: thanks for reconsidering closing this as working as designed. |
Thanks for following up again so quickly. I'm glad we found a solution that made sense for both of us. I do think this is an improvement on where things were at, so thanks for prodding me to reconsider this. I updated Spring Security to avoid trying to handle the exception in the event that the response is committed. The changes are in 5.0.5.BUILD-SNAPSHOT and 5.1.0.BUILD-SNAPSHOT. |
Unfortunately, the change that has been made doesn't fully address the problem. Trying it with the sample application that was supplied with the Boot issue shows that a 500 is still returned:
There is an improvement as the message now reads "Access is denied" so I think the change made in 9bb841a was the right thing to do. To fully address the issue, I've now learned that Jersey can be configured so that it doesn't use |
Thanks for following up with the proposed changes in Boot |
Originally raised in spring-projects/spring-boot#12995.
If you try use GlobalMethodSecurity on Jersey resources you will face exception below:
The text was updated successfully, but these errors were encountered: