-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Using WebSecurity.ignoring results in 401 status code when rendering error page #33341
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
Ah this was also reported a year ago. Sorry! Closing as duplicate of #28768 |
Actually this is not a duplicate of #28768. The linked fix in that case is when multiple security chains are involved. In my case, I have a single chain, but it is just not being applied to some endpoints. The problem is that, for me, sometimes So basically, it doesn't look like it is possible to have a "secured" and an "unsecured" error page. I can either remove security from my error page (or for ERROR dispatches) such that it doesn't apply even when I'm routing from a secured page, or I can include the Spring Security filter chain on all requests and use |
Actually (again):
The reason is that
So for now I could use |
As far as I can see, the only reason (?) to want to have the security chain fire for ERROR dispatches is because we want some of the information added by Spring Security to be available to the ErrorController, either for logging or rendering purposes. In my particular case, I don't need this information so I think the best workaround for me is to explicitly disable the security chain for all ERROR dispatches like this:
|
@rupert-madden-abbott Thanks for your patience. Your analysis here is spot on. Few things to note: While ignoring the security filter chain for error dispatches works in that it shows you the error code, it allows anyone to view the details on the error page (even when the original request was unauthorized). This is something to be aware about before opting for The error page security behavior has changed with Spring Boot 3.0. Spring Boot 2.7 had an This issue also reports a similar problem. I think this is something that, if at all, needs to be fixed in Spring Security. I've created an issue for it here. |
spring-projects/spring-security#12771 has been declined by the Spring Security team, but we're not sure that we want to start deviating from their recommendations. @rupert-madden-abbott I'm going to close this one here, but feel free to add additional comments to spring-projects/spring-security#12771 if you like. |
Any one who is still stuck with this issue can please refer my answer in another post. I could make it working by just permiting the URL |
Thanks, @vemahendran. @mbhave has already noted this in her comment above:
|
If an error is thrown when handling a request to an endpoint that does not have the Spring Security filter chain applied to it (via
WebSecurity.ignoring
), then an additional error is encountered when rendering the built in error page and a 401 status code is returned, rather than the original status code e.g. a 500.When using the default Tomcat server, the status code is altered but no additional error is logged. However, when using undertow, the following error is also logged:
I have upload a sample application that reproduces this issue here.
If you run these tests, you will note that
shouldReturnInternalServerErrorWhenUnauthenticatedAccessToUnsecuredErrorEndpoint
fails.There is an interesting aside. If I use
authorizeHttpRequests
instead ofauthorizeRequests
, then the error page can be successfully rendered. Here are some tests using that configuration and you will note that the equivalent test succeeds.The text was updated successfully, but these errors were encountered: