[net] http2: prevent processing DATA before HEADERS

200 views
Skip to first unread message

Michael Fraenkel (Gerrit)

unread,
Jun 23, 2021, 11:55:21 PM6/23/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Michael Fraenkel has uploaded this change for review.

View Change

http2: prevent processing DATA before HEADERS

DATA frames must only be processed after all HEADER frames have been
processed first.

Fixes golang/go#43965

Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
---
M http2/transport.go
M http2/transport_test.go
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/http2/transport.go b/http2/transport.go
index b97adff..c746f2f 100644
--- a/http2/transport.go
+++ b/http2/transport.go
@@ -2220,7 +2220,7 @@
}
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,
diff --git a/http2/transport_test.go b/http2/transport_test.go
index 750813b..ed6cc31 100644
--- a/http2/transport_test.go
+++ b/http2/transport_test.go
@@ -3787,6 +3787,14 @@
if err, ok := err.(StreamError); !ok || err.Code != ErrCodeProtocol {
return fmt.Errorf("expected stream PROTOCOL_ERROR, got: %v", err)
}
+ // Third request returns a DATA frame after HEADERS with a 100 status code.
+ resp, err = ct.tr.RoundTrip(req)
+ if err == nil {
+ return fmt.Errorf("RoundTrip expected error, got response: %+v", resp)
+ }
+ if err, ok := err.(StreamError); !ok || err.Code != ErrCodeProtocol {
+ return fmt.Errorf("expected stream PROTOCOL_ERROR, got: %v", err)
+ }
return nil
}
ct.server = func() error {
@@ -3815,6 +3823,17 @@
})
case 3:
ct.fr.WriteData(f.StreamID, true, []byte("payload"))
+ case 5:
+ // Send a 100 continue followed by DATA
+ var buf bytes.Buffer
+ enc := hpack.NewEncoder(&buf)
+ enc.WriteField(hpack.HeaderField{Name: ":status", Value: "100"})
+ ct.fr.WriteHeaders(HeadersFrameParam{
+ StreamID: f.StreamID,
+ EndHeaders: true,
+ BlockFragment: buf.Bytes(),
+ })
+ ct.fr.WriteData(f.StreamID, true, []byte("payload"))
}
default:
return fmt.Errorf("Unexpected client frame %v", f)

To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: net
Gerrit-Branch: master
Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
Gerrit-Change-Number: 330415
Gerrit-PatchSet: 1
Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
Gerrit-MessageType: newchange

Damien Neil (Gerrit)

unread,
Jun 28, 2021, 4:41:37 PM6/28/21
to Michael Fraenkel, goph...@pubsubhelper.golang.org, Tom Bergan, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: Tom Bergan, Michael Fraenkel.

Patch set 1:Code-Review +2

