proxy/http: fix panic in readResponseAndHandle100Continue on malformed upstream response - #6545
Open
younesvatan78 wants to merge 1 commit into
Open
proxy/http: fix panic in readResponseAndHandle100Continue on malformed upstream response#6545younesvatan78 wants to merge 1 commit into
younesvatan78 wants to merge 1 commit into
Conversation
Member
|
Rebase |
…d upstream response ResponseHeader1xx[len(ResponseHeader1xx)-4:] was sliced with no check that at least 4 bytes had been accumulated. A malformed upstream response containing a bare '\n' before the real status line (e.g. sniffed as 1xx from the initial 56-byte peek, but with the actual first line break arriving after only 1-3 bytes) makes len(ResponseHeader1xx)-4 negative, causing: panic: runtime error: slice bounds out of range [-2:] This runs in a per-connection goroutine with no recover() in the call chain, so any target HTTP server reached through the HTTP inbound's plain-HTTP path can crash the entire process, not just its own connection. Guard the slice with a length check, and add regression tests: one reproducing the crash on unpatched code, and one confirming legitimate 1xx forwarding still parses the final response correctly.
younesvatan78
force-pushed
the
fix-http-1xx-panic
branch
from
July 27, 2026 15:46
f70b157 to
997ef7e
Compare
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.
Bug
readResponseAndHandle100Continue(HTTP inbound, plain-HTTP path) accumulates the upstream's 1xx response header intoResponseHeader1xxand checks for the end of headers with:There's no check that at least 4 bytes have been accumulated yet.
ResponseHeader1xxis filled oner.ReadSlice('\n')result at a time, and if the upstream response contains a bare\nbefore the real status line, the firstReadSlice('\n')can return only 1-3 bytes.len(ResponseHeader1xx)-4then goes negative and the slice panics:Minimal trigger, reproduced with a unit test (included in this PR): an upstream response body of
The leading
X\ngets picked up byr.ReadSlice('\n')as a 2-byte first read (since bufio's read position hasn't advanced past the earlierPeek(56)), while the 56-byte peek used to detect "is this a 1xx response" sees"...Continue\r\n..."and classifies it as 1xx based on the next line — so the 1xx-forwarding loop is entered, then panics on the first iteration.This connection handler runs in a per-connection goroutine with no
recover()anywhere in the call chain (app/proxyman/inbound→proxy/http), so the panic terminates the whole process, not just the one connection. Any HTTP target reached through the HTTP inbound's plain-HTTP mode that returns a response shaped like this brings down the entire server for all users on it.Fix
Guard the slice with a length check before comparing:
Test plan
Added
proxy/http/server_test.go(this package previously had no tests):TestReadResponseAndHandle100ContinueDoesNotPanicOnEarlyNewline— reproduces the crash above. Confirmed it panics against the unpatched code and passes with the fix.TestReadResponseAndHandle100ContinueForwardsAndParsesFinalResponse— sanity check that legitimate 1xx forwarding is unaffected: a real100 Continuefollowed by a200 OKis still forwarded and parsed correctly.