-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Cannot configure ErrorPageSecurityFilter to not prevent sending message body on authentication failures #29383
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
Thanks for the report, @xcq1. There have been some improvements in this area in Spring Security. The details are in spring-projects/spring-security#10554, the changes for which have been backported to the yet-to-be-released 5.6.2 and 5.5.5. The gist is that things should now work better with multiple security filter chains and when a URL is covered by ignoring(), i.e. when there's no Could you please give your app a try with Spring Security 5.6.2-SNAPSHOT available from https://repo.spring.io/snapshot and let us know how you get on? If it doesn't help, could you please share a small sample application that reproduces the problem that you're facing? You can share it with us by zipping it up and attaching it to this issue or pushing it to a separate repository in GitHub. In the meantime, you may also be interested in this workaround which should work equally well in main code. It'll remove the filter entirely. |
Thanks @wilkinsona, those are excellent news. |
Thanks very much for trying the security snapshot, @xcq1. It's great to hear that it fixes your problem. I'll close this one as a duplicate of the security issues. We'll pick up the Security maintenance releases in due course. |
I've been trying to update one Spring Boot project today from 2.5.8 to 2.6.2. However the introduction of
ErrorPageSecurityFilter
causes me quite some headache. I've read a few other issues that say it's fixed now, but I cannot find a way to make my use case work:We have a client that tries to authenticate with the Spring Boot server. Before the update, it would just sent 401 and a message containing the reason for the failure. When no message is returned (like now) the client assumes some sort of Internal Server Error. The way this is implemented is that we have an
AuthenticationFailureHandler
that handlesAuthenticationException
during the authentication process and then essentially callsresponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, exception.message)
.Now the suggestion with the new filter as far as I understood is to permit access to "/error" to explicitly allow this behavior. However that will never work as the
WebInvocationPrivilegeEvaluator
whenisAllowed()
is called, checksif (authentication == null) return false;
and I don't have an authentication since it just failed to authenticate. Even if I try to set one, it gets removed.I would be completely fine with just disabling the new filter entirely, but this seems to be extremely difficult?
I've tried setting the property
server.error.include-message=always
, but as far as I can see that changes nothing. Creating my ownFilterRegistrationBean<ErrorPageSecurityFilter>
and settingsetEnabled(false)
doesn't work. I can't simply exclude theErrorPageSecurityFilterConfiguration
since it's not an AutoConfiguration and/or package private. I've tried wrapping theDefaultWebInvocationPrivilegeEvaluator
to always allow/error
, but that is getting nowhere because in theWebSecurityConfigurerAdapter
the constructor argumentFilterSecurityInterceptor
has no public getter and it apparently gets passed by some complicated mechanism.So obviously, if the default configuration had been like this from the start, we would have never designed the flow like this; but I feel like the current behavior should be easier to opt-out of.
The text was updated successfully, but these errors were encountered: