From 207767a9b0878ea90690fc5ca28d3d531d104c18 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Wed, 22 Oct 2014 16:25:22 -0700 Subject: [PATCH] #15 - Validate ping frame size limits. --- .../CommonWebSocket.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Microsoft.AspNet.WebSockets.Protocol/CommonWebSocket.cs b/src/Microsoft.AspNet.WebSockets.Protocol/CommonWebSocket.cs index 191d436157..32b39389bd 100644 --- a/src/Microsoft.AspNet.WebSockets.Protocol/CommonWebSocket.cs +++ b/src/Microsoft.AspNet.WebSockets.Protocol/CommonWebSocket.cs @@ -299,6 +299,15 @@ namespace Microsoft.AspNet.WebSockets.Protocol if (_frameInProgress.OpCode == Constants.OpCodes.PingFrame || _frameInProgress.OpCode == Constants.OpCodes.PongFrame) { + if (_frameBytesRemaining > 125) + { + if (State == WebSocketState.Open) + { + await CloseOutputAsync(WebSocketCloseStatus.ProtocolError, "Invalid control frame size", cancellationToken); + Abort(); + } + throw new InvalidOperationException("Control frame too large."); // TODO: WebSocketException + } // Drain it, should be less than 125 bytes await EnsureDataAvailableOrReadAsync((int)_frameBytesRemaining, cancellationToken);