Filter out TURN/STUN .local URLs from a RTCPeerConnection iceServers list
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2020 16:40:19 +0000 (16:40 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Feb 2020 16:40:19 +0000 (16:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207332

Reviewed by Eric Carlson.

LayoutTests/imported/w3c:

* web-platform-tests/webrtc/RTCConfiguration-iceServers-expected.txt:
Rebase tests since we are passing a few more sub tests by converting String to a Vector of one string,
as allowed by the spec and tested by this test.

Source/WebCore:

Test: webrtc/stun-server-filtering.html

* Modules/mediastream/RTCPeerConnection.cpp:
(WebCore::iceServersFromConfiguration):
Ignore .local URLs for STUN/TURN servers as they are not used right now
and could be used to discover local network services.

LayoutTests:

* webrtc/stun-server-filtering-expected.txt: Added.
* webrtc/stun-server-filtering.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/webrtc/RTCConfiguration-iceServers-expected.txt
LayoutTests/webrtc/stun-server-filtering-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/stun-server-filtering.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp

index d51261b..0885ffc 100644 (file)
@@ -1,3 +1,13 @@
+2020-02-07  youenn fablet  <youenn@apple.com>
+
+        Filter out TURN/STUN .local URLs from a RTCPeerConnection iceServers list
+        https://bugs.webkit.org/show_bug.cgi?id=207332
+
+        Reviewed by Eric Carlson.
+
+        * webrtc/stun-server-filtering-expected.txt: Added.
+        * webrtc/stun-server-filtering.html: Added.
+
 2020-02-07  Tomoki Imai  <Tomoki.Imai@sony.com>
 
         [OpenSSL] Implement WebCrypto APIs for AES-CBC, AES-CFB and AES-GCM
index bec8d33..dfd2cce 100644 (file)
@@ -1,3 +1,14 @@
+2020-02-07  youenn fablet  <youenn@apple.com>
+
+        Filter out TURN/STUN .local URLs from a RTCPeerConnection iceServers list
+        https://bugs.webkit.org/show_bug.cgi?id=207332
+
+        Reviewed by Eric Carlson.
+
+        * web-platform-tests/webrtc/RTCConfiguration-iceServers-expected.txt:
+        Rebase tests since we are passing a few more sub tests by converting String to a Vector of one string,
+        as allowed by the spec and tested by this test.
+
 2020-02-07  Rob Buis  <rbuis@igalia.com>
 
         Fix fetch/api/policies/referrer-origin-worker.html
index 9767e09..a48522f 100644 (file)
@@ -14,22 +14,22 @@ PASS new RTCPeerConnection(config) - { iceServers: [undefined] } should throw Ty
 PASS setConfiguration(config) - { iceServers: [undefined] } should throw TypeError 
 PASS new RTCPeerConnection(config) - { iceServers: [{}] } should throw TypeError 
 PASS setConfiguration(config) - { iceServers: [{}] } should throw TypeError 
-FAIL new RTCPeerConnection(config) - with stun server should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
-FAIL setConfiguration(config) - with stun server should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
+FAIL new RTCPeerConnection(config) - with stun server should succeed assert_equals: expected (string) "password" but got (undefined) undefined
+FAIL setConfiguration(config) - with stun server should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 FAIL new RTCPeerConnection(config) - with stun server array should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 FAIL setConfiguration(config) - with stun server array should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 FAIL new RTCPeerConnection(config) - with 2 stun servers should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 FAIL setConfiguration(config) - with 2 stun servers should succeed assert_equals: expected (string) "password" but got (undefined) undefined
-FAIL new RTCPeerConnection(config) - with turn server, username, credential should succeed assert_array_equals: value is "turn:turn.example.org", expected array
-FAIL setConfiguration(config) - with turn server, username, credential should succeed assert_array_equals: value is "turn:turn.example.org", expected array
+FAIL new RTCPeerConnection(config) - with turn server, username, credential should succeed assert_equals: expected (string) "password" but got (undefined) undefined
+FAIL setConfiguration(config) - with turn server, username, credential should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 FAIL new RTCPeerConnection(config) - with turns server and empty string username, credential should succeed Bad Configuration Parameters
 FAIL setConfiguration(config) - with turns server and empty string username, credential should succeed Bad Configuration Parameters
 FAIL new RTCPeerConnection(config) - with turn server and empty string username, credential should succeed Bad Configuration Parameters
 FAIL setConfiguration(config) - with turn server and empty string username, credential should succeed Bad Configuration Parameters
 PASS new RTCPeerConnection(config) - with one turns server, one turn server, username, credential should succeed 
 PASS setConfiguration(config) - with one turns server, one turn server, username, credential should succeed 
-FAIL new RTCPeerConnection(config) - with stun server and credentialType password should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
-FAIL setConfiguration(config) - with stun server and credentialType password should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
+FAIL new RTCPeerConnection(config) - with stun server and credentialType password should succeed assert_equals: expected (string) "password" but got (undefined) undefined
+FAIL setConfiguration(config) - with stun server and credentialType password should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 PASS new RTCPeerConnection(config) - with turn server and no credentials should throw InvalidAccessError 
 PASS setConfiguration(config) - with turn server and no credentials should throw InvalidAccessError 
 PASS new RTCPeerConnection(config) - with turn server and only username should throw InvalidAccessError 
@@ -154,12 +154,12 @@ FAIL setConfiguration(config) - with turns server, credentialType oauth, and str
         username: 'user',
         credential: 'cred'
       }] })" did not throw
