spring-projects / spring-projects/spring-security

`EnableWebSocketSecurity` is not 1:1 replacement for `AbstractSecurityWebSocketMessageBrokerConfigurer`

Open
#13,640 12 comments 5 reactions 1 assignee View on GitHub

@sjohnr is already working on this.

Since Aug 10, 2023.

status: feedback-provided type: bug
Dominant language
Java
Stars
9.6k
Forks
6.3k
Avg merge
2d 11h
Merged PRs (30d)
52

Description

Describe the bug
When using AbstractSecurityWebSocketMessageBrokerConfigurer we can override sameOriginDisabled and enable or disable the CsrfChannelInterceptor. In configureClientInboundChannel it does

if (!sameOriginDisabled()) {
    registration.interceptors(this.context.getBean(CsrfChannelInterceptor.class));
}

However, with @EnableWebSocketSecurity it is not possible to disable it since in configureClientInboundChannel it does

ChannelInterceptor csrfChannelInterceptor = getBeanOrNull(CSRF_CHANNEL_INTERCEPTOR_BEAN_NAME, ChannelInterceptor.class);
    if (csrfChannelInterceptor != null) {
        this.csrfChannelInterceptor = csrfChannelInterceptor;
    }

and in the configuration itself it is already defined through

private ChannelInterceptor csrfChannelInterceptor = new XorCsrfChannelInterceptor();

The same sameOriginDisabled is also used in afterSingletonsInstantiated to configure the CSRF for the handler mappings.

Expected behavior
Provide a 1:1 replacement for the deprecated AbstractSecurityWebSocketMessageBrokerConfigurer

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.