HTTP/2: close connection with PROTOCOL_ERROR when receiving GOAWAY frame with non-zero stream ID.

This commit is contained in:
Cesar Blum Silveira 2017-09-21 10:29:43 -07:00 committed by Cesar Blum Silveira
parent fc56552b2a
commit a4887f4caf
2 changed files with 23 additions and 0 deletions

View File

@ -406,6 +406,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR); throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR);
} }
if (_incomingFrame.StreamId != 0)
{
throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR);
}
Stop(); Stop();
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -941,6 +941,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
Assert.Contains(5, _abortedStreamIds); Assert.Contains(5, _abortedStreamIds);
} }
[Fact]
public async Task GOAWAY_Received_StreamIdNonZero_ConnectionError()
{
await InitializeConnectionAsync(_noopApplication);
await SendInvalidGoAwayFrameAsync();
await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false);
}
[Fact] [Fact]
public async Task GOAWAY_Received_InterleavedWithHeaders_ConnectionError() public async Task GOAWAY_Received_InterleavedWithHeaders_ConnectionError()
{ {
@ -1484,6 +1494,14 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
return SendAsync(frame.Raw); return SendAsync(frame.Raw);
} }
private Task SendInvalidGoAwayFrameAsync()
{
var frame = new Http2Frame();
frame.PrepareGoAway(0, Http2ErrorCode.NO_ERROR);
frame.StreamId = 1;
return SendAsync(frame.Raw);
}
private Task SendWindowUpdateAsync(int streamId, int sizeIncrement) private Task SendWindowUpdateAsync(int streamId, int sizeIncrement)
{ {
var frame = new Http2Frame(); var frame = new Http2Frame();