runtime icon indicating copy to clipboard operation
runtime copied to clipboard

HttpClient did'nt respect bypass list in IE

Open McMlok opened this issue 8 years ago • 8 comments

Hello,

After upgrading to .NET Core 2.1.300 (SDK) I have issue in communicating from my app to WCF services. On our LAN we have proxy but for WCF endpoints I setup bypass in IE proxy settings. But in WinHttp I have configured direct access. After upgrading to core 2.1 I get HTTP 407 from proxy server. I find out that there is change in core and core now use WinInet settings not WinHttp by default. But with default proxy setting it didn't respect bypass list in IE.

Possible workarounds are using ENV variable DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER=false or set use proxy to false on HttpClientHandler.

When I set Proxy in HtppClientHandler.Proxy I find out that I can't add address with asterisk like "*.lab.domain.com".

May be there is one of these issues. Core 2.1 by default not use bypass list from WinInet. Or use this list but not support asterisk in address in bypass list.

Thank you

McMlok avatar Jul 12 '18 14:07 McMlok

But in WinHttp I have configured direct access.

Can you be more specific about this? How exactly did you configure WinHTTP? Are you using "netsh" commands?

In general, .NET Core 2.1 uses "Wininet" settings (IE settings) in the same way as before. .NET Core has never used WinHTTP settings except if you use WinHttpHandler directly and use WindowsProxyUsePolicy.UseWinHttpProxy:

https://github.com/dotnet/corefx/blob/3c150ba50dc08a1df3ee85cf9f869ff8f933febe/src/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.cs#L21

Can you show your specific IE settings dialog with your "bypass" list?

cc: @wfurt

davidsh avatar Jul 12 '18 15:07 davidsh

wildcards should be supported. Note, that there is no reverse lookup e.g. if you access server by IP, it will not match the wildcard even if the IP would resolve to xx.lab.domain.com

wfurt avatar Jul 12 '18 17:07 wfurt

Are you using "netsh"

Yes, we used netsh winhttp commands for setup proxy for WCF client

OK, I dont know exactly how WCF client works underhood before 2.1 and usage of HttpClient was my guess.

My IE settings are *.lab.domain.com;etrservice-sit.lab.domain.com;etrservice-int.lab.domain.com;etrservice-dev.lab.domain.com;etrservice-ref.lab.domain.com;tfs.domain.com;etradmin.domain.com;nexus.domain.com

When I try this sample project

static async Task Main(string[] args)
{
    var handler = new HttpClientHandler();
    string[] bypassList = new[]
    {
        "*.lab.domain.com"
    };
    handler.Proxy = new WebProxy(new Uri("http://localhost:3128"), true, bypassList);
    var client = new HttpClient(handler);
    var response = await client.GetAsync("https://testservice.lab.domain.com/WCFService");
    Console.WriteLine(response.StatusCode);
}

I get error parsing '*.lab.domain.com' - Quantifier {x,y} following nothing. OK, WebProxy does'nt support wildcards.

I try sample above without line with handler.Proxy =.... on two computers and maybe it's not connected to .NET Core because on both computers are same .NET Core 2.1.300 SDK

Proxy needs authentication (NTLMv2 or KERBEROS) Computer one - Windows 10 1703 in domain which proxy trust. End with HTTP 200 Computer two - Windows 10 1803 outside of domain which proxy trust. End with HTTP 407 from proxy.

McMlok avatar Jul 13 '18 08:07 McMlok

There might be multiple bugs at work here.

Proxy needs authentication (NTLMv2 or KERBEROS) Computer one - Windows 10 1703 in domain which proxy trust. End with HTTP 200 Computer two - Windows 10 1803 outside of domain which proxy trust. End with HTTP 407 from proxy.

There is a bug in .NET Core 2.1 regarding the use of authenticating proxies that use Windows auth schemes (Negotiate/NTLM). You might be hitting either dotnet/runtime#26461 or dotnet/runtime#26462.

Yes, we used netsh winhttp commands for setup proxy for WCF client OK, I dont know exactly how WCF client works underhood before 2.1 and usage of HttpClient was my guess.

I don't think WCF uses winhttp proxy settings directly via reading 'netsh' commands. @mconnew can you comment on that?

davidsh avatar Jul 13 '18 17:07 davidsh

I get error parsing '*.lab.domain.com' - Quantifier {x,y} following nothing. OK, WebProxy does'nt support wildcards.

.NET WebProxy class does not support wildcards. Neither .NET Framework nor .NET Core have ever supported that.

davidsh avatar Jul 13 '18 17:07 davidsh

Sorry for late answer.

I think issues dotnet/runtime#26461 nor dotnet/runtime#26462 are not applicable to this case. Its because when I want to communicate with endpoint testservice.lab.domain.com I don't want to go to proxy. I want to bypass proxy for all *.lab.domain.com endpoints, then there is no proxy auth. And when I try this in IE it works, but when same do my app HttpClient contact proxy.

McMlok avatar Jul 18 '18 19:07 McMlok

Did you try it without setting the HtppClientHandler.Proxy ??? The default is to get default system proxy setting. So it should work like IE without any additional work.

wfurt avatar Sep 18 '18 23:09 wfurt

No response, not enough information, closing.

karelz avatar Oct 12 '18 19:10 karelz