fix: skip http2 fallback when explicitly disabled#530
Closed
khs-alt wants to merge 2 commits intoprojectdiscovery:mainfrom
Closed
fix: skip http2 fallback when explicitly disabled#530khs-alt wants to merge 2 commits intoprojectdiscovery:mainfrom
khs-alt wants to merge 2 commits intoprojectdiscovery:mainfrom
Conversation
Neo - PR Security ReviewNo security issues found Highlights
Hardening Notes
Comment |
Member
|
The underlying issue (httpx#2240) has been resolved at the httpx level — the HTTP/1.1 protocol preference is now correctly enforced without requiring changes to retryablehttp-go. Closing as the original bounty issue is already complete. Thanks for the contribution. |
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.
fix httpx #2240
Description
When a caller disables HTTP/2 (e.g., httpx
-pr http11setsTLSNextPrototo an empty map), retryablehttp-go still falls back toHTTPClient2on malformed HTTP/2 errors, silently switching protocols.See my comment on the issue for detailed root cause analysis.
Changes
DialTLSContext = nilon HTTPClient2 (client.go):Clears inherited
DialTLSContextsohttp2.ConfigureTransportcannegotiate
h2via ALPN properly.isHTTP2Disabled()→HTTPClient2 = nil(client.go):Detects when caller's transport has HTTP/2 disabled (non-nil empty
TLSNextProto— Go standard convention) and skips creating HTTPClient2.Nil guard on fallback (do.go):
Added
c.HTTPClient2 != nilcheck before HTTP/2 fallback, so disabledconfigs go through normal retry policy instead.
Before
Default — HTTPClient2 fallback fires but fails (no h2 ALPN), request sent twice:
run
go run ./cmd/httpx -u https://localhost:8443/malformed-version-pr http11— fallback still fires despite HTTP/1.1-only config, request sent twice:run
go run ./cmd/httpx -pr http11 -u https://localhost:8443/malformed-versionAfter
Default — HTTPClient2 fallback works correctly via h2 ALPN:
run
go run ./cmd/httpx -u https://localhost:8443/malformed-version-pr http11— no fallback, single request as expected:run
go run ./cmd/httpx -pr http11 -u https://localhost:8443/malformed-versionFull server logs
Before
run
go run ./cmd/httpx -u https://localhost:8443/malformed-versionrun
go run ./cmd/httpx -pr http11 -u https://localhost:8443/malformed-versionAfter
run
go run ./cmd/httpx -u https://localhost:8443/malformed-versionrun
go run ./cmd/httpx -pr http11 -u https://localhost:8443/malformed-version