HTTP/2: close connection on PING frame with non-zero stream ID.

This commit is contained in:
Cesar Blum Silveira 2017-09-20 18:40:19 -07:00 committed by Cesar Blum Silveira
parent 555a881cb7
commit fc56552b2a
2 changed files with 25 additions and 0 deletions

View File

@ -386,6 +386,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR);
}
if (_incomingFrame.StreamId != 0)
{
throw new Http2ConnectionErrorException(Http2ErrorCode.PROTOCOL_ERROR);
}
if (_incomingFrame.Length != 8)
{
throw new Http2ConnectionErrorException(Http2ErrorCode.FRAME_SIZE_ERROR);

View File

@ -887,6 +887,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false);
}
[Fact]
public async Task PING_Received_StreamIdNotZero_ConnectionError()
{
await InitializeConnectionAsync(_noopApplication);
await SendPingWithInvalidStreamIdAsync(streamId: 1);
await WaitForConnectionErrorAsync(expectedLastStreamId: 0, expectedErrorCode: Http2ErrorCode.PROTOCOL_ERROR, ignoreNonGoAwayFrames: false);
}
[Theory]
[InlineData(0)]
[InlineData(1)]
@ -1427,6 +1437,16 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
return SendAsync(pingFrame.Raw);
}
private Task SendPingWithInvalidStreamIdAsync(int streamId)
{
Assert.NotEqual(0, streamId);
var pingFrame = new Http2Frame();
pingFrame.PreparePing(Http2PingFrameFlags.NONE);
pingFrame.StreamId = streamId;
return SendAsync(pingFrame.Raw);
}
private Task SendPriorityAsync(int streamId)
{
var priorityFrame = new Http2Frame();