Skip to content

Limit proxy CONNECT auth retries without Connection: close#9538

Open
kamilkrzywanski wants to merge 1 commit into
lysine-dev:masterfrom
kamilkrzywanski:fix/proxy-tunnel-auth-infinite-loop
Open

Limit proxy CONNECT auth retries without Connection: close#9538
kamilkrzywanski wants to merge 1 commit into
lysine-dev:masterfrom
kamilkrzywanski:fix/proxy-tunnel-auth-infinite-loop

Conversation

@kamilkrzywanski

@kamilkrzywanski kamilkrzywanski commented Jul 12, 2026

Copy link
Copy Markdown

Summary

  • Fixes an infinite loop in ConnectPlan.createTunnel() when an HTTP proxy repeatedly responds with 407 Proxy Authentication Required without Connection: close (#9477).
  • Keep-alive proxy auth retries now share the existing MAX_TUNNEL_ATTEMPTS (21) budget already used for reconnects after Connection: close.
  • After the limit is exceeded, OkHttp fails with ProtocolException("Too many tunnel connections attempted: 21") instead of looping forever.

Background

createTunnel() only exited a while (true) loop when the proxy closed the connection, the authenticator returned null, or I/O failed. Unlike RetryAndFollowUpInterceptor (MAX_FOLLOW_UPS = 20) and the reconnect path (MAX_TUNNEL_ATTEMPTS = 21), keep-alive 407 handling had no iteration counter.

Approach

Reuse MAX_TUNNEL_ATTEMPTS and seed the counter from the plan's existing attempt field so keep-alive retries and Connection: close reconnects share one budget (mixed cases cannot exceed 21 total either).

Test plan

  • CallTest.tooManyProxyAuthFailuresWithoutConnectionClose — reproducer for Infinite Authentication Loop in Proxy CONNECT Tunnel in OkHttp #9477 (21 keep-alive 407s → ProtocolException)
  • CallTest.proxyAuthenticateOnConnectSucceedsAfterManyChallenges — 20 challenges then success still works
  • CallTest.tooManyProxyAuthFailuresWithConnectionClose — asserts the shared error message
  • Existing proxyAuthenticateOnConnect / proxyAuthenticateOnConnectWithConnectionClose still pass

Closes #9477

A malicious or misconfigured HTTP proxy could trap createTunnel() in an
infinite loop by repeatedly responding 407 without Connection: close.
Keep-alive retries now share the existing MAX_TUNNEL_ATTEMPTS budget
with reconnects after Connection: close.

Fixes lysine-dev#9477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Infinite Authentication Loop in Proxy CONNECT Tunnel in OkHttp

1 participant