Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

[release/2.1] Fix WinHttpHandler when using authenticating proxies #30212

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,21 @@ public void CheckResponseForAuthentication(
out authTarget))
{
// WinHTTP returns an error for schemes it doesn't handle.
// So, we need to ignore the error and just let it stay at 401.
// So, we need to ignore the error and just let it stay at 407.
break;
}

// WinHTTP returns the proper authTarget based on the status code (401, 407).
// But we can validate with assert.
Debug.Assert(authTarget == Interop.WinHttp.WINHTTP_AUTH_TARGET_PROXY);

proxyAuthScheme = ChooseAuthScheme(supportedSchemes, state.Proxy.GetProxy(state.RequestMessage.RequestUri), proxyCreds);
proxyAuthScheme = ChooseAuthScheme(
supportedSchemes,
// TODO: Issue #6997. If Proxy==null, we're using the system proxy which is possibly
// discovered/calculated with a PAC file. So, we can't determine the actual proxy uri at
// this point since it is calculated internally in WinHTTP. For now, pass in null for the uri.
state.Proxy?.GetProxy(state.RequestMessage.RequestUri),
proxyCreds);
state.RetryRequest = true;
break;

Expand Down Expand Up @@ -378,6 +384,15 @@ private static uint ChooseAuthScheme(uint supportedSchemes, Uri uri, ICredential
return 0;
}

if (uri == null && !(credentials is NetworkCredential))
{
// TODO: Issue #6997.
// If the credentials are a NetworkCredential, the uri isn't used when calling .GetCredential() since
// it will work against all uri's. Otherwise, credentials is probably a CredentialCache and passing in
// null for a uri is invalid.
return 0;
}

foreach (uint authScheme in s_authSchemePriorityOrder)
{
if ((supportedSchemes & authScheme) != 0 && credentials.GetCredential(uri, s_authSchemeStringMapping[authScheme]) != null)
Expand Down