Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge r230052 - WebSocket cookie incorrectly stored
https://bugs.webkit.org/show_bug.cgi?id=184100 <rdar://problem/37928715> Reviewed by Brent Fulgham. Source/WebCore: A cookie received in a WebSocket response should be stored with respect to the origin of the WebSocket server in order for it to be sent in a subsequent request. Also removed a FIXME about implementing support for the long since deprecated Set-Cookie2 header. Test: http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior.html * Modules/websockets/WebSocketChannel.cpp: (WebCore::WebSocketChannel::processBuffer): * Modules/websockets/WebSocketHandshake.h: LayoutTests: * http/tests/websocket/tests/hybi/cookie_wsh.py: Added. Downloaded from <https://github.com/w3c/pywebsocket/blob/b2e1d11086fdf00b33a0d30c504f227e7d4fa86b/src/example/cookie_wsh.py>. (_add_set_cookie): (web_socket_do_extra_handshake): (web_socket_transfer_data): * http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior-expected.txt: Added. * http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior.html: Added.
- Loading branch information
1 parent
2d5f589
commit 2bc84b6
Showing
7 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (C) 2014 Google Inc. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions are | ||
# met: | ||
# | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above | ||
# copyright notice, this list of conditions and the following disclaimer | ||
# in the documentation and/or other materials provided with the | ||
# distribution. | ||
# * Neither the name of Google Inc. nor the names of its | ||
# contributors may be used to endorse or promote products derived from | ||
# this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
from mod_pywebsocket import msgutil | ||
import urlparse | ||
|
||
|
||
def _add_set_cookie(request, value): | ||
request.extra_headers.append(('Set-Cookie', value)) | ||
|
||
def web_socket_do_extra_handshake(request): | ||
components = urlparse.urlparse(request.uri) | ||
command = components[4] | ||
|
||
ONE_DAY_LIFE = 'Max-Age=86400' | ||
|
||
if command == 'set': | ||
_add_set_cookie(request, '; '.join(['foo=bar', ONE_DAY_LIFE])) | ||
elif command == 'set_httponly': | ||
_add_set_cookie(request, | ||
'; '.join(['httpOnlyFoo=bar', ONE_DAY_LIFE, 'httpOnly'])) | ||
elif command == 'clear': | ||
_add_set_cookie(request, 'foo=0; Max-Age=0') | ||
_add_set_cookie(request, 'httpOnlyFoo=0; Max-Age=0') | ||
|
||
|
||
def web_socket_transfer_data(request): | ||
pass |
14 changes: 14 additions & 0 deletions
14
LayoutTests/http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Tests WebSocket Set-Cookie overwriting behavior with respect to a document cookie. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
Same origin WebSocket: | ||
PASS cookieValue is "foo=bar" | ||
|
||
Cross origin WebSocket: | ||
PASS cookieValue is "" | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
62 changes: 62 additions & 0 deletions
62
LayoutTests/http/tests/websocket/tests/hybi/websocket-cookie-overwrite-behavior.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../../../../js-test-resources/js-test.js"></script> | ||
<script> | ||
window.jsTestIsAsync = true; | ||
|
||
var cookieValue; | ||
|
||
function clearCookie() | ||
{ | ||
document.cookie = "foo=0; Max-Age=0"; // The key "foo" must match the key used in the WebSocket Set-Cookie header. | ||
} | ||
|
||
function setCookieFromHost(host) | ||
{ | ||
var promise = new Promise(resolve => { | ||
var websocket = new WebSocket(`ws://${host}:8880/websocket/tests/hybi/cookie?set`); | ||
websocket.onclose = () => resolve(); | ||
}); | ||
return promise; | ||
} | ||
|
||
function echoCookie() | ||
{ | ||
return document.cookie; | ||
} | ||
|
||
async function testSameOriginCookie() | ||
{ | ||
clearCookie(); | ||
document.cookie = "foo=should_be_overwritten_by_websocket_set_cookie"; | ||
await setCookieFromHost("127.0.0.1"); | ||
cookieValue = echoCookie(); | ||
shouldBeEqualToString("cookieValue", "foo=bar"); | ||
} | ||
|
||
async function testCrossOriginCookie() | ||
{ | ||
clearCookie(); | ||
await setCookieFromHost("localhost"); | ||
cookieValue = echoCookie(); | ||
shouldBeEmptyString("cookieValue"); | ||
} | ||
|
||
async function runTests() | ||
{ | ||
debug("Same origin WebSocket:"); | ||
await testSameOriginCookie(); | ||
debug("<br>Cross origin WebSocket:"); | ||
await testCrossOriginCookie(); | ||
finishJSTest(); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<script> | ||
description("Tests WebSocket Set-Cookie overwriting behavior with respect to a document cookie."); | ||
runTests(); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters