Skip to content

Commit

Permalink
http2: reject DATA frames after 1xx and before final headers
Browse files Browse the repository at this point in the history
When checking to see if a DATA frame can be accepted, check to
see if we have received a non-1xx header, not whether we have
received any header.

Fixes golang/go#65927

Change-Id: Id4fae1862de6179f8fc95e02dec7d4c47a7640e1
Reviewed-on: https://go-review.googlesource.com/c/net/+/567175
Reviewed-by: Jonathan Amsterdam <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
neild committed Mar 11, 2024
1 parent d600ae0 commit 12ddef7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion http2/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2787,7 +2787,7 @@ func (rl *clientConnReadLoop) processData(f *DataFrame) error {
})
return nil
}
if !cs.firstByte {
if !cs.pastHeaders {
cc.logf("protocol error: received DATA before a HEADERS frame")
rl.endStreamError(cs, StreamError{
StreamID: f.StreamID,
Expand Down
29 changes: 29 additions & 0 deletions http2/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6254,3 +6254,32 @@ func TestDialRaceResumesDial(t *testing.T) {
case <-successCh:
}
}

func TestTransportDataAfter1xxHeader(t *testing.T) {
// Discard logger output to avoid spamming stderr.
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stderr)

// https://go.dev/issue/65927 - server sends a 1xx response, followed by a DATA frame.
tc := newTestClientConn(t)
tc.greet()

req, _ := http.NewRequest("GET", "https://dummy.tld/", nil)
rt := tc.roundTrip(req)

tc.wantFrameType(FrameHeaders)
tc.writeHeaders(HeadersFrameParam{
StreamID: rt.streamID(),
EndHeaders: true,
EndStream: false,
BlockFragment: tc.makeHeaderBlockFragment(
":status", "100",
),
})
tc.writeData(rt.streamID(), true, []byte{0})
err := rt.err()
if err, ok := err.(StreamError); !ok || err.Code != ErrCodeProtocol {
t.Errorf("RoundTrip error: %v; want ErrCodeProtocol", err)
}
tc.wantFrameType(FrameRSTStream)
}

0 comments on commit 12ddef7

Please sign in to comment.