Skip to content

Commit 695e38b

Browse files
addaleaxtargos
authored andcommitted
http2: consider 0-length non-end DATA frames an error
This is intended to mitigate CVE-2019-9518. PR-URL: #29122 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b2c7c51 commit 695e38b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/node_http2.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,7 @@ int Http2Session::OnFrameReceive(nghttp2_session* handle,
979979
frame->hd.type);
980980
switch (frame->hd.type) {
981981
case NGHTTP2_DATA:
982-
session->HandleDataFrame(frame);
983-
break;
982+
return session->HandleDataFrame(frame);
984983
case NGHTTP2_PUSH_PROMISE:
985984
// Intentional fall-through, handled just like headers frames
986985
case NGHTTP2_HEADERS:
@@ -1372,13 +1371,18 @@ void Http2Session::HandlePriorityFrame(const nghttp2_frame* frame) {
13721371
// Called by OnFrameReceived when a complete DATA frame has been received.
13731372
// If we know that this was the last DATA frame (because the END_STREAM flag
13741373
// is set), then we'll terminate the readable side of the StreamBase.
1375-
void Http2Session::HandleDataFrame(const nghttp2_frame* frame) {
1374+
int Http2Session::HandleDataFrame(const nghttp2_frame* frame) {
13761375
int32_t id = GetFrameID(frame);
13771376
Debug(this, "handling data frame for stream %d", id);
13781377
Http2Stream* stream = FindStream(id);
13791378

1380-
if (!stream->IsDestroyed() && frame->hd.flags & NGHTTP2_FLAG_END_STREAM)
1379+
if (!stream->IsDestroyed() && frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
13811380
stream->EmitRead(UV_EOF);
1381+
} else if (frame->hd.length == 0 &&
1382+
!IsReverted(SECURITY_REVERT_CVE_2019_9518)) {
1383+
return 1; // Consider 0-length frame without END_STREAM an error.
1384+
}
1385+
return 0;
13821386
}
13831387

13841388

src/node_http2.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ class Http2Session : public AsyncWrap, public StreamListener {
877877
size_t maxPayloadLen);
878878

879879
// Frame Handler
880-
void HandleDataFrame(const nghttp2_frame* frame);
880+
int HandleDataFrame(const nghttp2_frame* frame);
881881
void HandleGoawayFrame(const nghttp2_frame* frame);
882882
void HandleHeadersFrame(const nghttp2_frame* frame);
883883
void HandlePriorityFrame(const nghttp2_frame* frame);

src/node_revert.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace node {
1818
#define SECURITY_REVERSIONS(XX) \
1919
XX(CVE_2019_9514, "CVE-2019-9514", "HTTP/2 Reset Flood") \
2020
XX(CVE_2019_9516, "CVE-2019-9516", "HTTP/2 0-Length Headers Leak") \
21+
XX(CVE_2019_9518, "CVE-2019-9518", "HTTP/2 Empty DATA Frame Flooding") \
2122
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
2223
// TODO(addaleax): Remove all of the above before Node.js 13 as the comment
2324
// at the start of the file indicates.

0 commit comments

Comments
 (0)