[WebSocket]Browser must fail connection if Sec-WebSocket-Protocol mismatched.
[WebKit-https.git] / Source / WebCore / Modules / websockets / WebSocketHandshake.cpp
index 17c59e1..4f32d6c 100644 (file)
@@ -34,6 +34,7 @@
 #if ENABLE(WEB_SOCKETS)
 
 #include "WebSocketHandshake.h"
+#include "WebSocket.h"
 
 #include "Base64.h"
 #include "Cookie.h"
@@ -727,6 +728,18 @@ bool WebSocketHandshake::checkResponseHeaders()
             m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Accept mismatch";
             return false;
         }
+        if (!serverWebSocketProtocol.isNull()) {
+            if (m_clientProtocol.isEmpty()) {
+                m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch";
+                return false;
+            }
+            Vector<String> result;
+            m_clientProtocol.split(String(WebSocket::subProtocolSeperator()), result);
+            if (!result.contains(serverWebSocketProtocol)) {
+                m_failureReason = "Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch";
+                return false;
+            }
+        }
     }
     return true;
 }