Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for websocket server reading Sec-WebSocket-Key in wrong place when missing, and handling common mistakes from clients #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions FishNet/Plugins/Bayou/SimpleWebTransport/Server/ServerHandshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ void AcceptHandshake(Stream stream, string msg)
}


static void GetKey(string msg, byte[] keyBuffer)
static void GetKey(string msg, byte[] keyBuffer)
{
int start = msg.IndexOf(KeyHeaderString) + KeyHeaderString.Length;
// really should be parsing http headers properly here, and then finding required header,
// as this string could be crammed in anywhere in the message
// but as a hack, for https://github.com/FirstGearGames/Bayou/issues/12
// search for the key case insensitively
var KeyIndex = msg.IndexOf(KeyHeaderString,StringComparison.InvariantCultureIgnoreCase);
if ( KeyIndex <= -1 )
throw new Exception($"Request missing required header {KeyHeaderString}");

int start = KeyIndex + KeyHeaderString.Length;

Log.Verbose($"Handshake Key: {msg.Substring(start, KeyLength)}");
Encoding.ASCII.GetBytes(msg, start, KeyLength, keyBuffer, 0);
Expand Down