Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

SocketsHttpHandler: fix logic to check for Proxy-support header#27886

Merged
geoffkizer merged 2 commits intodotnet:masterfrom
geoffkizer:fixntproxyauth
Mar 12, 2018
Merged

SocketsHttpHandler: fix logic to check for Proxy-support header#27886
geoffkizer merged 2 commits intodotnet:masterfrom
geoffkizer:fixntproxyauth

Conversation

@geoffkizer
Copy link

Currently we're looking for this header when we do proxy auth. This is wrong. We should look for this header when we are trying to do regular auth through a proxy.

@davidsh @wfurt @stephentoub

Fixes #27872

@wfurt can you test and confirm that this fixes #27872? (Windows only)


if (TryGetAuthenticationChallenge(response, isProxyAuth, authUri, credentials, out AuthenticationChallenge challenge) &&
(!isProxyAuth || CheckIfProxySupportsConnectionAuth(response)))
if (!isProxyAuth && connection.UsingProxy && !CheckIfProxySupportsConnectionAuth(response))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "IsProxyAuth" mean here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could CheckIfProxySupportsConnectionAuth just be ProxySupportsConnectionAuth?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's better, I'll change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re isProxyAuth:

This routine (and the similar one in AuthenticationHelper for basic/digest) is used in two cases:
(1) Authenticate against proxy (isProxyAuth = true)
(2) Authenticate against origin server (isProxyAuth = false)

The logic is basically the same between these two cases, just different status code (407 vs 401) and different header names (Proxy-Authenticate vs Www-Authenticate, Proxy-Authorization vs Authorization). So we just use the isProxyAuth flag to distinguish.

For example, this helper is called:

        private static HttpHeaderValueCollection<AuthenticationHeaderValue> GetResponseAuthenticationHeaderValues(HttpResponseMessage response, bool isProxyAuth)
        {
            return isProxyAuth ?
                response.Headers.ProxyAuthenticate :
                response.Headers.WwwAuthenticate;
        }

I'm open to a better parameter name than "isProxyAuth" if you have suggestions...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. Maybe just a comment on the parameter explaining what it is.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps "proxyAuthMode"?

@geoffkizer
Copy link
Author

@wfurt, I'm going to merge. Let me know when you have a chance to try this in your setup.

@geoffkizer geoffkizer merged commit ae60f0f into dotnet:master Mar 12, 2018
@karelz karelz added this to the 2.1.0 milestone Mar 18, 2018
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
SocketsHttpHandler: fix logic to check for Proxy-support header

Commit migrated from dotnet/corefx@ae60f0f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SocketHttpHandler is failing NTLM authentication to proxy

4 participants