Title: [220805] trunk
Revision
220805
Author
[email protected]
Date
2017-08-16 13:20:56 -0700 (Wed, 16 Aug 2017)

Log Message

Consider allow gUM to be called from localhost without https
https://bugs.webkit.org/show_bug.cgi?id=173457
<rdar://problem/33900527>

Reviewed by Youenn Fablet.

Source/WebCore:

Tests: http/tests/media/media-stream/get-user-media-localhost.html
       http/tests/media/media-stream/get-user-media-loopback-ip.html

* Modules/mediastream/UserMediaRequest.cpp:
(WebCore::isSecure): Call SchemeRegistry::shouldTreatURLSchemeAsSecure instead of looking for
the string 'https'.
(WebCore::canCallGetUserMedia): Allow localhost or loopback address.

* page/SecurityOrigin.cpp:
(WebCore::isLoopbackIPAddress): Add a comment.
(WebCore::shouldTreatAsPotentionallyTrustworthy): Move tests for localhost and loopback address
to isLocalHostOrLoopbackIPAddress, call it.
(WebCore::SecurityOrigin::isLocalHostOrLoopbackIPAddress):
* page/SecurityOrigin.h:

LayoutTests:

* http/tests/media/media-stream/get-user-media-localhost-expected.txt: Added.
* http/tests/media/media-stream/get-user-media-localhost.html: Added.
* http/tests/media/media-stream/get-user-media-loopback-ip-expected.txt: Added.
* http/tests/media/media-stream/get-user-media-loopback-ip.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (220804 => 220805)


--- trunk/LayoutTests/ChangeLog	2017-08-16 20:19:58 UTC (rev 220804)
+++ trunk/LayoutTests/ChangeLog	2017-08-16 20:20:56 UTC (rev 220805)
@@ -1,3 +1,16 @@
+2017-08-16  Eric Carlson  <[email protected]>
+
+        Consider allow gUM to be called from localhost without https
+        https://bugs.webkit.org/show_bug.cgi?id=173457
+        <rdar://problem/33900527>
+
+        Reviewed by Youenn Fablet.
+
+        * http/tests/media/media-stream/get-user-media-localhost-expected.txt: Added.
+        * http/tests/media/media-stream/get-user-media-localhost.html: Added.
+        * http/tests/media/media-stream/get-user-media-loopback-ip-expected.txt: Added.
+        * http/tests/media/media-stream/get-user-media-loopback-ip.html: Added.
+
 2017-08-16  Ryan Haddad  <[email protected]>
 
         Skip workers/wasm-hashset-many.html and workers/wasm-hashset-many-2.html

Added: trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost-expected.txt (0 => 220805)


--- trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost-expected.txt	2017-08-16 20:20:56 UTC (rev 220805)
@@ -0,0 +1,10 @@
+Tests that getUserMedia is allowed from localhost when secure connection is required.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getUserMedia succeeded
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost.html (0 => 220805)


--- trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-user-media-localhost.html	2017-08-16 20:20:56 UTC (rev 220805)
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <script src=""
+        <script>
+
+            window.jsTestIsAsync = true;
+
+            if (window.internals)
+                internals.settings.setMediaCaptureRequiresSecureConnection(true);
+
+            if (window.testRunner) {
+                testRunner.waitUntilDone();
+                testRunner.setUserMediaPermission(true);
+                testRunner.dumpAsText();
+            }
+
+            if (location.hostname != "localhost")
+                window.location = `${location.protocol}//localhost:${location.port}${location.pathname}`;
+            else {
+                window.addEventListener("load", async () => {
+                    try {
+                        await window.navigator.mediaDevices.getUserMedia({audio:true});
+                        testPassed("getUserMedia succeeded");
+                    } catch(err) {
+                        testFailed(`getUserMedia should have succeeded but failed with error "${err}"`);
+                    }
+
+                    finishJSTest();
+                });
+            }
+
+            description("Tests that getUserMedia is allowed from localhost when secure connection is required.");
+        </script>
+        <script src=""
+    </head>
+    <body>
+        <div id="console"></div>
+    </body>
+</html>

Added: trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip-expected.txt (0 => 220805)


--- trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip-expected.txt	2017-08-16 20:20:56 UTC (rev 220805)
@@ -0,0 +1,10 @@
+Tests that getUserMedia is allowed from the loopback IP address when secure connection is required.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getUserMedia succeeded
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip.html (0 => 220805)


--- trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/media/media-stream/get-user-media-loopback-ip.html	2017-08-16 20:20:56 UTC (rev 220805)
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <script src=""
+        <script>
+
+            window.jsTestIsAsync = true;
+
+            if (window.internals)
+                internals.settings.setMediaCaptureRequiresSecureConnection(true);
+
+            if (window.testRunner) {
+                testRunner.waitUntilDone();
+                testRunner.setUserMediaPermission(true);
+                testRunner.dumpAsText();
+            }
+
+            window.addEventListener("load", async () => {
+                if (location.protocol != "http:" || location.host != "127.0.0.1:8000") {
+                    testFailed("This test must be run from http://127.0.0.1:8000");
+                    finishJSTest();
+                    return;
+                }
+
+                try {
+                    await window.navigator.mediaDevices.getUserMedia({audio:true});
+                    testPassed("getUserMedia succeeded");
+                } catch(err) {
+                    testFailed(`getUserMedia should have succeeded but failed with error "${err}"`);
+                }
+
+                finishJSTest();
+            });
+
+            description("Tests that getUserMedia is allowed from the loopback IP address when secure connection is required.");
+        </script>
+        <script src=""
+    </head>
+    <body>
+        <div id="console"></div>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (220804 => 220805)


