Skip to content

Missing CORS headers defined in SockJS CORS configuration #23843

@stnor

Description

@stnor

Affects: 5.2.0


I tried to bump Spring and Spring Sec boms to 5.2.0.RELEASE (from 5.1.6.RELEASE, Spring Sec 5.1.5.RELEASE) and ended up with CORS issues:

Access to XMLHttpRequest at 'https://ws.something.com/ws/info?t=1571689325027' from origin 'https://something.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
something.d4e1dbafa8d1cd4d94b8.js:1 Stomp connect error. Whoops! Lost connection to https://ws.something.com/ws

Headers returned (5.1.6) from the /ws/info endpoint:

access-control-allow-credentials: true
access-control-allow-origin: https://something.com
cache-control: no-store, no-cache, must-revalidate, max-age=0
content-encoding: gzip
content-type: application/json;charset=UTF-8
date: Mon, 21 Oct 2019 21:11:08 GMT
status: 200
vary: Origin,Accept-Encoding

Headers returned (5.2.0) from the /ws/info endpoint.

cache-control: no-store, no-cache, must-revalidate, max-age=0
content-encoding: gzip
content-type: application/json;charset=UTF-8
date: Mon, 21 Oct 2019 20:22:15 GMT
status: 200
vary: Accept-Encoding

Config:

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer {

    @Autowired
    private JwtAuthenticationWebsocketChannelInterceptorAdapter jwtAuthenticationWebsocketChannelInterceptorAdapter;

    @Bean
    public ServletServerContainerFactoryBean createWebSocketContainer() {
        ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
        container.setMaxTextMessageBufferSize(2048);
        container.setMaxBinaryMessageBufferSize(2048);
        return container;
    }

    @Override
    protected void configureStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws")
                .setAllowedOrigins("*")
                .withSockJS()
                .setClientLibraryUrl("https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.1.4/sockjs.min.js");
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.setApplicationDestinationPrefixes("/ws");
        config.enableSimpleBroker("/topic", "/queue", "/user");
    }

    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.interceptors(jwtAuthenticationWebsocketChannelInterceptorAdapter);
    }

}

No other changes to the application than the version bump.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions