-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
EnableWebSocketSecurity
is not 1:1 replacement for AbstractSecurityWebSocketMessageBrokerConfigurer
#13640
Comments
Hi @filiphr, thanks for reaching out! The intention of the check when using @Bean
public ChannelInterceptor csrfChannelInterceptor() {
return new ChannelInterceptor() {};
} Does that provide a viable path forward for you? |
That workaround is a bit more complicated, especially considering the fact that we are creating returning the boolean based on a property configuration. We could try using Boot's |
@filiphr sorry for the delay on replies. You can use Boot's @Bean
public ChannelInterceptor csrfChannelInterceptor(ApplicationContext context) {
if (!sameOriginDisabled(context)) {
return new XorCsrfChannelInterceptor();
} else {
return new ChannelInterceptor() {};
}
}
// ... Does that help? In regard to making |
@sjohnr that is not enough. That will only cover the case when invoking Lines 222 to 245 in 9de717a
When using I think that the best solution would be for Spring Security to provide some other interface that would be used in
I do not agree with this. Since the capabilities of the abstract class are not the same of the capabilities of the |
Hi @filiphr, thanks for following up! I did not focus on the Currently with I don't have full context on
I'm not keen on re-introducing this type of configuration element if we can be more straightforward then that. Since this seems to be about disabling CSRF protection, I'd prefer to provide a direct mechanism for disabling it. I wonder if it would be better to make it possible to simply disable the protection through publishing a bean. Instead of a customizer with property names, we could add a Alternatively, we could detect the Either way, the goal would be to allow a smooth migration (with some good javadoc to help guide the user), but not simply replicate old patterns needlessly. Would either of these be a promising path forward? |
I am completely OK to have some other mechanism that will disable the CSRF protection. It doesn't have to be named
Using a special bean for the
Being able to detect a custom
The goal is indeed to allow a smooth migration. How this is done doesn't really matter. However, I do not like the proposals as they are not that intuitive. I would suggest the following. Why not introduce something like the public interface WebSocketSecurityConfigurer {
/**
* <p>
* Determines if a CSRF token is required for connecting. This protects against remote
* sites from connecting to the application and being able to read/write data over the
* connection. The default is false (the token is required).
* </p>
* <p>
* Subclasses can override this method to disable CSRF protection
* </p>
* @return false if a CSRF token is required for connecting, else true
*/
default boolean csrfDisabled() {
return false;
}
} and then in you would use such a bean (if one exists); If the That makes it relatively easy for people to configure what they need to configure. At least in my opinion |
Thanks for the feedback, @filiphr. I appreciate the conversation!
Since the existing abstract configurer class was deprecated in favor of annotations + configuration through publishing beans, my preference would be not to introduce a new interface like this to replace it. This is also generally the opposite of the direction the Spring Security codebase is headed, which favors publishing components as beans that are directly configurable themselves (instead of configurers that apply or implement configuration). Perhaps we could look at introducing an attribute on the annotation as well, such as |
The annotation is not enough, since it doesn't allow programatic configuration through properties. It means you would be forcing people to use Spring Boot and
You can still achieve the same thing by allowing people to publish beans. Thinking more about it, to make it even more easier to configure CSRF you can introduce an enum public enum WebSocketCsrfStrategy {
XOR_CSRF,
CSRF,
NONE,
} People can expose this bean and based on this you can even switch to using Anyways, I'll leave it up to you. I completely understand the fact that you would like to favor another direction for Spring Security configuration. I am trying to provide feedback of how we use some parts of Spring Security and what kind of stuff we need to configure for our projects. |
Hi @filiphr.
Agreed, I mentioned it as an additional option to be the easiest way for folks migrating to fully disable CSRF. But if it isn't useful immediately, we don't need to introduce it right now. |
Any update? |
1 similar comment
Any update? |
Describe the bug
When using
AbstractSecurityWebSocketMessageBrokerConfigurer
we can overridesameOriginDisabled
and enable or disable theCsrfChannelInterceptor
. InconfigureClientInboundChannel
it doesHowever, with
@EnableWebSocketSecurity
it is not possible to disable it since inconfigureClientInboundChannel
it doesand in the configuration itself it is already defined through
The same
sameOriginDisabled
is also used inafterSingletonsInstantiated
to configure the CSRF for the handler mappings.Expected behavior
Provide a 1:1 replacement for the deprecated
AbstractSecurityWebSocketMessageBrokerConfigurer
The text was updated successfully, but these errors were encountered: