Skip to content

Commit ba45cab

Browse files
committed
Validate the headers of WebSocket handshake request loosely #1602
1 parent 71f0f97 commit ba45cab

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

turms-gateway/src/main/java/im/turms/gateway/access/client/websocket/WebSocketServerFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package im.turms.gateway.access.client.websocket;
1919

2020
import java.net.InetSocketAddress;
21-
import java.util.List;
2221
import jakarta.annotation.Nullable;
2322

2423
import io.netty.buffer.ByteBuf;
@@ -228,14 +227,13 @@ private static HttpResponseStatus validateHandshakeRequest(HttpServerRequest req
228227
+ method
229228
+ "' not supported");
230229
}
231-
if (!"WebSocket".equalsIgnoreCase(headers.get(UPGRADE))) {
230+
if (!headers.containsValue(UPGRADE, "websocket", true)) {
232231
return new HttpResponseStatus(
233232
HttpResponseStatus.BAD_REQUEST.code(),
234233
"Invalid 'Upgrade' header: "
235234
+ headers);
236235
}
237-
List<String> connectionValue = headers.getAll(CONNECTION);
238-
if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
236+
if (!headers.containsValue(CONNECTION, "upgrade", true)) {
239237
return new HttpResponseStatus(
240238
HttpResponseStatus.BAD_REQUEST.code(),
241239
"Invalid 'Connection' header: "

0 commit comments

Comments
 (0)