Issue
.Net Core versions tested: 2.1.2, 2.1.6, 2.2.0
OS tested: Windows Server 2016 x64
If your Windows proxy settings are set to:


then SocketsHttpHandler doesn't respect proxy bypass preferences.
Reproduction
- In Internet Options:
- Tick "Automatically detect settings"
- Populate the proxy server details at the bottom
- Click 'Advanced' and add some manual proxy exclusions
- Using a
HttpClient, request a URL which should match the manual exclusion list.
Expected result: The request does not go via the proxy as it matches the bypass list
Actual Result: The bypass list is ignored and the request goes via the proxy
Cause
With the configuration above, WinInetProxyHelper has the following properties:
WinInetHttpProxyHelper:
AutoConfigUrl:
AutoDetect: True
AutoSettingsUsed: True
ManualSettingsOnly: False
Proxy: myproxy.local:8080
ProxyBypass: localhost;*.local
When WinInetProxyHelper.GetProxyForUrl() is called, it fails during auto-detection since there's no PAC file, and then falls back to the manual proxy settings (in this case myproxy.local:8080). The manual settings are then parsed and returned by HttpSystemProxy.GetProxy()
However, HttpSystemProxy.IsBypassed contains an assumption that HttpSystemProxy.GetProxy() will have returned null when AutoSettingsUsed is true, but that assumption is incorrect because the manual fallback settings were returned instead of null. This means the URL goes via the proxy even if it matches the bypass list.
Workaround
You can either:
- Untick "Automatically detect settings" to cause
AutoSettingsUsed to be false, then HttpSystemProxy.GetProxy() will actually check the bypass list and return null if a bypass matches, or
- Set the environment variable
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER to 0 so that SocketsHttpHandler isn't used (which shows that this is a regression from the older WinHttpHandler implementation).
The longer term solution should probably be that if auto-detection is enabled but fails, set AutoSettingsUsed to false so that the normal manual behaviour is used.
Issue
.Net Core versions tested:
2.1.2,2.1.6,2.2.0OS tested: Windows Server 2016 x64
If your Windows proxy settings are set to:
then
SocketsHttpHandlerdoesn't respect proxy bypass preferences.Reproduction
HttpClient, request a URL which should match the manual exclusion list.Expected result: The request does not go via the proxy as it matches the bypass list
Actual Result: The bypass list is ignored and the request goes via the proxy
Cause
With the configuration above,
WinInetProxyHelperhas the following properties:When
WinInetProxyHelper.GetProxyForUrl()is called, it fails during auto-detection since there's no PAC file, and then falls back to the manual proxy settings (in this casemyproxy.local:8080). The manual settings are then parsed and returned byHttpSystemProxy.GetProxy()However,
HttpSystemProxy.IsBypassedcontains an assumption thatHttpSystemProxy.GetProxy()will have returnednullwhenAutoSettingsUsedistrue, but that assumption is incorrect because the manual fallback settings were returned instead ofnull. This means the URL goes via the proxy even if it matches the bypass list.Workaround
You can either:
AutoSettingsUsedto befalse, thenHttpSystemProxy.GetProxy()will actually check the bypass list and returnnullif a bypass matches, orDOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLERto0so thatSocketsHttpHandlerisn't used (which shows that this is a regression from the olderWinHttpHandlerimplementation).The longer term solution should probably be that if auto-detection is enabled but fails, set
AutoSettingsUsedto false so that the normal manual behaviour is used.