Bug 1382834 fix ws/wss protocol matching, r=kmag
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 24 Jul 2017 17:00:29 -0700
changeset 420198 59e214139531f8aaf544d93f9fba0a77d6efa554
parent 420197 4e92ebe6256dbc4776c569004aa416a5ed1f200e
child 420199 a9029a587fec3ad8f2d2ea7586b4d54a7c3265e5
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1382834
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1382834 fix ws/wss protocol matching, r=kmag MozReview-Commit-ID: 6IKTPA1sJgh
toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
toolkit/modules/addons/MatchPattern.jsm
toolkit/modules/addons/WebRequest.jsm
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
@@ -21,17 +21,17 @@ add_task(async function test_webSocket()
         "webRequestBlocking",
         "<all_urls>",
       ],
     },
     background() {
       browser.webRequest.onBeforeRequest.addListener(details => {
         browser.test.assertEq("ws:", new URL(details.url).protocol, "ws protocol worked");
         browser.test.notifyPass("websocket");
-      }, {urls: ["*://mochi.test/*"]}, ["blocking"]);
+      }, {urls: ["ws://mochi.test/*"]}, ["blocking"]);
 
       browser.test.onMessage.addListener(msg => {
         let ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/file_websocket_hello");
         ws.onopen = (e) => {
           ws.send("data");
         };
         ws.onclose = (e) => {};
         ws.onerror = (e) => {};
--- a/toolkit/modules/addons/MatchPattern.jsm
+++ b/toolkit/modules/addons/MatchPattern.jsm
@@ -13,17 +13,17 @@ XPCOMUtils.defineLazyModuleGetter(this, 
                                   "resource://gre/modules/NetUtil.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 
 this.EXPORTED_SYMBOLS = ["MatchPattern", "MatchGlobs", "MatchURLFilters"];
 
 /* globals MatchPattern, MatchGlobs */
 
-const PERMITTED_SCHEMES = ["http", "https", "file", "ftp", "data"];
+const PERMITTED_SCHEMES = ["http", "https", "ws", "wss", "file", "ftp", "data"];
 const PERMITTED_SCHEMES_REGEXP = [...PERMITTED_SCHEMES, "moz-extension"].join("|");
 
 // The basic RE for matching patterns
 const PATTERN_REGEXP = new RegExp(`^(${PERMITTED_SCHEMES_REGEXP}|\\*)://(\\*|\\*\\.[^*/]+|[^*/]+|)(/.*)$`);
 
 // The schemes/protocols implied by a pattern that starts with *://
 const WILDCARD_SCHEMES = ["http", "https"];
 
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -676,18 +676,18 @@ HttpObserverManager = {
     } else if (lastActivity !== this.GOOD_LAST_ACTIVITY &&
                lastActivity !== nsIHttpActivityObserver.ACTIVITY_SUBTYPE_TRANSACTION_CLOSE) {
       channelData.lastActivity = activitySubtype;
     }
   },
 
   shouldRunListener(policyType, uri, filter) {
     // force the protocol to be ws again.
-    if (policyType == "websocket" && uri.startsWith("http")) {
-      uri = `ws${uri.substring(4)}`;
+    if (policyType == "websocket" && ["http", "https"].includes(uri.scheme)) {
+      uri = new Services.io.newURI(`ws${uri.spec.substring(4)}`);
     }
     return WebRequestCommon.typeMatches(policyType, filter.types) &&
            WebRequestCommon.urlMatches(uri, filter.urls);
   },
 
   get resultsMap() {
     delete this.resultsMap;
     this.resultsMap = new Map(Object.keys(Cr).map(name => [Cr[name], name]));