Skip to content

Commit a9217d5

Browse files
committed
Safe InetSocketAddress init for WebSocket and SockJS
Issue: SPR-14295
1 parent 9c02a99 commit a9217d5

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

spring-websocket/src/main/java/org/springframework/web/socket/server/standard/AbstractStandardUpgradeStrategy.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,8 +105,20 @@ public void upgrade(ServerHttpRequest request, ServerHttpResponse response,
105105
WebSocketHandler wsHandler, Map<String, Object> attrs) throws HandshakeFailureException {
106106

107107
HttpHeaders headers = request.getHeaders();
108-
InetSocketAddress localAddr = request.getLocalAddress();
109-
InetSocketAddress remoteAddr = request.getRemoteAddress();
108+
InetSocketAddress localAddr = null;
109+
try {
110+
localAddr = request.getLocalAddress();
111+
}
112+
catch (Exception ex) {
113+
// Ignore
114+
}
115+
InetSocketAddress remoteAddr = null;
116+
try {
117+
remoteAddr = request.getRemoteAddress();
118+
}
119+
catch (Exception ex) {
120+
// Ignore
121+
}
110122

111123
StandardWebSocketSession session = new StandardWebSocketSession(headers, attrs, localAddr, remoteAddr, user);
112124
StandardWebSocketHandlerAdapter endpoint = new StandardWebSocketHandlerAdapter(wsHandler, session);

spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/session/AbstractHttpSockJsSession.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -196,8 +196,18 @@ public void handleInitialRequest(ServerHttpRequest request, ServerHttpResponse r
196196
this.uri = request.getURI();
197197
this.handshakeHeaders = request.getHeaders();
198198
this.principal = request.getPrincipal();
199-
this.localAddress = request.getLocalAddress();
200-
this.remoteAddress = request.getRemoteAddress();
199+
try {
200+
this.localAddress = request.getLocalAddress();
201+
}
202+
catch (Exception ex) {
203+
// Ignore
204+
}
205+
try {
206+
this.remoteAddress = request.getRemoteAddress();
207+
}
208+
catch (Exception ex) {
209+
// Ignore
210+
}
201211

202212
synchronized (this.responseLock) {
203213
try {

0 commit comments

Comments
 (0)