-FAIL new RTCPeerConnection(config) - with turns server, credentialType oauth and RTCOAuthCredential credential should succeed assert_array_equals: value is "turns:turn.example.org", expected array
-FAIL setConfiguration(config) - with turns server, credentialType oauth and RTCOAuthCredential credential should succeed assert_array_equals: value is "turns:turn.example.org", expected array
+FAIL new RTCPeerConnection(config) - with turns server, credentialType oauth and RTCOAuthCredential credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
+FAIL setConfiguration(config) - with turns server, credentialType oauth and RTCOAuthCredential credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
 FAIL new RTCPeerConnection(config) - with both turns and stun server, credentialType oauth and RTCOAuthCredential credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
 FAIL setConfiguration(config) - with both turns and stun server, credentialType oauth and RTCOAuthCredential credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
-FAIL new RTCPeerConnection(config) - with stun server, credentialType oauth, and string credential should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
-FAIL setConfiguration(config) - with stun server, credentialType oauth, and string credential should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
-FAIL new RTCPeerConnection(config) - with stun server, credentialType password, and RTCOAuthCredential credential should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
-FAIL setConfiguration(config) - with stun server, credentialType password, and RTCOAuthCredential credential should succeed assert_array_equals: value is "stun:stun1.example.net", expected array
+FAIL new RTCPeerConnection(config) - with stun server, credentialType oauth, and string credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
+FAIL setConfiguration(config) - with stun server, credentialType oauth, and string credential should succeed assert_equals: expected (string) "oauth" but got (undefined) undefined
+FAIL new RTCPeerConnection(config) - with stun server, credentialType password, and RTCOAuthCredential credential should succeed assert_equals: expected (string) "password" but got (undefined) undefined
+FAIL setConfiguration(config) - with stun server, credentialType password, and RTCOAuthCredential credential should succeed assert_equals: expected (string) "password" but got (undefined) undefined
 
diff --git a/LayoutTests/webrtc/stun-server-filtering-expected.txt b/LayoutTests/webrtc/stun-server-filtering-expected.txt
new file mode 100644 (file)
index 0000000..542d293
--- /dev/null
@@ -0,0 +1,4 @@
+
+PASS RTCPeerConnection and local STUN server 
+PASS RTCPeerConnection and local TURN server 
+
diff --git a/LayoutTests/webrtc/stun-server-filtering.html b/LayoutTests/webrtc/stun-server-filtering.html
new file mode 100644 (file)
index 0000000..56472b8
--- /dev/null
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<script src='../resources/testharness.js'></script>
+<script src='../resources/testharnessreport.js'></script>
+<script>
+test((test) => {
+    let pc = new RTCPeerConnection({iceServers:[{urls:['stun:foo.com', 'stun:blabla.local']}]});
+    let configuration = pc.getConfiguration();
+
+    assert_equals(configuration.iceServers[0].urls.length, 1);
+    assert_equals(configuration.iceServers[0].urls[0], 'stun:foo.com');
+}, "RTCPeerConnection and local STUN server");
+
+test((test) => {
+    let pc = new RTCPeerConnection({iceServers:[{username: 'test', credential: 'test', urls:['turn:foo.com', 'turn:blabla.local']}]});
+    let configuration = pc.getConfiguration();
+
+    assert_equals(configuration.iceServers[0].urls.length, 1);
+    assert_equals(configuration.iceServers[0].urls[0], 'turn:foo.com');
+}, "RTCPeerConnection and local TURN server");
+</script>
index 8a0c4da..af14570 100644 (file)
@@ -1,3 +1,17 @@
+2020-02-07  youenn fablet  <youenn@apple.com>
+
+        Filter out TURN/STUN .local URLs from a RTCPeerConnection iceServers list
+        https://bugs.webkit.org/show_bug.cgi?id=207332
+
+        Reviewed by Eric Carlson.
+
+        Test: webrtc/stun-server-filtering.html
+
+        * Modules/mediastream/RTCPeerConnection.cpp:
+        (WebCore::iceServersFromConfiguration):
+        Ignore .local URLs for STUN/TURN servers as they are not used right now
+        and could be used to discover local network services.
+
 2020-02-07  Antoine Quint  <graouts@webkit.org>
 
         REGRESSION (r255953): [ iOS Mac ] imported/w3c/web-platform-tests/web-animations/timing-model/timelines/update-and-send-events.html is crashing
index 05471f3..aaabc09 100644 (file)
@@ -294,15 +294,22 @@ static inline ExceptionOr<Vector<MediaEndpointConfiguration::IceServerInfo>> ice
     if (newConfiguration.iceServers) {
         servers.reserveInitialCapacity(newConfiguration.iceServers->size());
         for (auto& server : newConfiguration.iceServers.value()) {
-            Vector<URL> serverURLs;
-            WTF::switchOn(server.urls, [&serverURLs] (const String& string) {
-                serverURLs.reserveInitialCapacity(1);
-                serverURLs.uncheckedAppend(URL { URL { }, string });
-            }, [&serverURLs] (const Vector<String>& vector) {
-                serverURLs.reserveInitialCapacity(vector.size());
-                for (auto& string : vector)
-                    serverURLs.uncheckedAppend(URL { URL { }, string });
+            Vector<String> urls;
+            WTF::switchOn(server.urls, [&urls] (String& url) {
+                urls = { WTFMove(url) };
+            }, [&urls] (Vector<String>& vector) {
+                urls = WTFMove(vector);
             });
+
+            urls.removeAllMatching([](auto& url) {
+                return URL { URL { }, url }.path().endsWithIgnoringASCIICase(".local");
+            });
+
+            auto serverURLs = WTF::map(urls, [](auto& url) -> URL {
+                return { URL { }, url };
+            });
+            server.urls = WTFMove(urls);
+
             for (auto& serverURL : serverURLs) {
                 if (serverURL.isNull())
                     return Exception { TypeError, "Bad ICE server URL" };