Commit 7bbd01ba authored by valenting's avatar valenting
Browse files

Bug 1805666 - Do not sort challenges if authentication is already in progress...

Bug 1805666 - Do not sort challenges if authentication is already in progress r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D210280
parent d114c5f0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -11596,6 +11596,13 @@
  value: @IS_EARLY_BETA_OR_EARLIER@
  mirror: always

# When true, authentication challenges will be sorted even if
# an authentication is already in progress. This may cause issues sometimes.
- name: network.auth.sort_challenge_in_progress
  type: RelaxedAtomicBool
  value: false
  mirror: always

# Whether to allow truncated brotli with empty output. This also fixes
# throwing an erroring when receiving highly compressed brotli files when
# no content type is specified (Bug 1715401). This pref can be removed after
+26 −16
Original line number Diff line number Diff line
@@ -619,6 +619,15 @@ nsresult nsHttpChannelAuthProvider::GetCredentials(
    cc.AppendElement(ac);
  }

  // Returns true if an authorization is in progress
  auto authInProgress = [&]() -> bool {
    return proxyAuth ? mProxyAuthContinuationState : mAuthContinuationState;
  };

  // We shouldn't sort if authorization is already in progress
  // otherwise we might end up picking the wrong one. See bug 1805666
  if (!authInProgress() ||
      StaticPrefs::network_auth_sort_challenge_in_progress()) {
    cc.StableSort([](const AuthChallenge& lhs, const AuthChallenge& rhs) {
      // Different auth types
      if (lhs.rank != rhs.rank) {
@@ -638,6 +647,7 @@ nsresult nsHttpChannelAuthProvider::GetCredentials(

      return lhs.algorithm < rhs.algorithm ? 1 : -1;
    });
  }

  nsCOMPtr<nsIHttpAuthenticator> auth;
  nsCString authType;  // force heap allocation to enable string sharing since