Skip to content

Commit 17fd3d4

Browse files
committed
Add workaround for Undertow WebSocket client sending illegal Origin
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.
1 parent 6253cc5 commit 17fd3d4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-boot-samples/spring-boot-sample-websocket-undertow/src/main/java/samples/websocket/SampleUndertowWebSocketsApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public class SampleUndertowWebSocketsApplication extends SpringBootServletInitia
4545

4646
@Override
4747
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
48-
registry.addHandler(echoWebSocketHandler(), "/echo").withSockJS();
49-
registry.addHandler(snakeWebSocketHandler(), "/snake").withSockJS();
48+
registry.addHandler(echoWebSocketHandler(), "/echo").setAllowedOrigins("*")
49+
.withSockJS();
50+
registry.addHandler(snakeWebSocketHandler(), "/snake").setAllowedOrigins("*")
51+
.withSockJS();
5052
}
5153

5254
@Override

0 commit comments

Comments
 (0)