Skip to content

Authentication headers for HTTP Proxy are not sent proactively #123363

@ptarjan

Description

@ptarjan

Description

Context

In the https://claude.ai/code environment, the proxy doesn't work for dotnet restore. This is because dotnet restore expect the proxy to respond with an HTTP 407 before it sends the authentication headers, but this one does not.

Problem

When using an authenticated HTTP proxy configured via environment variables (HTTP_PROXY/HTTPS_PROXY with credentials in the URL), dotnet restore and other HttpClient-based operations fail with 401 Unauthorized.

Root cause: The current implementation waits for a 407 Proxy Authentication Required response before sending credentials. However, many proxies:

  1. Return 401 Unauthorized instead of 407
  2. Simply drop/timeout unauthenticated connections without any response
  3. Close the connection after 407, making retry impossible for CONNECT tunnels

Reproduction:

export HTTPS_PROXY="http://user:[email protected]:8080"
dotnet restore  # Fails with 401 or timeout

Direct test showing the issue:

# Without Proxy-Authorization header:
CONNECT example.com:443 HTTP/1.1 → HTTP/1.1 401 Unauthorized
 
# With Proxy-Authorization header:
CONNECT example.com:443 HTTP/1.1
Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==
→ HTTP/1.1 200 OK

Solution

Modify AuthenticationHelper.SendWithProxyAuthAsync to proactively send Proxy-Authorization: Basic ... header on the first request when NetworkCredential is available, rather than waiting for a challenge.

This matches the behavior of curl, wget, and other HTTP clients that send proxy auth proactively.

Affected scenarios

  • Corporate proxies requiring authentication
  • Container environments with authenticated egress proxies
  • CI/CD pipelines behind authenticated proxies

Reproduction Steps

  1. Fork https://github.com/dotnet/runtime/
  2. Open https://claude.ai/code
  3. Choose "runtime" and type "run the tests" and choose "Full Internet" as the environment then press enter

Expected behavior

The tests run

Actual behavior

NuGet won't download

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions