Bug 1520125 - Don't use origin attributes to distinguish proxy authentication cache entries. r=dragana, r=mixedpuppy
authorHonza Bambas <honzab.moz@firemni.cz>
Tue, 22 Jan 2019 07:34:00 -0500
changeset 514898 7a27f9d0f611a1c0baf420705a83b4258b93c7fe
parent 514897 fef99cfead16d68737b741e6579c91d1d09ae395
child 514899 2e1923054d3b5103f13e257cd9d416d6679c1460
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdragana, mixedpuppy
bugs1520125
milestone66.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 1520125 - Don't use origin attributes to distinguish proxy authentication cache entries. r=dragana, r=mixedpuppy
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,10 +1,14 @@
 "use strict";
 
+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")) {
     response.setStatusLine(request.httpVersion, 200, "OK");
@@ -69,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() {
@@ -107,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,10 +1,14 @@
 "use strict";
 
+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")) {
     response.setStatusLine(request.httpVersion, 200, "OK");
@@ -71,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() {
@@ -107,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"),
   ]);