Title: [112377] trunk
Revision
112377
Author
[email protected]
Date
2012-03-28 02:12:00 -0700 (Wed, 28 Mar 2012)

Log Message

[WebSocket]The Sec-WebSocket-Protocol must not appear more than once in an HTTP response
https://bugs.webkit.org/show_bug.cgi?id=82432

Patch by Li Yin <[email protected]> on 2012-03-28
Reviewed by Kent Tamura.

Source/WebCore:

>From RFC6455: http://tools.ietf.org/html/rfc6455#section-11.3.4
The |Sec-WebSocket-Protocol| header field must not appear
more than once in an HTTP response.

Test: http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html

* Modules/websockets/WebSocketHandshake.cpp:
(WebCore::WebSocketHandshake::readHTTPHeaders):

LayoutTests:

>From RFC6455: http://tools.ietf.org/html/rfc6455#section-11.3.4
The |Sec-WebSocket-Protocol| header field must not appear
more than once in an HTTP response.

* http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header_wsh.py: Added.
(web_socket_do_extra_handshake):
(web_socket_transfer_data):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (112376 => 112377)


--- trunk/LayoutTests/ChangeLog	2012-03-28 08:59:43 UTC (rev 112376)
+++ trunk/LayoutTests/ChangeLog	2012-03-28 09:12:00 UTC (rev 112377)
@@ -1,3 +1,20 @@
+2012-03-28  Li Yin  <[email protected]>
+
+        [WebSocket]The Sec-WebSocket-Protocol must not appear more than once in an HTTP response
+        https://bugs.webkit.org/show_bug.cgi?id=82432
+
+        Reviewed by Kent Tamura.
+
+        From RFC6455: http://tools.ietf.org/html/rfc6455#section-11.3.4
+        The |Sec-WebSocket-Protocol| header field must not appear
+        more than once in an HTTP response.
+
+        * http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header-expected.txt: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html: Added.
+        * http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header_wsh.py: Added.
+        (web_socket_do_extra_handshake):
+        (web_socket_transfer_data):
+
 2012-03-28  Philippe Normand  <[email protected]>
 
         Unreviewed, GTK rebaseline after r112254.

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header-expected.txt (0 => 112377)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header-expected.txt	2012-03-28 09:12:00 UTC (rev 112377)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: The Sec-WebSocket-Protocol header MUST NOT appear more than once in an HTTP response
+Test that WebSocket handshake fails if there are more than one Sec-WebSocket-Protocol header field in the response.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html (0 => 112377)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html	2012-03-28 09:12:00 UTC (rev 112377)
@@ -0,0 +1,51 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="description"></div>
+<div id="console"></div>
+<script>
+description("Test that WebSocket handshake fails if there are more than one Sec-WebSocket-Protocol header field in the response.");
+
+window.jsTestIsAsync = true;
+if (window.layoutTestController)
+    layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+
+function endTest()
+{
+    clearTimeout(timeoutID);
+    finishJSTest();
+}
+
+var url = ""
+var ws = new WebSocket(url, "MatchProtocol");
+
+ws._onopen_ = function()
+{
+    testFailed("Unexpectedly Connected.");
+};
+
+ws._onmessage_ = function(messageEvent)
+{
+    testFailed("Unexpectedly Received: '" + messageEvent.data + "'");
+};
+
+ws._onclose_ = function()
+{
+    endTest();
+};
+
+function timeOutCallback()
+{
+    debug("Timed out in state: " + ws.readyState);
+    endTest();
+}
+
+var timeoutID = setTimeout(timeOutCallback, 3000);
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header_wsh.py (0 => 112377)


--- trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header_wsh.py	                        (rev 0)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header_wsh.py	2012-03-28 09:12:00 UTC (rev 112377)
@@ -0,0 +1,18 @@
+from mod_pywebsocket import handshake
+from mod_pywebsocket.handshake.hybi import compute_accept
+
+
+def web_socket_do_extra_handshake(request):
+    msg = 'HTTP/1.1 101 Switching Protocols\r\n'
+    msg += 'Upgrade: websocket\r\n'
+    msg += 'Connection: Upgrade\r\n'
+    msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
+    msg += 'Sec-WebSocket-Protocol: MatchProtocol\r\n'
+    msg += 'Sec-WebSocket-Protocol: MismatchProtocol\r\n'
+    msg += '\r\n'
+    request.connection.write(msg)
+    raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from sending its own handshake message.
+
+
+def web_socket_transfer_data(request):
+    pass

Modified: trunk/Source/WebCore/ChangeLog (112376 => 112377)


--- trunk/Source/WebCore/ChangeLog	2012-03-28 08:59:43 UTC (rev 112376)
+++ trunk/Source/WebCore/ChangeLog	2012-03-28 09:12:00 UTC (rev 112377)
@@ -1,3 +1,19 @@
+2012-03-28  Li Yin  <[email protected]>
+
+        [WebSocket]The Sec-WebSocket-Protocol must not appear more than once in an HTTP response
+        https://bugs.webkit.org/show_bug.cgi?id=82432
+
+        Reviewed by Kent Tamura.
+
+        From RFC6455: http://tools.ietf.org/html/rfc6455#section-11.3.4
+        The |Sec-WebSocket-Protocol| header field must not appear 
+        more than once in an HTTP response.
+
+        Test: http/tests/websocket/tests/hybi/handshake-fail-by-more-protocol-header.html
+
+        * Modules/websockets/WebSocketHandshake.cpp:
+        (WebCore::WebSocketHandshake::readHTTPHeaders):
+
 2012-03-27  James Robinson  <[email protected]>
 
         [chromium] Transfer wheel fling via WebCompositorInputHandlerClient

Modified: trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp (112376 => 112377)


--- trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2012-03-28 08:59:43 UTC (rev 112376)
+++ trunk/Source/WebCore/Modules/websockets/WebSocketHandshake.cpp	2012-03-28 09:12:00 UTC (rev 112377)
@@ -576,6 +576,7 @@
     Vector<char> name;
     Vector<char> value;
     bool sawSecWebSocketAcceptHeaderField = false;
+    bool sawSecWebSocketProtocolHeaderField = false;
     for (const char* p = start; p < end; p++) {
         name.clear();
         value.clear();
@@ -652,6 +653,13 @@
             }
             m_response.addHeaderField(nameStr, valueStr);
             sawSecWebSocketAcceptHeaderField = true;
+        } else if (equalIgnoringCase("Sec-WebSocket-Protocol", nameStr)) {
+            if (sawSecWebSocketProtocolHeaderField) {
+                m_failureReason = "The Sec-WebSocket-Protocol header MUST NOT appear more than once in an HTTP response";
+                return 0;
+            }
+            m_response.addHeaderField(nameStr, valueStr);
+            sawSecWebSocketProtocolHeaderField = true;
         } else
             m_response.addHeaderField(nameStr, valueStr);
     }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to