Skip to content

Commit 207767a

Browse files
committed
#15 - Validate ping frame size limits.
1 parent 4a5dbcc commit 207767a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/Microsoft.AspNet.WebSockets.Protocol/CommonWebSocket.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ private async Task ReadNextFrameAsync(CancellationToken cancellationToken)
299299

300300
if (_frameInProgress.OpCode == Constants.OpCodes.PingFrame || _frameInProgress.OpCode == Constants.OpCodes.PongFrame)
301301
{
302+
if (_frameBytesRemaining > 125)
303+
{
304+
if (State == WebSocketState.Open)
305+
{
306+
await CloseOutputAsync(WebSocketCloseStatus.ProtocolError, "Invalid control frame size", cancellationToken);
307+
Abort();
308+
}
309+
throw new InvalidOperationException("Control frame too large."); // TODO: WebSocketException
310+
}
302311
// Drain it, should be less than 125 bytes
303312
await EnsureDataAvailableOrReadAsync((int)_frameBytesRemaining, cancellationToken);
304313

0 commit comments

Comments
 (0)