Limit proxy CONNECT auth retries without Connection: close#9538
Open
kamilkrzywanski wants to merge 1 commit into
Open
Limit proxy CONNECT auth retries without Connection: close#9538kamilkrzywanski wants to merge 1 commit into
kamilkrzywanski wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConnectPlan.createTunnel()when an HTTP proxy repeatedly responds with407 Proxy Authentication RequiredwithoutConnection: close(#9477).MAX_TUNNEL_ATTEMPTS(21) budget already used for reconnects afterConnection: close.ProtocolException("Too many tunnel connections attempted: 21")instead of looping forever.Background
createTunnel()only exited awhile (true)loop when the proxy closed the connection, the authenticator returned null, or I/O failed. UnlikeRetryAndFollowUpInterceptor(MAX_FOLLOW_UPS = 20) and the reconnect path (MAX_TUNNEL_ATTEMPTS = 21), keep-alive 407 handling had no iteration counter.Approach
Reuse
MAX_TUNNEL_ATTEMPTSand seed the counter from the plan's existingattemptfield so keep-alive retries andConnection: closereconnects 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 worksCallTest.tooManyProxyAuthFailuresWithConnectionClose— asserts the shared error messageproxyAuthenticateOnConnect/proxyAuthenticateOnConnectWithConnectionClosestill passCloses #9477