Cannot configure allowedOrigins for OriginHandshakeInterceptor
cpesch opened this issue · 3 comments
After an update to SpringBoot 2.1.4 and WAMP2Spring 2.0.2, my application stopped working. The OriginHandshakeInterceptor blocks requests since the Origin header contains the port 8080 which is not expected.
My setup is an Apache with
RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /ws ws://localhost:8080/ws [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /ws http://localhost:8080/ws [P,L]
ProxyPass /api/ http://localhost:8080/
ProxyPassReverse /ws http://localhost:8080/ws
in front of the Spring Boot app.
I've tried to configure OriginHandshakeInterceptor#setAllowedOrigins() but got stuck at the point that it's created in AbstractWebSocketHandlerRegistration#getInterceptors() but I found no way to configure AbstractWebSocketHandlerRegistration#setAllowedOrigins()
Am I blind or how is this supposed to work?
I use this code for configuring CORS. Let me know if this no longer works.
@SpringBootApplication
@EnableScheduling
@EnableServletWamp(disable = Feature.DEALER)
public class Application implements WampServletConfigurer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void configureWebSocketHandlerRegistration(
WebSocketHandlerRegistration registration) {
registration.setAllowedOrigins("*");
}
}
Maybe the better solution is to forward the real origin from Apache to Spring Boot.
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
Thank you for the fast response. Using
ProxyPreserveHost On
worked fine for me and feels like the better solution.