View Change

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 1
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Comment-Date: Mon, 28 Jun 2021 20:41:34 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Dmitri Shuralyov (Gerrit)

    unread,
    Jun 28, 2021, 6:49:25 PM6/28/21
    to Michael Fraenkel, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Damien Neil, Tom Bergan, Go Bot, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan, Michael Fraenkel.

    Patch set 1:Run-TryBot +1Trust +1

    View Change

    1 comment:

    • Commit Message:

      • Patch Set #1, Line 12: Fixes golang/go#43965

        That issue is currently for the net/http package in the main Go repo, but this CL is for the x/net repo.

        If this is merged as is, that issue will need to be re-opened to track this x/net/http2 fix being vendored (or bundled) into net/http. Alternatively, you can replace "Fixes" with "For", or create a new issue for x/net/http2 specifically.

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 1
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-CC: Go Bot <go...@golang.org>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Comment-Date: Mon, 28 Jun 2021 22:49:21 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Michael Fraenkel (Gerrit)

    unread,
    Jun 28, 2021, 9:53:15 PM6/28/21
    to goph...@pubsubhelper.golang.org, Go Bot, Dmitri Shuralyov, Damien Neil, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan, Dmitri Shuralyov.

    View Change

    1 comment:

    • Commit Message:

      • That issue is currently for the net/http package in the main Go repo, but this CL is for the x/net r […]

        Is there a plan to refresh the http2 bundle for 1.17 before its released?

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 1
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Comment-Date: Tue, 29 Jun 2021 01:53:12 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-MessageType: comment

    Michael Fraenkel (Gerrit)

    unread,
    Jun 28, 2021, 9:54:10 PM6/28/21
    to goph...@pubsubhelper.golang.org, Go Bot, Dmitri Shuralyov, Damien Neil, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan, Dmitri Shuralyov.

    View Change

    1 comment:

    • Commit Message:

      • Is there a plan to refresh the http2 bundle for 1. […]

        Ack

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 1
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Comment-Date: Tue, 29 Jun 2021 01:54:07 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Dmitri Shuralyov <dmit...@golang.org>
    Comment-In-Reply-To: Michael Fraenkel <michael....@gmail.com>
    Gerrit-MessageType: comment

    Michael Fraenkel (Gerrit)

    unread,
    Jun 28, 2021, 9:56:27 PM6/28/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan, Dmitri Shuralyov.

    Michael Fraenkel uploaded patch set #2 to this change.

    View Change

    http2: prevent processing DATA before HEADERS

    DATA frames must only be processed after all HEADER frames have been
    processed first.

    For golang/go#43965


    Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    ---
    M http2/transport.go
    M http2/transport_test.go
    2 files changed, 20 insertions(+), 1 deletion(-)

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 2
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-MessageType: newpatchset

    Dmitri Shuralyov (Gerrit)

    unread,
    Jun 28, 2021, 11:13:07 PM6/28/21
    to Michael Fraenkel, goph...@pubsubhelper.golang.org, Go Bot, Dmitri Shuralyov, Damien Neil, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan, Michael Fraenkel.

    Patch set 2:Trust +1

    View Change

    1 comment:

    • Commit Message:

      • Ack

        If the net/http issue fix is intended for 1.17, the Go repo will need to be updated after this is submitted. If it’s meant for 1.18, this should wait until the 1.17 is out and its code freeze is over. (The code freeze applies to the main repo and all packages that are vendored/bundled into it.)

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 2
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Comment-Date: Tue, 29 Jun 2021 03:13:03 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes

    Michael Fraenkel (Gerrit)

    unread,
    Aug 18, 2021, 10:21:06 PM8/18/21
    to goph...@pubsubhelper.golang.org, Go Bot, Dmitri Shuralyov, Damien Neil, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan.

    View Change

    1 comment:

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 2
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Comment-Date: Thu, 19 Aug 2021 02:21:02 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    Michael Fraenkel (Gerrit)

    unread,
    Oct 29, 2021, 9:32:24 AM10/29/21
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Tom Bergan.

    Michael Fraenkel uploaded patch set #3 to this change.

    View Change

    http2: prevent processing DATA before HEADERS

    DATA frames must only be processed after all HEADER frames have been
    processed first.

    For golang/go#43965

    Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    ---
    M http2/transport_test.go
    M http2/transport.go
    2 files changed, 34 insertions(+), 1 deletion(-)

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 3
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Go Bot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-MessageType: newpatchset

    Damien Neil (Gerrit)

    unread,
    Jan 26, 2023, 2:07:38 PM1/26/23
    to Michael Fraenkel, goph...@pubsubhelper.golang.org, Gopher Robot, Dmitri Shuralyov, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Michael Fraenkel, Tom Bergan.

    Patch set 3:Run-TryBot +1Code-Review +2

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        I'm not sure what happened to this CL. It had a positive trybot result and sufficient plusses at some point in the past, but now it's missing the trybot result and I think we changed the way trust labels work.

        Sorry for letting this fall through the cracks.

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 3
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Comment-Date: Thu, 26 Jan 2023 19:07:33 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Damien Neil (Gerrit)

    unread,
    Jan 26, 2023, 2:12:28 PM1/26/23
    to Michael Fraenkel, goph...@pubsubhelper.golang.org, Gopher Robot, Dmitri Shuralyov, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Michael Fraenkel, Tom Bergan.

    View Change

    1 comment:

    • Patchset:

      • Patch Set #3:

        11 of 11 TryBots failed. […]

        Looks like this needs to be resynced.

    To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: net
    Gerrit-Branch: master
    Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
    Gerrit-Change-Number: 330415
    Gerrit-PatchSet: 3
    Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Tom Bergan <tomb...@google.com>
    Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
    Gerrit-Comment-Date: Thu, 26 Jan 2023 19:12:23 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Gopher Robot <go...@golang.org>
    Gerrit-MessageType: comment

    Dmitri Shuralyov (Gerrit)

    unread,
    Jan 26, 2023, 2:18:55 PM1/26/23
    to Michael Fraenkel, goph...@pubsubhelper.golang.org, Gopher Robot, Damien Neil, Dmitri Shuralyov, Tom Bergan, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil, Michael Fraenkel, Tom Bergan.

    Patch set 3:Code-Review +1

    View Change

      To view, visit change 330415. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: net
      Gerrit-Branch: master
      Gerrit-Change-Id: I1607c713cc766c6e48c9abca8ca1671cf0575167
      Gerrit-Change-Number: 330415
      Gerrit-PatchSet: 3
      Gerrit-Owner: Michael Fraenkel <michael....@gmail.com>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: Dmitri Shuralyov <dmit...@golang.org>
      Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Tom Bergan <tomb...@google.com>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Attention: Tom Bergan <tomb...@google.com>
      Gerrit-Attention: Michael Fraenkel <michael....@gmail.com>
      Gerrit-Comment-Date: Thu, 26 Jan 2023 19:18:51 +0000
      Reply all
      Reply to author
      Forward
      0 new messages