Skip to content

SocketsHttpHandler Doesn't Respect Manual Proxy Bypass #28078

@adamrodger

Description

@adamrodger

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:

image
image

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.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions