fix: return 400 instead of 502 for a Host header with a non-numeric port - #1708
Open
RajeshRajendiran wants to merge 2 commits into
Open
fix: return 400 instead of 502 for a Host header with a non-numeric port#1708RajeshRajendiran wants to merge 2 commits into
RajeshRajendiran wants to merge 2 commits into
Conversation
connectRequest.Dest can carry the eyeball's Host header verbatim, so a port like ":aaaa" fails Go's URL parser inside http.NewRequestWithContext. That error was surfacing to the eyeball as a 502, which looks like an origin failure rather than a malformed client request. Wrap it in a distinguishable error type so handleDataStream can report it as 400.
errors.Is against a sentinel matches the existing cfdflow.ErrTooManyActiveFlows check right above it in handleDataStream, and needs less code than a custom struct type with hand-written Error()/Unwrap() methods.
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
ConnectRequest.Destcan carry the eyeball's Host header verbatim, so a request withHost: app.example.com:aaaaproduces aDestlikehttp://app.example.com:aaaa/....buildHTTPRequestpasses this straight intohttp.NewRequestWithContext, which fails Go's URL parser withinvalid port ":aaaa" after hostsince the port isn't numeric.dispatchRequest/handleDataStreamwith no distinguishing metadata, so it was reported to the eyeball as a bare error with the default 502 status — indistinguishable from a genuine origin/proxy failure, and misleading for anyone debugging the client-side issue.Fix
http.NewRequestWithContexterror in a newmalformedRequestErrortype when it fails to build the request fromDest.handleDataStream, detect this error type (same pattern already used forcfdflow.ErrTooManyActiveFlows) and attachHttpStatus: 400metadata so the eyeball gets a 400 instead of a 502.Test plan
TestBuildHTTPRequestMalformedDestverifying a Dest with a non-numeric port returnsmalformedRequestError.TestHTTPProxy_MalformedHostPort, an end-to-end QUIC test verifying the response metadata carriesHttpStatus: 400.go build ./...go vet ./connection/...go test -race -count=1 ./connection/...golangci-lint run ./connection/...-> 0 issuesFixes #1490