Skip to content

Fix/http proxy auth#4259

Open
hugeagi wants to merge 113 commits into
SagerNet:testingfrom
hugeagi:fix/http-proxy-auth
Open

Fix/http proxy auth#4259
hugeagi wants to merge 113 commits into
SagerNet:testingfrom
hugeagi:fix/http-proxy-auth

Conversation

@hugeagi

@hugeagi hugeagi commented Jun 30, 2026

Copy link
Copy Markdown

Bugs Fixed

  1. HTTP 407 challenge flow closed connection too early
  • Impact: clients using challenge auth (no initial Proxy-Authorization) could receive 407 but then lose the same TCP connection before sending a second authenticated request.
  • Fixed in:
    • protocol/http/inbound.go
    • protocol/mixed/inbound.go
  • Behavior now:
    • Retry only when error is exactly http: authentication failed, no Proxy-Authorization header.
    • Retry only once.
    • Keep connection open for a bounded wait window, then timeout.
    • Clear read deadline after the one retry attempt.
  1. Tests could hide a failure path (silent early return)
  • Impact: in two auth-retry tests, a write failure could return early and skip assertions.
  • Fixed in:
    • test/http_test.go
  • Behavior now:
    • write errors are asserted with require.NoError, so failures are explicit.

How To Reproduce (Before Fix)

  1. Challenge auth via proxy (expected to fail pre-fix due to connection closure):
curl --proxy https://<host>:443 --proxy-anyauth --proxy-user '<user>:<pass>' https://www.google.com -v
  1. Preemptive auth (often succeeds even when challenge path is broken):
curl --proxy https://<host>:443 --proxy-user '<user>:<pass>' https://www.google.com -v

How To Verify Fixed

  1. Run focused HTTP auth regression tests from test module:
cd test
go test -v -tags "$(cat ../release/DEFAULT_BUILD_TAGS_OTHERS)" -run 'TestHTTPProxyAuthRetryAfter407|TestHTTPProxyAuthRetryOnlyOnce|TestHTTPProxyAuthRetryTimeout' .
  1. Expected:
  • TestHTTPProxyAuthRetryAfter407: first CONNECT gets 407, second CONNECT on same socket with valid auth gets 200.
  • TestHTTPProxyAuthRetryOnlyOnce: second unauthenticated retry still 407, third authenticated attempt after retry budget is exhausted does not proceed on same connection.
  • TestHTTPProxyAuthRetryTimeout: authenticated attempt after timeout window fails as expected.

Notes

  • Preemptive-only success is not sufficient proof; challenge flow behavior is the regression target.

nekohasekai and others added 30 commits June 20, 2026 22:23
The URL test history update hook and the Clash mode update hook were
single-slot: the API service's attached service overwrote the hook set
by the daemon, so clients stopped receiving group updates. Replace both
with multicast hook lists.

Also share a single URL test history storage via context: Clash API
looked it up under a key nobody registered and fell back to its own
empty storage, so dashboards showed no delay once an API service was
configured. Selector changes now notify through the shared storage,
covering selections made from any API surface.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants