Title: [250446] branches/safari-608-branch
Revision
250446
Author
[email protected]
Date
2019-09-27 13:25:29 -0700 (Fri, 27 Sep 2019)

Log Message

Cherry-pick r250300. rdar://problem/55770718

    Mixed content blocking is bypassed for WebSockets in Workers (159726)
    https://bugs.webkit.org/show_bug.cgi?id=159726
    <rdar://problem/27326438>

    Patch by Kate Cheney <[email protected]> on 2019-09-24
    Reviewed by Brady Eidson.

    Source/WebCore:

    Tests: http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html
           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html
           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html
           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html

    * Modules/websockets/WebSocket.cpp:
    (WebCore::WebSocket::connect):
    * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
    (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):
    * loader/MixedContentChecker.cpp:
    (WebCore::MixedContentChecker::checkForMixedContentInFrameTree):
    * loader/MixedContentChecker.h:
    Patch to block insecure WebSocket URL connection attempts by Workers
    on secure pages. If the URL is ws, and any embedding iframe has protocol
    https, and the context is a Worker, the connection should be blocked.

    I was unable to write a test case to hit the case where a document
    does not have a frame and tries to communicate via a worker to
    connect to a WebSocket because after removing the subframe from its
    parent, the subframe is unable to perform a postMessage to a worker
    even in the same script execution to tell the worker to connect
    to a WebSocket.

    LayoutTests:

    Added 4 test cases and 2 html resources utilized by the tests.
    The cases test the following:
    1. an https page with a worker trying to connect via ws: url -->
    fails.
    2. an https page embedded in an http page trying to connect via ws
    :url (through a worker) --> fails.
    3. an http page embedded in an https page with an http top frame
    trying to connect via an insecure ws url fails.
    4. an https page embedded in an http page embedded in an https page
    trying to connect to a ws :url via a worker --> fails.

    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt: Added.
    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html: Added.
    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html: Added.
    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedding-https.js: Added.
    (handleConnect.self.postMessage):
    (handleConnect):
    (runTests.ws.onopen):
    (runTests.ws.onerror):
    (runTests):
    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html: Added.
    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js: Added.
    (handleConnect.self.postMessage):
    (handleConnect):
    (runTests.ws.onopen):
    (runTests.ws.onerror):
    (runTests):
    * http/tests/workers/service/resources/serviceworker-websocket-worker.js:
    (async.doTest):
    Updated previous test which was hitting the fix to use a wss url

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250300 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-608-branch/LayoutTests/ChangeLog (250445 => 250446)


--- branches/safari-608-branch/LayoutTests/ChangeLog	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/LayoutTests/ChangeLog	2019-09-27 20:25:29 UTC (rev 250446)
@@ -1,3 +1,125 @@
+2019-09-27  Alan Coon  <[email protected]>
+
+        Cherry-pick r250300. rdar://problem/55770718
+
+    Mixed content blocking is bypassed for WebSockets in Workers (159726)
+    https://bugs.webkit.org/show_bug.cgi?id=159726
+    <rdar://problem/27326438>
+    
+    Patch by Kate Cheney <[email protected]> on 2019-09-24
+    Reviewed by Brady Eidson.
+    
+    Source/WebCore:
+    
+    Tests: http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html
+    
+    * Modules/websockets/WebSocket.cpp:
+    (WebCore::WebSocket::connect):
+    * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+    (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):
+    * loader/MixedContentChecker.cpp:
+    (WebCore::MixedContentChecker::checkForMixedContentInFrameTree):
+    * loader/MixedContentChecker.h:
+    Patch to block insecure WebSocket URL connection attempts by Workers
+    on secure pages. If the URL is ws, and any embedding iframe has protocol
+    https, and the context is a Worker, the connection should be blocked.
+    
+    I was unable to write a test case to hit the case where a document
+    does not have a frame and tries to communicate via a worker to
+    connect to a WebSocket because after removing the subframe from its
+    parent, the subframe is unable to perform a postMessage to a worker
+    even in the same script execution to tell the worker to connect
+    to a WebSocket.
+    
+    LayoutTests:
+    
+    Added 4 test cases and 2 html resources utilized by the tests.
+    The cases test the following:
+    1. an https page with a worker trying to connect via ws: url -->
+    fails.
+    2. an https page embedded in an http page trying to connect via ws
+    :url (through a worker) --> fails.
+    3. an http page embedded in an https page with an http top frame
+    trying to connect via an insecure ws url fails.
+    4. an https page embedded in an http page embedded in an https page
+    trying to connect to a ws :url via a worker --> fails.
+    
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedding-https.js: Added.
+    (handleConnect.self.postMessage):
+    (handleConnect):
+    (runTests.ws.onopen):
+    (runTests.ws.onerror):
+    (runTests):
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js: Added.
+    (handleConnect.self.postMessage):
+    (handleConnect):
+    (runTests.ws.onopen):
+    (runTests.ws.onerror):
+    (runTests):
+    * http/tests/workers/service/resources/serviceworker-websocket-worker.js:
+    (async.doTest):
+    Updated previous test which was hitting the fix to use a wss url
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250300 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-24  Kate Cheney  <[email protected]>
+
+            Mixed content blocking is bypassed for WebSockets in Workers (159726)
+            https://bugs.webkit.org/show_bug.cgi?id=159726
+            <rdar://problem/27326438>
+
+            Reviewed by Brady Eidson.
+
+            Added 4 test cases and 2 html resources utilized by the tests.
+            The cases test the following:
+            1. an https page with a worker trying to connect via ws: url -->
+            fails.
+            2. an https page embedded in an http page trying to connect via ws
+            :url (through a worker) --> fails.
+            3. an http page embedded in an https page with an http top frame
+            trying to connect via an insecure ws url fails.
+            4. an https page embedded in an http page embedded in an https page
+            trying to connect to a ws :url via a worker --> fails.
+
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt: Added.
+            * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html: Added.
+            * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html: Added.
+            * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedding-https.js: Added.
+            (handleConnect.self.postMessage):
+            (handleConnect):
+            (runTests.ws.onopen):
+            (runTests.ws.onerror):
+            (runTests):
+            * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html: Added.
+            * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js: Added.
+            (handleConnect.self.postMessage):
+            (handleConnect):
+            (runTests.ws.onopen):
+            (runTests.ws.onerror):
+            (runTests):
+            * http/tests/workers/service/resources/serviceworker-websocket-worker.js:
+            (async.doTest):
+            Updated previous test which was hitting the fix to use a wss url
+
 2019-09-23  Alan Coon  <[email protected]>
 
         Cherry-pick r250255. rdar://problem/55644665

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: WebSocket connection failed: The page at https://localhost:8443/websocket/tests/hybi/non-document-mixed-content-blocked.https.html was blocked from connecting insecurely to ws://127.0.0.1:8880/websocket/tests/hybi/simple either because the protocol is insecure or the page is embedded from an insecure page.
+
+Test topFrame http with embedded https blocks worker from iframe.
+
+

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: WebSocket connection failed: The page at https://localhost:8443/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html was blocked from connecting insecurely to ws://127.0.0.1:8880/websocket/tests/hybi/simple either because the protocol is insecure or the page is embedded from an insecure page.
+
+Test topFrame http with embedded https with embedded http blocks worker connecting to insecure webSocket.
+
+

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML>
+<html>
+<head></head>
+<body>
+<iframe src=""
+<p>Test topFrame http with embedded https with embedded http blocks worker connecting to insecure webSocket.
+</p>
+<p></p>
+<pre id=log>
+</pre>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,12 @@
+<!DOCTYPE HTML>
+<html>
+<head></head>
+<body>
+<iframe src=""
+<p>Test topFrame http with embedded https blocks worker from iframe.
+</p>
+<p></p>
+<pre id=log>
+</pre>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,7 @@
+CONSOLE MESSAGE: The page at about:blank was allowed to display insecure content from http://localhost:8000/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html.
+
+CONSOLE MESSAGE: WebSocket connection failed: The page at https://localhost:8443/websocket/tests/hybi/non-document-mixed-content-blocked.https.html was blocked from connecting insecurely to ws://127.0.0.1:8880/websocket/tests/hybi/simple either because the protocol is insecure or the page is embedded from an insecure page.
+
+Test topFrame https with embedded http with embedded https blocks worker trying to connect with insecure webSocket.
+
+

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,23 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+if (window.internals)
+    internals.settings.setAllowDisplayOfInsecureContent(true);
+
+</script>
+</head>
+<body>
+<iframe src=""
+<p>Test topFrame https with embedded http with embedded https blocks worker trying to connect with insecure webSocket.
+</p>
+<p></p>
+<pre id=log>
+</pre>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,9 @@
+CONSOLE MESSAGE: WebSocket connection failed: The page at https://127.0.0.1:8443/websocket/tests/hybi/non-document-mixed-content-blocked.https.html was blocked from connecting insecurely to ws://127.0.0.1:8880/websocket/tests/hybi/simple either because the protocol is insecure or the page is embedded from an insecure page.
+Test mixed content from unsecure WebSocket within Worker blocked from secure page.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS worker onerror. readyState 3
+DONE
+TEST COMPLETE
+

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,44 @@
+<!DOCTYPE HTML>
+<html>
+<head></head>
+<body>
+<p>Test mixed content from unsecure WebSocket within Worker blocked from secure page.</p>
+<p></p>
+<p>On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".</p>
+<pre id=log>
+</pre>
+<script>
+if (location.protocol !== "https:")
+    location = "https://127.0.0.1:8443/wesocket/tests/hybi/non-document-mixed-content-blocked.https.html";
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+if (window.internals)
+    internals.settings.setAllowDisplayOfInsecureContent(true);
+
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    log("TEST COMPLETE");
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var worker = new Worker("resources/non-document-mixed-content-blocked.js");
+worker._onmessage_ = function (event)
+{
+    log(event.data);
+    if (event.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML>
+<html>
+<head></head>
+<body>
+<iframe src=""
+<p>Https page with embedded http</p>
+<pre id=log>
+</pre>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<head></head>
+<body>
+<p></p>
+<p>Plain http page trying to connect to a worker.</p>
+<pre id=log>
+</pre>
+<script>
+
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+}
+
+function log(message)
+{
+    document.getElementById("log").innerHTML += message + "\n";
+}
+
+function endTest()
+{
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+var worker = new Worker("non-document-mixed-content-blocked.js");
+worker._onmessage_ = function (event)
+{
+    log(event.data);
+    if (event.data == "DONE")
+        endTest();
+};
+</script>
+</body>
+</html>

Added: branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js (0 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js	                        (rev 0)
+++ branches/safari-608-branch/LayoutTests/http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js	2019-09-27 20:25:29 UTC (rev 250446)
@@ -0,0 +1,29 @@
+if (self.postMessage)
+    runTests();
+else
+    _onconnect_ = handleConnect;
+
+function handleConnect(event)
+{
+    // For shared workers, create a faux postMessage() API to send message back to the parent page.
+    self.postMessage = function (message) { event.ports[0].postMessage(message); };
+    runTests();
+};
+
+function runTests()
+{
+    var ws = new WebSocket('ws://127.0.0.1:8880/websocket/tests/hybi/simple');
+
+    ws._onopen_ = function() {
+        postMessage("FAIL: worker: Connected. readyState " + ws.readyState);
+        postMessage("DONE");
+    };
+    ws._onerror_ = function(error) {
+        postMessage("PASS worker onerror. readyState " + ws.readyState);
+        postMessage("DONE");
+    };
+
+    setTimeout(function() {
+        postMessage("FAIL worker timeout");
+    }, 3000);
+}

Modified: branches/safari-608-branch/LayoutTests/http/tests/workers/service/resources/serviceworker-websocket-worker.js (250445 => 250446)


--- branches/safari-608-branch/LayoutTests/http/tests/workers/service/resources/serviceworker-websocket-worker.js	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/LayoutTests/http/tests/workers/service/resources/serviceworker-websocket-worker.js	2019-09-27 20:25:29 UTC (rev 250446)
@@ -6,8 +6,7 @@
     }
 
     try {
-        var webSocket = new WebSocket('ws://localhost:8880/websocket/tests/hybi/workers/resources/echo');
-
+        var webSocket = new WebSocket('wss://localhost:9323/websocket/tests/hybi/workers/resources/echo');
         webSocket._onerror_ = (e) => {
             event.source.postMessage("FAIL: websocket had an error: " + e);
         };

Modified: branches/safari-608-branch/Source/WebCore/ChangeLog (250445 => 250446)


--- branches/safari-608-branch/Source/WebCore/ChangeLog	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/Source/WebCore/ChangeLog	2019-09-27 20:25:29 UTC (rev 250446)
@@ -1,5 +1,113 @@
 2019-09-27  Alan Coon  <[email protected]>
 
+        Cherry-pick r250300. rdar://problem/55770718
+
+    Mixed content blocking is bypassed for WebSockets in Workers (159726)
+    https://bugs.webkit.org/show_bug.cgi?id=159726
+    <rdar://problem/27326438>
+    
+    Patch by Kate Cheney <[email protected]> on 2019-09-24
+    Reviewed by Brady Eidson.
+    
+    Source/WebCore:
+    
+    Tests: http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html
+           http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html
+    
+    * Modules/websockets/WebSocket.cpp:
+    (WebCore::WebSocket::connect):
+    * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+    (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):
+    * loader/MixedContentChecker.cpp:
+    (WebCore::MixedContentChecker::checkForMixedContentInFrameTree):
+    * loader/MixedContentChecker.h:
+    Patch to block insecure WebSocket URL connection attempts by Workers
+    on secure pages. If the URL is ws, and any embedding iframe has protocol
+    https, and the context is a Worker, the connection should be blocked.
+    
+    I was unable to write a test case to hit the case where a document
+    does not have a frame and tries to communicate via a worker to
+    connect to a WebSocket because after removing the subframe from its
+    parent, the subframe is unable to perform a postMessage to a worker
+    even in the same script execution to tell the worker to connect
+    to a WebSocket.
+    
+    LayoutTests:
+    
+    Added 4 test cases and 2 html resources utilized by the tests.
+    The cases test the following:
+    1. an https page with a worker trying to connect via ws: url -->
+    fails.
+    2. an https page embedded in an http page trying to connect via ws
+    :url (through a worker) --> fails.
+    3. an http page embedded in an https page with an http top frame
+    trying to connect via an insecure ws url fails.
+    4. an https page embedded in an http page embedded in an https page
+    trying to connect to a ws :url via a worker --> fails.
+    
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https-expected.txt: Added.
+    * http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedded-http.https.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked-embedding-https.js: Added.
+    (handleConnect.self.postMessage):
+    (handleConnect):
+    (runTests.ws.onopen):
+    (runTests.ws.onerror):
+    (runTests):
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.html: Added.
+    * http/tests/websocket/tests/hybi/resources/non-document-mixed-content-blocked.js: Added.
+    (handleConnect.self.postMessage):
+    (handleConnect):
+    (runTests.ws.onopen):
+    (runTests.ws.onerror):
+    (runTests):
+    * http/tests/workers/service/resources/serviceworker-websocket-worker.js:
+    (async.doTest):
+    Updated previous test which was hitting the fix to use a wss url
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@250300 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-24  Kate Cheney  <[email protected]>
+
+            Mixed content blocking is bypassed for WebSockets in Workers (159726)
+            https://bugs.webkit.org/show_bug.cgi?id=159726
+            <rdar://problem/27326438>
+
+            Reviewed by Brady Eidson.
+
+            Tests: http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https-with-embedded-http.html
+                   http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-http-with-embedded-https.html
+                   http/tests/websocket/tests/hybi/non-document-mixed-content-blocked-https-with-embedded-http-with-embedded-https.https.html
+                   http/tests/websocket/tests/hybi/non-document-mixed-content-blocked.https.html
+
+            * Modules/websockets/WebSocket.cpp:
+            (WebCore::WebSocket::connect):
+            * Modules/websockets/WorkerThreadableWebSocketChannel.cpp:
+            (WebCore::WorkerThreadableWebSocketChannel::Bridge::connect):
+            * loader/MixedContentChecker.cpp:
+            (WebCore::MixedContentChecker::checkForMixedContentInFrameTree):
+            * loader/MixedContentChecker.h:
+            Patch to block insecure WebSocket URL connection attempts by Workers
+            on secure pages. If the URL is ws, and any embedding iframe has protocol
+            https, and the context is a Worker, the connection should be blocked.
+
+            I was unable to write a test case to hit the case where a document
+            does not have a frame and tries to communicate via a worker to
+            connect to a WebSocket because after removing the subframe from its
+            parent, the subframe is unable to perform a postMessage to a worker
+            even in the same script execution to tell the worker to connect
+            to a WebSocket.
+
+2019-09-27  Alan Coon  <[email protected]>
+
         Cherry-pick r250290. rdar://problem/55770704
 
     AudioTrackPrivateMediaStreamCocoa does not need to manipulate the audio unit in play/pause methods

Modified: branches/safari-608-branch/Source/WebCore/Modules/websockets/WebSocket.cpp (250445 => 250446)


--- branches/safari-608-branch/Source/WebCore/Modules/websockets/WebSocket.cpp	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/Source/WebCore/Modules/websockets/WebSocket.cpp	2019-09-27 20:25:29 UTC (rev 250446)
@@ -305,6 +305,7 @@
     if (is<Document>(context)) {
         Document& document = downcast<Document>(context);
         RefPtr<Frame> frame = document.frame();
+        // FIXME: make the mixed content check equivalent to the non-document mixed content check currently in WorkerThreadableWebSocketChannel::Bridge::connect()
         if (!frame || !frame->loader().mixedContentChecker().canRunInsecureContent(document.securityOrigin(), m_url)) {
             failAsynchronously();
             return { };

Modified: branches/safari-608-branch/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp (250445 => 250446)


--- branches/safari-608-branch/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/Source/WebCore/Modules/websockets/WorkerThreadableWebSocketChannel.cpp	2019-09-27 20:25:29 UTC (rev 250446)
@@ -33,6 +33,7 @@
 
 #include "Blob.h"
 #include "Document.h"
+#include "FrameLoader.h"
 #include "ScriptExecutionContext.h"
 #include "SocketProvider.h"
 #include "ThreadableWebSocketChannelClientWrapper.h"
@@ -402,9 +403,20 @@
 
     m_loaderProxy.postTaskToLoader([peer = m_peer, url = "" protocol = protocol.isolatedCopy()](ScriptExecutionContext& context) {
         ASSERT(isMainThread());
-        ASSERT_UNUSED(context, context.isDocument());
+        ASSERT(context.isDocument());
         ASSERT(peer);
 
+        auto& document = downcast<Document>(context);
+        
+        // FIXME: make this mixed content check equivalent to the document mixed content check currently in WebSocket::connect()
+        if (document.frame()) {
+            Optional<String> errorString = document.frame()->loader().mixedContentChecker().checkForMixedContentInFrameTree(url);
+            if (errorString) {
+                peer->fail(errorString.value());
+                return;
+            }
+        }
+
         if (peer->connect(url, protocol) == ThreadableWebSocketChannel::ConnectStatus::KO)
             peer->didReceiveMessageError();
     });

Modified: branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.cpp (250445 => 250446)


--- branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.cpp	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.cpp	2019-09-27 20:25:29 UTC (rev 250446)
@@ -120,6 +120,28 @@
     client().didDisplayInsecureContent();
 }
 
+Optional<String> MixedContentChecker::checkForMixedContentInFrameTree(const URL& url)
+{
+    auto* document = m_frame.document();
+
+    while (document) {
+        RELEASE_ASSERT_WITH_MESSAGE(document->frame(), "An unparented document tried to connect to a websocket with url: %s", url.string().utf8().data());
+        
+        auto* frame = document->frame();
+        if (isMixedContent(document->securityOrigin(), url))
+            return makeString("The page at ", document->url().stringCenterEllipsizedToLength(), " was blocked from connecting insecurely to ", url.stringCenterEllipsizedToLength(), " either because the protocol is insecure or the page is embedded from an insecure page.");
+
+        if (frame->isMainFrame())
+            break;
+
+        frame = frame->tree().parent();
+        RELEASE_ASSERT_WITH_MESSAGE(frame, "Should never have a parentless non main frame");
+        document = frame->document();
+    }
+    
+    return WTF::nullopt;
+}
+
 void MixedContentChecker::logWarning(bool allowed, const String& action, const URL& target) const
 {
     const char* errorString = allowed ? " was allowed to " : " was not allowed to ";

Modified: branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.h (250445 => 250446)


--- branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.h	2019-09-27 20:25:23 UTC (rev 250445)
+++ branches/safari-608-branch/Source/WebCore/loader/MixedContentChecker.h	2019-09-27 20:25:29 UTC (rev 250446)
@@ -58,6 +58,7 @@
     bool canRunInsecureContent(SecurityOrigin&, const URL&) const;
     void checkFormForMixedContent(SecurityOrigin&, const URL&) const;
     static bool isMixedContent(SecurityOrigin&, const URL&);
+    Optional<String> checkForMixedContentInFrameTree(const URL&);
 
 private:
     // FIXME: This should probably have a separate client from FrameLoader.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to