Bug 1520125 - Don't use origin attributes to distinguish proxy authentication cache entries. r=dragana, r=mixedpuppy, a=RyanVM FENNEC_65_0_BUILD2 FENNEC_65_0_RELEASE FIREFOX_65_0_BUILD2 FIREFOX_65_0_RELEASE
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 22 Jan 2019 07:34:00 -0500
changeset 509582 896611703c2b8f04f596ebcb09e612b7ab06eea3
parent 509581 9e7348e493af0cd4359776ed95f3e0046bca36b0
child 509583 2118960567b8acf5fbde6899685ae971d4d8a593
push id1914
push userryanvm@gmail.com
push dateThu, 24 Jan 2019 17:47:41 +0000
treeherdermozilla-release@896611703c2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, mixedpuppy, RyanVM
bugs1520125
milestone65.0
Bug 1520125 - Don't use origin attributes to distinguish proxy authentication cache entries. r=dragana, r=mixedpuppy, a=RyanVM
netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
toolkit/components/extensions/test/xpcshell/test_ext_proxy_auth.js
toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js
--- a/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
+++ b/netwerk/protocol/http/nsHttpChannelAuthProvider.cpp
@@ -1537,26 +1537,26 @@ void nsHttpChannelAuthProvider::SetAutho
   nsHttpAuthEntry *entry = nullptr;
   nsresult rv;
 
   // set informations that depend on whether
   // we're authenticating against a proxy
   // or a webserver
   nsISupports **continuationState;
 
+  nsAutoCString suffix;
   if (header == nsHttp::Proxy_Authorization) {
     continuationState = &mProxyAuthContinuationState;
   } else {
     continuationState = &mAuthContinuationState;
+
+    nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel);
+    GetOriginAttributesSuffix(chan, suffix);
   }
 
-  nsCOMPtr<nsIChannel> chan = do_QueryInterface(mAuthChannel);
-  nsAutoCString suffix;
-  GetOriginAttributesSuffix(chan, suffix);
-
   rv = authCache->GetAuthEntryForPath(scheme, host, port, path, suffix, &entry);
   if (NS_SUCCEEDED(rv)) {
     // if we are trying to add a header for origin server auth and if the
     // URL contains an explicit username, then try the given username first.
     // we only want to do this, however, if we know the URL requires auth
     // based on the presence of an auth cache entry for this URL (which is
     // true since we are here).  but, if the username from the URL matches
     // the username from the cache, then we should prefer the password
--- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_auth.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_auth.js
@@ -1,11 +1,13 @@
 "use strict";
 
-Cu.importGlobalProperties(["XMLHttpRequest"]);
+XPCOMUtils.defineLazyServiceGetter(this, "authManager",
+                                   "@mozilla.org/network/http-auth-manager;1",
+                                   "nsIHttpAuthManager");
 
 const proxy = createHttpServer();
 
 // accept proxy connections for mozilla.org
 proxy.identity.add("http", "mozilla.org", 80);
 
 proxy.registerPathHandler("/", (request, response) => {
   if (request.hasHeader("Proxy-Authorization")) {
@@ -71,16 +73,18 @@ add_task(async function test_webRequest_
     browser.test.sendMessage("pac-ready");
   }
 
   let handlingExt = getExtension(background);
 
   await handlingExt.startup();
   await handlingExt.awaitMessage("pac-ready");
 
+  authManager.clearAll();
+
   let contentPage = await ExtensionTestUtils.loadContentPage(`http://mozilla.org/`);
 
   await handlingExt.awaitMessage("done");
   await contentPage.close();
   await handlingExt.unload();
 });
 
 add_task(async function test_webRequest_auth_proxy_system() {
@@ -109,20 +113,20 @@ add_task(async function test_webRequest_
 
   function fetch(url) {
     return new Promise((resolve, reject) => {
       let xhr = new XMLHttpRequest();
       xhr.mozBackgroundRequest = true;
       xhr.open("GET", url);
       xhr.onload = () => { resolve(xhr.responseText); };
       xhr.onerror = () => { reject(xhr.status); };
-      // use a different contextId to avoid auth cache.
-      xhr.setOriginAttributes({userContextId: 1});
       xhr.send();
     });
   }
 
+  authManager.clearAll();
+
   await Promise.all([
     handlingExt.awaitMessage("onAuthRequired"),
     fetch("http://mozilla.org"),
   ]);
   await handlingExt.unload();
 });
--- a/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_proxy_onauthrequired.js
@@ -1,11 +1,13 @@
 "use strict";
 
-Cu.importGlobalProperties(["XMLHttpRequest"]);
+XPCOMUtils.defineLazyServiceGetter(this, "authManager",
+                                   "@mozilla.org/network/http-auth-manager;1",
+                                   "nsIHttpAuthManager");
 
 const proxy = createHttpServer();
 
 // accept proxy connections for mozilla.org
 proxy.identity.add("http", "mozilla.org", 80);
 
 proxy.registerPathHandler("/", (request, response) => {
   if (request.hasHeader("Proxy-Authorization")) {
@@ -73,16 +75,18 @@ add_task(async function test_webRequest_
     browser.test.sendMessage("ready");
   }
 
   let handlingExt = getExtension(background);
 
   await handlingExt.startup();
   await handlingExt.awaitMessage("ready");
 
+  authManager.clearAll();
+
   let contentPage = await ExtensionTestUtils.loadContentPage(`http://mozilla.org/`);
 
   await handlingExt.awaitMessage("done");
   await contentPage.close();
   await handlingExt.unload();
 });
 
 add_task(async function test_webRequest_auth_proxy_system() {
@@ -109,25 +113,25 @@ add_task(async function test_webRequest_
     browser.test.sendMessage("ready");
   }
 
   let handlingExt = getExtension(background);
 
   await handlingExt.startup();
   await handlingExt.awaitMessage("ready");
 
+  authManager.clearAll();
+
   function fetch(url) {
     return new Promise((resolve, reject) => {
       let xhr = new XMLHttpRequest();
       xhr.mozBackgroundRequest = true;
       xhr.open("GET", url);
       xhr.onload = () => { resolve(xhr.responseText); };
       xhr.onerror = () => { reject(xhr.status); };
-      // use a different contextId to avoid auth cache.
-      xhr.setOriginAttributes({userContextId: 1});
       xhr.send();
     });
   }
 
   await Promise.all([
     handlingExt.awaitMessage("onAuthRequired"),
     fetch("http://mozilla.org"),
   ]);