New issue
Advanced search Search tips

Issue 688244 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Feb 2017
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



Sign in to add a comment

WebSocket Accept does not terminate base64 reading on \r\n

Reported by welfordm...@gmail.com, Feb 3 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36

Steps to reproduce the problem:
1. Setup a Web Socket Server with the headers that send "Sec-WebSocket-Accept: {base64}\r\n"
2. Try to connect use using web browser
3. 

What is the expected behavior?
Browser should allow the connection 

What went wrong?
WebSocket connection to 'ws://127.0.0.1:8080/chat' failed: Unrecognized frame opcode: 13

Did this work before? N/A 

Chrome version: 56.0.2924.76  Channel: n/a
OS Version: 10.0
Flash Version: Shockwave Flash 24.0 r0

C# code i used to create the problem:
TcpClient client = this.TCPServer.AcceptTcpClient();
Thread thread = new Thread(delegate () { HandleConnection(client); });
thread.Start();

public void HandleConnection(TcpClient client)
{
    Console.WriteLine("Connection Establised from: " + ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString());
    // sets two streams
    StreamWriter sWriter = new StreamWriter(client.GetStream(), Encoding.UTF8);
    StreamReader sReader = new StreamReader(client.GetStream(), Encoding.UTF8);
    // you could use the NetworkStream to read and write, 
    // but there is no forcing flush, even when requested
    Boolean bClientConnected = true;
    String sData = null;
    bool gotHeaders = false;
    string headerBlock = "";
    while (!gotHeaders)
    {
        sData = sReader.ReadLine();
        headerBlock += sData + "\r\n";
        Console.WriteLine("Client << " + sData);
        if (headerBlock.Substring(headerBlock.Length - 4, 4) == "\r\n\r\n")
           {
               gotHeaders = true;
            }
        }
        string headerResponse = "HTTP/1.1 101 Switching Protocols\r\n"
        + "Connection: Upgrade\r\n"
        + "Upgrade: websocket\r\n"
        + "Sec-WebSocket-Accept: " + Convert.ToBase64String(
            SHA1.Create().ComputeHash(
               Encoding.UTF8.GetBytes(
                    new Regex("Sec-WebSocket-Key: (.*)").Match(headerBlock).Groups[1].Value.Trim() + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
                )
            )
        ) + "\r\n\";
        sWriter.WriteLine(headerResponse);
        sWriter.Flush();
    }
}

To fixed i had to change to 
+ "Sec-WebSocket-Accept: " + Convert.ToBase64String(
   SHA1.Create().ComputeHash(
       Encoding.UTF8.GetBytes(
           new Regex("Sec-WebSocket-Key: (.*)").Match(headerBlock).Groups[1].Value.Trim() + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
       )
   )
) + " \r\n\";

 
Components: -Blink Blink>Network>WebSockets
Sorry just noticed the C# code is slightly wrong the while(!gotHeders) should be closed before the string headerResponce = ...

Owner: yhirano@chromium.org
Could you provide a net-internals log[1] for the failure case?

1: https://dev.chromium.org/for-testers/providing-network-details
Labels: Needs-Feedback
Ok this appears to be fixed in an update yesterday, 56.0.2924.87 (Official Build) (64-bit) as the same code that was not working is now working.
Labels: -Needs-Feedback
Status: WontFix (was: Unconfirmed)

Sign in to add a comment