From e2af346733ea903a8df6f0ffc545c60ddf9a2eb3 Mon Sep 17 00:00:00 2001 From: Cesar Blum Silveira Date: Thu, 21 Sep 2017 09:38:20 -0700 Subject: [PATCH] HTTP/2: close the connection with PROTOCOL_ERROR when a PUSH_PROMISE frame is received. --- .../Internal/Http2/Http2Connection.cs | 2 ++ .../Http2ConnectionTests.cs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs index 5796b73a91..ae2b7d5bed 100644 --- a/src/Kestrel.Core/Internal/Http2/Http2Connection.cs +++ b/src/Kestrel.Core/Internal/Http2/Http2Connection.cs @@ -208,6 +208,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2 return ProcessRstStreamFrameAsync(); case Http2FrameType.SETTINGS: return ProcessSettingsFrameAsync(); + case Http2FrameType.PUSH_PROMISE: + throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); case Http2FrameType.PING: return ProcessPingFrameAsync(); case Http2FrameType.GOAWAY: diff --git a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs index 56f2787b83..56bd6f3b31 100644 --- a/test/Kestrel.Core.Tests/Http2ConnectionTests.cs +++ b/test/Kestrel.Core.Tests/Http2ConnectionTests.cs @@ -852,6 +852,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.FRAME_SIZE_ERROR, ignoreNonGoAwayFrames: false); } + [Fact] + public async Task PUSH_PROMISE_Received_ConnectionError() + { + await InitializeConnectionAsync(_noopApplication); + + await SendPushPromiseFrameAsync(); + + await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false); + } + [Fact] public async Task PING_Received_Sends_ACK() { @@ -1280,6 +1290,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests return SendAsync(frame.Raw); } + private Task SendPushPromiseFrameAsync() + { + var frame = new Http2Frame(); + frame.Length = 0; + frame.Type = Http2FrameType.PUSH_PROMISE; + frame.StreamId = 1; + return SendAsync(frame.Raw); + } + private async Task SendHeadersAsync(int streamId, Http2HeadersFrameFlags flags, IEnumerable> headers) { var frame = new Http2Frame();