--- trunk/Source/WebCore/ChangeLog	2017-08-16 20:19:58 UTC (rev 220804)
+++ trunk/Source/WebCore/ChangeLog	2017-08-16 20:20:56 UTC (rev 220805)
@@ -1,3 +1,26 @@
+2017-08-16  Eric Carlson  <[email protected]>
+
+        Consider allow gUM to be called from localhost without https
+        https://bugs.webkit.org/show_bug.cgi?id=173457
+        <rdar://problem/33900527>
+
+        Reviewed by Youenn Fablet.
+
+        Tests: http/tests/media/media-stream/get-user-media-localhost.html
+               http/tests/media/media-stream/get-user-media-loopback-ip.html
+
+        * Modules/mediastream/UserMediaRequest.cpp:
+        (WebCore::isSecure): Call SchemeRegistry::shouldTreatURLSchemeAsSecure instead of looking for
+        the string 'https'.
+        (WebCore::canCallGetUserMedia): Allow localhost or loopback address.
+
+        * page/SecurityOrigin.cpp:
+        (WebCore::isLoopbackIPAddress): Add a comment.
+        (WebCore::shouldTreatAsPotentionallyTrustworthy): Move tests for localhost and loopback address
+        to isLocalHostOrLoopbackIPAddress, call it.
+        (WebCore::SecurityOrigin::isLocalHostOrLoopbackIPAddress): 
+        * page/SecurityOrigin.h:
+
 2017-08-16  Chris Dumez  <[email protected]>
 
         EventSource: ignore IDs with U+0000

Modified: trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp (220804 => 220805)


--- trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2017-08-16 20:19:58 UTC (rev 220804)
+++ trunk/Source/WebCore/Modules/mediastream/UserMediaRequest.cpp	2017-08-16 20:20:56 UTC (rev 220805)
@@ -1,7 +1,7 @@
 /*
  * Copyright (C) 2011 Ericsson AB. All rights reserved.
  * Copyright (C) 2012 Google Inc. All rights reserved.
- * Copyright (C) 2013-2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
  * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@
 #include "MainFrame.h"
 #include "MediaConstraints.h"
 #include "RealtimeMediaSourceCenter.h"
+#include "SchemeRegistry.h"
 #include "Settings.h"
 #include "UserMediaController.h"
 
@@ -94,7 +95,7 @@
 static bool isSecure(DocumentLoader& documentLoader)
 {
     auto& response = documentLoader.response();
-    return response.url().protocolIs("https")
+    return SchemeRegistry::shouldTreatURLSchemeAsSecure(response.url().protocol().toStringWithoutCopying())
         && response.certificateInfo()
         && !response.certificateInfo()->containsNonRootSHA1SignedCertificate();
 }
@@ -102,7 +103,8 @@
 static bool canCallGetUserMedia(Document& document, String& errorMessage)
 {
     bool requiresSecureConnection = document.settings().mediaCaptureRequiresSecureConnection();
-    if (requiresSecureConnection && !isSecure(*document.loader())) {
+    auto& documentLoader = *document.loader();
+    if (requiresSecureConnection && !isSecure(documentLoader) && !SecurityOrigin::isLocalHostOrLoopbackIPAddress(documentLoader.response().url())) {
         errorMessage = "Trying to call getUserMedia from an insecure document.";
         return false;
     }

Modified: trunk/Source/WebCore/page/SecurityOrigin.cpp (220804 => 220805)


--- trunk/Source/WebCore/page/SecurityOrigin.cpp	2017-08-16 20:19:58 UTC (rev 220804)
+++ trunk/Source/WebCore/page/SecurityOrigin.cpp	2017-08-16 20:20:56 UTC (rev 220805)
@@ -101,6 +101,7 @@
 
 static bool isLoopbackIPAddress(const URL& url)
 {
+    // The IPv6 loopback address is 0:0:0:0:0:0:0:1, which compresses to ::1.
     ASSERT(url.isValid());
     auto host = url.host();
     if (host == "[::1]")
@@ -130,13 +131,9 @@
     if (SchemeRegistry::shouldTreatURLSchemeAsSecure(url.protocol().toStringWithoutCopying()))
         return true;
 
-    if (isLoopbackIPAddress(url))
+    if (SecurityOrigin::isLocalHostOrLoopbackIPAddress(url))
         return true;
 
-    // FIXME: Ensure that localhost resolves to the loopback address.
-    if (equalLettersIgnoringASCIICase(url.host(), "localhost"))
-        return true;
-
     if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol().toStringWithoutCopying()))
         return true;
 
@@ -587,4 +584,16 @@
     return uniqueSecurityOriginURL;
 }
 
+bool SecurityOrigin::isLocalHostOrLoopbackIPAddress(const URL& url)
+{
+    if (isLoopbackIPAddress(url))
+        return true;
+
+    // FIXME: Ensure that localhost resolves to the loopback address.
+    if (equalLettersIgnoringASCIICase(url.host(), "localhost"))
+        return true;
+
+    return false;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/page/SecurityOrigin.h (220804 => 220805)


--- trunk/Source/WebCore/page/SecurityOrigin.h	2017-08-16 20:19:58 UTC (rev 220804)
+++ trunk/Source/WebCore/page/SecurityOrigin.h	2017-08-16 20:20:56 UTC (rev 220805)
@@ -202,6 +202,8 @@
 
     bool isPotentionallyTrustworthy() const { return m_isPotentionallyTrustworthy; }
 
+    static bool isLocalHostOrLoopbackIPAddress(const URL&);
+
 private:
     SecurityOrigin();
     explicit SecurityOrigin(const URL&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to