From 17fd3d44b7f58e7c63f4a10468e3f7484e270ded Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 19 Feb 2015 14:30:23 +0000 Subject: [PATCH] Add workaround for Undertow WebSocket client sending illegal Origin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Undertow’s WebSocket client sends an illegal Origin header – it does not include the scheme, e.g. it’ll send “localhost” rather than “http://localhost”. This commit works around the problem by allowing access to the SockJS endpoints from any origin, thereby disabling OriginHandlerInterceptor’s checking of the Origin header. --- .../websocket/SampleUndertowWebSocketsApplication.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java index 938fc1d4f50..64454316c63 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java @@ -45,8 +45,10 @@ public class SampleUndertowWebSocketsApplication extends SpringBootServletInitia @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS(); - registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS(); + registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*") + .withSockJS(); + registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*") + .withSockJS(); } @Override