Subject: [hybi] CONNECT handshake text

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Tue, 7 Dec 2010 10:01:34 -0800

There's a lot of back and forth lately about a possible CONNECT handshake
and how it should look. I thought it might be helpful to send out some draft
text that is a somewhat minimal CONNECT handshake, without things like
JSON-encoded data and payload masking, as I think we may be getting
distracted by some of these things and I'm not sure they're actually
necessary or material.

Below is some text that I would like the group to consider for a CONNECT
handshake, as it would fit into the WebSockets protocol.

1.2.  Protocol overview

   _This section is non-normative._

   The protocol has two parts: a handshake, and then the data transfer.

   The handshake from the client looks as follows:

        CONNECT websocket.invalid:443 HTTP/1.1
        Host: websocket.invalid:443
        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
        Sec-WebSocket-Origin: http://example.com
        Sec-WebSocket-URL: ws://example.com/chat
        Sec-WebSocket-Protocol: chat, superchat

Fette                     Expires June 8, 2011                  [Page 5]
Internet-Draft           The WebSocket protocol            December 2010

        Sec-WebSocket-Draft: 4

   The handshake from the server looks as follows:

        HTTP/1.1 200 OK
        Sec-WebSocket-Accept: me89jWimTRKTWwrS3aRrL53YZSo=
        Sec-WebSocket-Protocol: chat

   The leading line from the client follows the Request-Line format.
   The leading line from the server follows the Status-Line format.  The
   Request-Line and Status-Line productions are defined in [RFC2616].

   After the leading line in both cases come an unordered set of
   headers.  The meaning of these headers is specified in Section 5 of
   this document.  Additional headers may also be present, such as
   cookies required to identify the user.  The format and parsing of
   headers is as defined in [RFC2616].

   Once the client and server have both sent their handshakes, and if
   the handshake was successful, then the data transfer part starts.
   This is a two-way communication channel where each side can,
   independently from the other, send data at will.

   Clients and servers, after a successful handshake, transfer data back
   and forth in conceptual units referred to in this specification as
   "messages".  A message is a complete unit of data at an application
   level, with the expectation that many or most applications
   implementing this protocol (such as web user agents) provide APIs in
   terms of sending and receiving messages.  The websocket message does
   not necessarily correspond to a particular network layer framing, as
   a fragmented message may be coalesced, or vice versa, e.g. by an
   intermediary.

   Data is sent on the wire in the form of frames that have an
   associated type.  Broadly speaking, there are types for textual data,
   which is interpreted as UTF-8 text, binary data (whose interpretation
   is left up to the application), and control frames, which are not
   intended to carry data for the application, but instead for protocol-
   level signaling, such as to signal that the connection should be
   closed.  This version of the protocol defines six frame types and
   leaves ten reserved for future use.

   The WebSocket protocol uses this framing so that specifications that
   use the WebSocket protocol can expose such connections using an
   event-based mechanism instead of requiring users of those
   specifications to implement buffering and piecing together of

Fette                     Expires June 8, 2011                  [Page 6]
Internet-Draft           The WebSocket protocol            December 2010

   messages manually.

1.3.  Opening handshake

   _This section is non-normative._

   The opening handshake is intended to be compatible with HTTP-based
   server-side software and intermediaries, so that a single port can be
   used by both HTTP clients talking to that server and WebSocket
   clients talking to that server.  To this end, the WebSocket client's
   handshake appears to HTTP intermediaries or servers to be a regular
   CONNECT request:

        CONNECT websocket.invalid:443 HTTP/1.1
        Host: websocket.invalid:443
        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
        Sec-WebSocket-Origin: http://example.com
        Sec-WebSocket-URL: ws://example.com/chat
        Sec-WebSocket-Protocol: chat, superchat
        Sec-WebSocket-Draft: 4

   Headers in the handshake are sent by the client in a random order;
   the order is not meaningful.

   Additional headers are used to select options in the WebSocket
   protocol.  Options available in this version are the subprotocol
   selector, |Sec-WebSocket-Protocol|, and |Cookie|, which can used for
   sending cookies to the server (e.g. as an authentication mechanism).
   The |Sec-WebSocket-Protocol| request-header field can be used to
   indicate what subprotocols (application-level protocols layered over
   the WebSocket protocol) are acceptable to the client.  The server
   selects one of the acceptable protocols and echoes that value in its
   handshake to indicate that it has selected that protocol.

        Sec-WebSocket-Protocol: chat

   The |Sec-WebSocket-URL| header is used to identify the endpoint of
   the WebSocket connection, both to allow multiple domains to be served
   from one IP address and to allow multiple WebSocket endpoints to be
   served by a single server.

   The client includes the hostname as a part of the |Sec-WebSocket-URL|
   field of its handshake, so that both the client and the server can
   verify that they agree on which host is in use.

   The |Sec-WebSocket-Origin| header is used to protect against

Fette                     Expires June 8, 2011                  [Page 7]
Internet-Draft           The WebSocket protocol            December 2010

   unauthorized cross-origin use of a WebSocket server by scripts using
   the |WebSocket| API in a Web browser.  The server is informed of the
   script origin generating the WebSocket connection request.  If the
   server does not wish to accept connections from this origin, it can
   choose to abort the connection.

   Finally, the server has to prove to the client that it received the
   client's WebSocket handshake, so that the server doesn't accept
   connections that are not WebSocket connections.  This prevents an
   attacker from tricking a WebSocket server by sending it carefully-
   crafted packets using |XMLHttpRequest| or a |form| submission.

   To prove that the handshake was received, the server has to take two
   pieces of information and combine them to form a response.  The first
   piece of information comes from the |Sec-WebSocket-Key| header in the
   client handshake:

        Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

   For this header, the server has to take the value (as present in the
   header, e.g. the base64-encoded version), and concatenate this with
   the GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" in string form, which
   is unlikely to be used by network endpoints that do not understand
   the WebSocket protocol.  A SHA-1 hash, base64-encoded, of this
   concatination is then returned in the server's handshake
   [FIPS.180-2.2002].

   Concretely, if as in the example above, header |Sec-WebSocket-Key|
   had the value "dGhlIHNhbXBsZSBub25jZQ==", the server would
   concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form
   the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
   C5AB0DC85B11".  The server would then take the sha-1 hash of this,
   giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6
   0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea.  This value is
   then base64-encoded, to give the value "s3pPLMBiTxaQ9kYGzzhZRbK+
   xOo=".

   The handshake from the server is much simpler than the client
   handshake.  The first line is an HTTP Status-Line, with the status
   code 200:

        HTTP/1.1 200 OK

   Any status code other than 200 should be treated as a failure and the
   websocket connection aborted.  The headers follow the status code.

Fette                     Expires June 8, 2011                  [Page 8]
Internet-Draft           The WebSocket protocol            December 2010

   The |Sec-WebSocket-Accept| header indicates whether the server is
   willing to accept the connection.  If present, this header must
   include a hash of the client's nonce sent in |Sec-WebSocket-Key|
   along with a predefined GUID.  Any other value must not be
   interpreted as an acceptance of the connection by the server.

               HTTP/1.1 200 OK
               Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=

   These fields are checked by the Web browser when it is acting as a
   |WebSocket| client for scripted pages.  If the |Sec-WebSocket-Accept|
   value does not match the expected value, or if the header is missing,
   or if the HTTP status code is not 200, the connection will not be
   established and WebSockets frames will not be sent.

   Option fields can also be included.  In this version of the protocol,
   the main option field is |Sec-WebSocket-Protocol|, which indicates
   the subprotocol that the server has selected.  Web browsers verify
   that the server included one of the values as was specified in the
   |WebSocket| constructor.  A server that speaks multiple subprotocols
   has to make sure it selects one based on the client's handshake and
   specifies it in its handshake.

        Sec-WebSocket-Protocol: chat

   The server can also set cookie-related option fields to _set_
   cookies, as in HTTP.

5.  Opening Handshake

5.1.  Client Requirements

   User agents running in controlled environments, e.g. browsers on
   mobile handsets tied to specific carriers, may offload the management
   of the connection to another agent on the network.  In such a
   situation, the user agent for the purposes of conformance is
   considered to include both the handset software and any such agents.

   When the user agent is to *establish a WebSocket connection* to a
   WebSocket URL /url/, it must meet the following requirements.  In the
   following text, we will use terms from Section 3 such as "/host/" and
   "/secure/ flag" as defined in that section.

   1.  The WebSocket URL and its components MUST be valid according to
       Section 3.3.  If any of the requirements are not met, the client
       MUST fail the WebSocket connection and abort these steps.

   2.  If the user agent already has a WebSocket connection to the
       remote host (IP address) identified by /host/, even if known by
       another name, the user agent MUST wait until that connection has
       been established or for that connection to have failed.  If
       multiple connections to the same IP address are attempted
       simultaneously, the user agent MUST serialize them so that there
       is no more than one connection at a time running through the
       following steps.

       If the user agent cannot determine the IP address of the remote
       host (for example because all communication is being done through
       a proxy server that performs DNS queries itself), then the user
       agent MUST assume for the purposes of this step that each host
       name refers to a distinct remote host, but should instead limit
       the total number of simultaneous connections that are not
       established to a reasonably low number (e.g., in a Web browser,
       to the number of tabs the user has open).

       NOTE: This makes it harder for a script to perform a denial of
       service attack by just opening a large number of WebSocket
       connections to a remote host.  A server can further reduce the
       load on itself when attacked by making use of this by pausing
       before closing the connection, as that will reduce the rate at
       which the client reconnects.

       NOTE: There is no limit to the number of established WebSocket
       connections a user agent can have with a single remote host.
       Servers can refuse to connect users with an excessive number of
       connections, or disconnect resource-hogging users when suffering

Fette                     Expires June 8, 2011                 [Page 24]
Internet-Draft           The WebSocket protocol            December 2010

       high load.

   3.  _Proxy Usage_: If the user agent is configured to use a proxy
       when using the WebSocket protocol to connect to host /host/
       and/or port /port/, then the user agent SHOULD connect to that
       proxy and ask it to open a TCP connection to the host given by
       /host/ and the port given by /port/.

          EXAMPLE: For example, if the user agent uses an HTTP proxy for
          all traffic, then if it was to try to connect to port 80 on
          server example.com, it might send the following lines to the
          proxy server:

              CONNECT example.com:80 HTTP/1.1
              Host: example.com

          If there was a password, the connection might look like:

              CONNECT example.com:80 HTTP/1.1
              Host: example.com
              Proxy-authorization: Basic ZWRuYW1vZGU6bm9jYXBlcyE=

       If the user agent is not configured to use a proxy, then a direct
       TCP connection SHOULD be opened to the host given by /host/ and
       the port given by /port/.

       NOTE: Implementations that do not expose explicit UI for
       selecting a proxy for WebSocket connections separate from other
       proxies are encouraged to use a SOCKS proxy for WebSocket
       connections, if available, or failing that, to prefer the proxy
       configured for HTTPS connections over the proxy configured for
       HTTP connections.

       For the purpose of proxy autoconfiguration scripts, the URL to
       pass the function must be constructed from /host/, /port/,
       /resource name/, and the /secure/ flag using the steps to
       construct a WebSocket URL.

       NOTE: The WebSocket protocol can be identified in proxy
       autoconfiguration scripts from the scheme ("ws:" for unencrypted
       connections and "wss:" for encrypted connections).

   4.  If the connection could not be opened, either because a direct
       connection failed or because any proxy used returned an error,
       then the user agent MUST fail the WebSocket connection and abort
       the connection attempt.

Fette                     Expires June 8, 2011                 [Page 25]
Internet-Draft           The WebSocket protocol            December 2010

   5.  If /secure/ is true, the user agent MUST perform a TLS handshake
       over the connection.  If this fails (e.g. the server's
       certificate could not be verified), then the user agent MUST fail
       the WebSocket connection and abort the connection.  Otherwise,
       all further communication on this channel MUST run through the
       encrypted tunnel.  [RFC2246]

       User agents MUST use the Server Name Indication extension in the
       TLS handshake.  [RFC4366]

   Once a connection to the server has been established (including a
   connection via a proxy or over a TLS-encrypted tunnel), the client
   MUST send a handshake to the server.  The handshake consists of a
   CONNECT request, along with a list of required and optional headers.
   The requirements for this handshake are as follows.

   1.   The handshake must be a valid HTTP request as specified by
        [RFC2616].

   2.   The Method of the request MUST be CONNECT, and the authority
        MUST be websocket.invalid:443.  The HTTP version MUST be at
        least 1.1.

        The first line sent SHOULD be "CONNECT websocket.invalid:443
        HTTP/1.1"

   3.   The request MUST contain a "HOST" header whose value is equal to
        "websocket.invalid:443"

   4.   The request MUST include a header with the name "Sec-WebSocket-
        Key".  The value of this header MUST be a nonce consisting of a
        randomly selected 16-byte value that has been base64-encoded
        [RFC3548].  The nonce MUST be randomly selected for each
        connection.

        NOTE: As an example, if the randomly selected value was the set
        of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b
        0x0c 0x0d 0x0e 0x0f 0x10, the value of the header should be
        "AQIDBAUGBwgJCgsMDQ4PEC=="

   5.   The request MUST include a header with the name "Sec-WebSocket-
        Origin".  The value of this header MUST be the origin of the
        context in which the code establishing the connection is
        running.

        As an example, if code is running on www.example.com attempting
        to establish a connection to ww2.example.com, the value of the
        header should be "http://www.example.com".

Fette                     Expires June 8, 2011                 [Page 26]
Internet-Draft           The WebSocket protocol            December 2010

   6.   The request MUST include a header with the name "Sec-WebSocket-
        URL".  The value of this header MUST be the WebSocket URL to
        which the connection is to be made.

   7.   The request MUST include a header with the name "Sec-WebSocket-
        Draft".  The value of this header must be 4.

   8.   The request MAY include a header with the name "Sec-WebSocket-
        Protocol".  If present, this value indicates the subprotocol(s)
        the client wishes to speak.  The ABNF for the value of this
        header is 1#(token | quoted-string), where the definitions of
        /token/ and /quoted-string/ are as given in [RFC2616].

   9.   The request MAY include a header with the name "Sec-WebSocket-
        Extensions".  If present, this value indicates the protocol-
        level extension(s) the client wishes to speak.  The ABNF for the
        value of this header is 1#(token | quoted-string), where the
        definitions of /token/ and /quoted-string/ are as given in
        [RFC2616].

   10.  The request MAY include headers associated with sending cookies,
        as defined by the appropriate specifications.  [RFC2109]
        [RFC2965]

   Once the client's opening handshake has been sent, the client MUST
   wait for a response from the server before sending any further data.
   The server's response is detailed in the next section.  Specifically,
   the client MUST receive from the server a 200 status code in the HTTP
   response, and a "Sec-WebSocket-Accept" header.  The value of this
   header MUST be the value specified in the following section, namely a
   SHA-1 hash of the concatenation of the Sec-WebSocket-Key with the
   string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", base64-encoded.  Any
   other status code or value of "Sec-WebSocket-Accept" MUST NOT be
   interpreted as having completed a WebSocket handshake, and the client
   MUST NOT send WebSocket framed data over this connection until a
   successful handshake is completed.

   Where the algorithm above requires that a user agent fail the
   WebSocket connection, the user agent may first read an arbitrary
   number of further bytes from the connection (and then discard them)
   before actually *failing the WebSocket connection*.  Similarly, if a
   user agent can show that the bytes read from the connection so far
   are such that there is no subsequent sequence of bytes that the
   server can send that would not result in the user agent being
   required to *fail the WebSocket connection*, the user agent may
   immediately *fail the WebSocket connection* without waiting for those
   bytes.

Fette                     Expires June 8, 2011                 [Page 27]
Internet-Draft           The WebSocket protocol            December 2010

   NOTE: The previous paragraph is intended to make it conforming for
   user agents to implement the algorithm in subtly different ways that
   are equivalent in all ways except that they terminate the connection
   at earlier or later points.  For example, it enables an
   implementation to buffer the entire handshake response before
   checking it, or to verify each field as it is received rather than
   collecting all the fields and then checking them as a block.

5.2.  Server-side requirements

   _This section only applies to servers._

   Servers may offload the management of the connection to other agents
   on the network, for example load balancers and reverse proxies.  In
   such a situation, the server for the purposes of conformance is
   considered to include all parts of the server-side infrastructure
   from the first device to terminate the TCP connection all the way to
   the server that processes requests and sends responses.

   EXAMPLE: For example, a data center might have a server that responds
   to Web Socket requests with an appropriate handshake, and then passes
   the connection to another server to actually process the data frames.
   For the purposes of this specification, the "server" is the
   combination of both computers.

5.2.1.  Reading the client's opening handshake

   When a client starts a WebSocket connection, it sends its part of the
   opening handshake.  The server must parse at least part of this
   handshake in order to obtain the necessary information to generate
   the server part of the handshake.

   The client handshake consists of the following parts.  If the server,
   while reading the handshake, finds that the client did not send a
   handshake that matches the description below, the server should abort
   the WebSocket connection.

   1.  An HTTP/1.1 or higher CONNECT request to "websocket.invalid:443"

   2.  A "Host" header with the value "websocket.invalid:443".

   3.  A "Sec-WebSocket-Key" header with a base64-encoded value that,
       when decoded, is 16 bytes in length.

   4.  A "Sec-WebSocket-Origin" header.

   5.  A "Sec-WebSocket-URL" header, with a value denoting the location
       of the resource (endpoint) requested of the server.  If the

Fette                     Expires June 8, 2011                 [Page 28]
Internet-Draft           The WebSocket protocol            December 2010

       server only supports one resource, then this can safely be
       ignored.

   6.  A "Sec-WebSocket-Draft" header, with a value of 4.

   7.  Optionally, a "Sec-WebSocket-Protocol header, with a list of
       values indicating which protocols the client would like to speak,
       ordered by preference.

   8.  Optionally, a "Sec-WebSocket-Extensions" header, with a list of
       values indicating which extensions the client would like to
       speak.

   9.  Optionally, other headers, such as those used to send cookies to
       a server.  Unknown headers MUST be ignored.

5.2.2.  Sending the server's opening handshake

   When a client establishes a WebSocket connection to a server, the
   server must complete the following steps to accept the connection and
   send the server's opening handshake.

   1.  If the server supports encryption, perform a TLS handshake over
       the connection.  If this fails (e.g. the client indicated a host
       name in the extended client hello "server_name" extension that
       the server does not host), then close the connection; otherwise,
       all further communication for the connection (including the
       server handshake) must run through the encrypted tunnel.
       [RFC2246]

   2.  Establish the following information:

       /origin/
          The |Sec-WebSocket-Origin| header in the client's handshake
          indicates the origin of the script establishing the
          connection.  The origin is serialized to ASCII and converted
          to lowercase.  The server MAY use this information as part of
          a determination of whether to accept the incoming connection.

       /key/
          The |Sec-WebSocket-Key| header in the client's handshake
          includes a base64-encoded value that, if decoded, is 16 bytes
          in length.  This (encoded) value is used in the creation of
          the server's handshake to indicate an acceptance of the
          connection.  It is not necessary for the server to base64-
          decode the Sec-WebSocket-Key value.

Fette                     Expires June 8, 2011                 [Page 29]
Internet-Draft           The WebSocket protocol            December 2010

       /draft/
          The |Sec-WebSocket-Draft| header in the client's handshake
          includes the version of the WebSocket protocol the client is
          attempting to communicate with.  If this version does not
          match a version understood by the server, the server MUST
          abort the WebSocket connection.  The server MAY send a non-200
          response code with a |Sec-WebSocket-Draft| header indicating
          the version(s) the server is capable of understanding along
          with this non-200 response code.

       /resource name/
          An identifier for the service provided by the server.  If the
          server provides multiple services, then the value should be
          derived from the resource name given in the client's handshake
          as part of the |Sec-WebSocket-URL| header.

       /subprotocol/
          A (possibly empty) list representing the subprotocol the
          server is ready to use.  If the server supports multiple
          subprotocols, then the value should be derived from the
          client's handshake, specifically by selecting one of the
          values from the "Sec-WebSocket-Protocol" field.  The absence
          of such a field is equivalent to the null value.  The empty
          string is not the same as the null value for these purposes.

       /extensions/
          A (possibly empty) list representing the protocol-level
          extensions the server is ready to use.  If the server supports
          multiple extensions, then the value should be derived from the
          client's handshake, specifically by selecting one of the
          values from the "Sec-WebSocket-Extensions" field.  The absence
          of such a field is equivalent to the null value.  The empty
          string is not the same as the null value for these purposes.

   3.  If the server chooses to accept the incoming connection, it must
       reply with a valid HTTP response indicating the following.

       1.  A 200 response code.  Such a response could look like
           "HTTP/1.1 200 OK".

       2.  A "Sec-WebSocket-Accept" header.  The value of this header is
           constructed by concatenating the value of the client's "Sec-
           WebSocket-Key" header in the client's handshake with the
           string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", taking the
           SHA-1 hash of this concatenated value to obtain a 20-byte
           value, and base64-encoding this 20-byte hash.

           NOTE: As an example, if the value of the "Sec-WebSocket-Key"

Fette                     Expires June 8, 2011                 [Page 30]
Internet-Draft           The WebSocket protocol            December 2010

           header in the client's handshake were
           "dGhlIHNhbXBsZSBub25jZQ==", the server would append the
           string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form the
           string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
           C5AB0DC85B11".  The server would then take the sha-1 hash of
           this, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f
           0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4
           0xea.  This value is then base64-encoded, to give the value
           "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned in
           the "Sec-WebSocket-Accept" header.

       3.  A "Sec-WebSocket-Draft" header.  The value of this header
           must be equal to the value sent by the client in its
           handshake, which must be equal to 4.

       4.  Optionally, a "Sec-WebSocket-Protocol" header, indicating the
           subprotocol, if any, the server is prepared to speak.  The
           value of this header must be equal to one of the values
           specified by the client in its opening handshake.

       5.  Optionally, a "Sec-WebSocket-Extensions" header, indicating
           the protocol level extensions, if any, the server is prepared
           to speak.  The value of this header must be a subset of the
           values specified by the client in its opening handshake.

   This completes the server's handshake.  If the server finishes these
   steps without aborting the WebSocket connection, and if the client
   does not then fail the WebSocket connection, then the connection is
   established and the server may begin sending and receiving data, as
   described in the next section.

---

From: Greg Wilkins <[email-masked]>
Date: Tue, 7 Dec 2010 21:13:02 +0100

Ian,

It  looks a lot better that the -76 handshake..... except I really
can't past the websocket.invalid:443
There appears to be significant objections to this usage of CONNECT
and I think a bogus host is only going to add to that  objection.  I
don't know how it can be argued that it is not protocol abuse if it is
blatantly lying about fundamental information.
On top of that, there is the practical problems of a bogus host that
have been raised by Willy, myself and others.

regards

---

From: Willy Tarreau <[email-masked]>
Date: Tue, 7 Dec 2010 21:20:01 +0100

> have been raised by Willy, myself and others.

Agreed. I'd say that even Eric suggested that we proceed by steps and that
we first don't mask the routing information.

Regards,
Willy

---

From: Salvatore Loreto <[email-masked]>
Date: Tue, 7 Dec 2010 22:44:34 +0200

> we first don't mask the routing information.
I agree,
proceeding step by step would let the discussion be more focused and 
hopefully effective

/Sal

---

From: John Tamplin <[email-masked]>
Date: Tue, 7 Dec 2010 15:45:59 -0500

> have been raised by Willy, myself and others.

It seems like a WebSocket-aware server would recognize this as a
WebSocket request, and then it can just get the URL from the header
before going into its normal request processing, and it isn't even
masked.  Non-WS-aware servers will choke on it, but that is what you
want rather than allowing it to possibly succeed and them getting
confused.

-- 
John A. Tamplin
Software Engineer (GWT), Google

---

From: Dave Cridland <[email-masked]>
Date: Tue, 07 Dec 2010 20:52:43 +0000

> want rather than allowing it to possibly succeed and them getting

Right, but if you make the initial request a "normal" Upgrade, and  
then handle the case of a pass-through proxy by including a  
pseudo-CONNECT if the Upgrade works, I'm pretty sure you get the best  
of both worlds - that is, the CONNECT is never sent as a "real" HTTP  
request, and the real HTTP request is based on existing standards  
(and can be internally routed within the server normally) - but the  
CONNECT still has the effect it does in Adam's paper.

Dave.
-- 
Dave Cridland - mailto:[email-masked] - xmpp:[email-masked]
  - acap://acap.dave.cridland.net/byowner/user/dwd/bookmarks/
  - http://dave.cridland.net/
Infotrope Polymer - ACAP, IMAP, ESMTP, and Lemonade

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Tue, 7 Dec 2010 13:18:04 -0800

On Tue, Dec 7, 2010 at 12:52 PM, Dave Cridland <[email-masked]> wrote:

> Right, but if you make the initial request a "normal" Upgrade, and then
> handle the case of a pass-through proxy by including a pseudo-CONNECT if the
> Upgrade works, I'm pretty sure you get the best of both worlds - that is,
> the CONNECT is never sent as a "real" HTTP request, and the real HTTP
> request is based on existing standards (and can be internally routed within
> the server normally) - but the CONNECT still has the effect it does in
> Adam's paper.
>
> Dave.
>

Dave, are you proposing a second roundtrip for the connect?

> --
> Dave Cridland - mailto:[email-masked] - xmpp:[email-masked]<[email-masked]>
> _______________________________________________
> hybi mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/hybi
>

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Tue, 7 Dec 2010 13:21:31 -0800

> proceeding step by step would let the discussion be more focused and
I am trying to proceed by steps. I have removed all sorts of things, such as
the JSON packed data, the payload masking, etc. However, I will let Adam
speak to the potential security implications of including the actual
hostname in the Host: header. I am not personally convinced I understand the
security implications of doing so.

-Ian

---

From: Adam Barth <[email-masked]>
Date: Tue, 7 Dec 2010 13:36:22 -0800

> want rather than allowing it to possibly succeed and them getting

Precisely.

2010/12/7 Ian Fette (イアンフェッティ) <[email-masked]>:
> On Tue, Dec 7, 2010 at 12:44 PM, Salvatore Loreto
> <[email-masked]> wrote:

Unmasking the Host header has some security risk.  The scenario we're
worried about is one in which the attacker and the target server are
virtually hosted on the same machine.  In that case, a machine that
does not understand the Host header is likely to route the request
according to the Host header, but not understand that it is
establishing a bidirectional tunnel.  Another approach to mitigating
this threat is to mask the payload data so the attacker won't be able
to trick the machine after the handshake completes.

All that being said, this threat is less worrisome than the other
threats we've been discussing (such as cache poisoning).  We could
decide that we're not worried about scenarios in which the attacker is
virtually hosted on the same machine as the target.

If this is the only issue holding back consensus on the handshake, I'd
be ok with using an unmasked Host header if other folks are ok with
the remainder of the handshake as detailed by Ian.

Adam

---

From: Dave Cridland <[email-masked]>
Date: Tue, 07 Dec 2010 21:42:14 +0000

On Tue Dec  7 21:18:04 2010, Ian Fette (イアンフェッティ)  
> Dave, are you proposing a second roundtrip for the connect?
No, single round-trip.

C->S [Upgrade]
S->C [101]
C->S [Pseudo-CONNECT]

Accomplishes everything (as far as I'm aware) that Adam's CONNECT  
proposal does, but does so within an HTTP framework. The only  
entities which see the CONNECT as an HTTP request are already broken  
WRT Upgrades.

I did want to pipeline, but that's not ideal.

Dave.

---

From: John Tamplin <[email-masked]>
Date: Tue, 7 Dec 2010 16:52:35 -0500

> C->S [Pseudo-CONNECT]

I assume the server has to receive the Pseudo-CONNECT before it can
send user frames, right?  So, I would argue that this adds "half" a
round trip.

Also, we have discussed Hello frames to verify that the connection is
up and that we can exchange WebSocket frames -- it seems like it would
be safe to send a S->C hello immediately after the 101 response (as it
would contain no attacker-controlled bytes).  It doesn't verify that
the Pseudo-CONNECT was correctly processed, but you can't get that
without adding another round trip.

---

From: Dave Cridland <[email-masked]>
Date: Tue, 07 Dec 2010 22:22:06 +0000

> without adding another round trip.

Right, I think you can keep it to one round-trip, since the CONNECT  
only has to occur prior to C->S frames, not be received prior to S->C  
frames.

But also, the "Am I talking to a websocket-aware server" is  
controlled by the response to the upgrade, the CONNECT itself is  
really only there to minimize the risk of the attacks described in  
Adam's paper, it's no longer serving double-duty as the primary  
websocket handshake.

Dave.

---

From: Greg Wilkins <[email-masked]>
Date: Wed, 8 Dec 2010 10:01:43 +0100

> want rather than allowing it to possibly succeed and them getting

I'm not so much worried about WebSocket-aware servers.

I'm worried about WebSocket-unaware load balancers and other
intermediaries that may either need the host header to route the
request or may support CONNECT and try to handle it.

If we are saying that we don't want to support any websocket-unaware
intermediaries, then why are we bothering with port 80.

We either live on port 80 and respect HTTP(until HTTP says we can go
free after upgrade->101 or connect->200) or we go elsewhere.

---

From: Willy Tarreau <[email-masked]>
Date: Wed, 8 Dec 2010 10:12:25 +0100

> free after upgrade->101 or connect->200) or we go elsewhere.

+1 !

Willy

---

From: Greg Wilkins <[email-masked]>
Date: Wed, 8 Dec 2010 10:13:59 +0100

> to trick the machine after the handshake completes.

Adam,

is the following description the attack vector that you are concerned about:

www.innocentbystander.com and www.drevil.com are virtually hosted on
the same machine

A client loads some of drevil's javascript that makes a WS connection
to www.drevil.com, which is routed to that virtual host and the WS
connection is accepted.    www.drevil.com and/or the drevil javascript
then send WS packets that contain spoof HTTP requests that are sent to
www.innocentbystander.com   allowing the attacker to bypass same
origin rules etc.

If the server hosting these domains is WS aware, then this is not a problem.
If the server is not WS aware, then we have to ensure that the
handshake is not something that can be accepted by a normal HTTP
server, no matter what application the drevil is running.

The Hello frames that I have proposed protect against this kind of
attack, because they are bytes that an application running on a
non-websocket-aware server cannot generate, thus they cannot trick the
client into accepting the WS connection and sending more bytes.

Also robust WS framing is another layer of defence as it would protect
any packets sent by the client from easily being interpreted as HTTP.

Thus regardless of using CONNECT of Get+Upgrade,  I believe my
proposals for Hello frames and inverting some bits the header are good
defences to include.   I've attached my proposed text/diff for them
again... please feel free to swap out Upgrade for CONNECT if that is
your preference.

regards
--- draft-ietf-hybi-thewebsocketprotocol-03.txt	2010-11-02 10:14:36.846127994 +1100
+++ draft-ietf-hybi-thewebsocketprotocol-03-gw.txt	2010-11-02 12:33:05.026127994 +1100
@@ -281,16 +281,14 @@
 Internet-Draft           The WebSocket protocol             October 2010

-        GET /demo HTTP/1.1
+        WEBSOCKET /demo HTTP/1.1
         Host: example.com
         Connection: Upgrade
-        Sec-WebSocket-Key2: 12998 5 Y3 1  .P00
+        Sec-WebSocket-Nonce: A23F2BCA452DDE01
         Sec-WebSocket-Protocol: sample
         Upgrade: WebSocket
-        Sec-WebSocket-Key1: 4 @1  46546xW%0l 1 5
         Origin: http://example.com
 
-        ^n:ds[4U

@@ -302,7 +300,6 @@
         Sec-WebSocket-Location: ws://example.com/demo
         Sec-WebSocket-Protocol: sample
 
-        8jKS'y:G*Co,Wxa-
 
    The leading line from the client follows the Request-Line format.
    The leading line from the server follows the Status-Line format.  The
@@ -361,18 +358,15 @@
    Lines that don't match the above production cause the connection to
    be aborted.
 
-   Finally, after the last field, the client sends 10 bytes starting
-   with 0x0D 0x0A and followed by 8 random bytes, part of a challenge,
-   and the server sends 18 bytes starting with 0x0D 0x0A and followed by
-   16 bytes consisting of a challenge response.  The details of this
-   challenge and other parts of the handshake are described in the next
-   section.
-
-
    Once the client and server have both sent their handshakes, and if
    the handshake was successful, then the data transfer part starts.
    This is a two-way communication channel where each side can,
    independently from the other, send data at will.
+   The first frame sent in both directions must be a Hello frame 
+   containing digests to prove the handshakes have been processed. 
+   The applications should be notified of the successful establishment of 
+   a websocket connect after the receipt and verification of the Hello 
+   frame from the other end. 
 
    Clients and servers, after a successful handshake, transfer data back
    and forth in conceptual units referred to in this specification as
@@ -415,13 +409,24 @@
    server-side software, so that a single port can be used by both HTTP
    clients talking to that server and WebSocket clients talking to that
    server.  To this end, the WebSocket client's handshake appears to
-   HTTP servers to be a regular GET request with an Upgrade offer:
+   HTTP servers to be a regular HTTP request with an Upgrade offer:

-        GET / HTTP/1.1
+        WEBSOCKET / HTTP/1.1
         Upgrade: WebSocket
         Connection: Upgrade
 
+   Any valid method may be used in the request, so long as the client is
+   prepared to accept a valid HTTP response if the upgrade is not accepted. 
+   If the client can only handle websocket handshake responses, then the 
+   WEBSOCKET method should be used.
+
+   Any valid URI may be passed, except that the client must not send a 
+   handshake with a URI path that contain the character ':' or any 
+   control or whitspace characters in explicit or encoded form. This limits 
+   the possibility of using a websocket client to attack a vulnerable 
+   non WebSocket servers.
+
    Fields in the handshake are sent by the client in a random order; the
    order is not meaningful.
 
@@ -470,33 +475,29 @@
 
-   To prove that the handshake was received, the server has to take
-   three pieces of information and combine them to form a response.  The
-   first two pieces of information come from the |Sec-WebSocket-Key1|
-   and |Sec-WebSocket-Key2| fields in the client handshake:
-
-
-        Sec-WebSocket-Key1: 18x 6]8vM;54 *(5:  {   U1]8  z [  8
-        Sec-WebSocket-Key2: 1_ tx7X d  <  nw  334J702) 7]o}` 0
-
-   For each of these fields, the server has to take the digits from the
-   value to obtain a number (in this case 1868545188 and 1733470270
-   respectively), then divide that number by the number of spaces
-   characters in the value (in this case 12 and 10) to obtain a 32-bit
-   number (155712099 and 173347027).  These two resulting numbers are
-   then used in the server handshake, as described below.
-
-   The counting of spaces is intended to make it impossible to smuggle
-   this field into the resource name; making this even harder is the
-   presence of _two_ such fields, and the use of a newline as the only
-   reliable indicator that the end of the key has been reached.  The use
-   of random characters interspersed with the spaces and the numbers
-   ensures that the implementor actually looks for spaces and newlines,
-   instead of being treating any character like a space, which would
-   make it again easy to smuggle the fields into the path and trick the
-   server.  Finally, _dividing_ by this number of spaces is intended to
-   make sure that even the most naive of implementations will check for
-   spaces, since if ther server does not verify that there are some
+   To prove that the handshake was received, the server has to initiate
+   websocket communication with a Hello frame containing the MD5 hash of
+   a random 64 bit client nonce generated by the client and sent as a 
+   hex encoded string in the Sec-WebSocket-Nonce field of the client 
+   handshake:
+
+        Sec-WebSocket-Nonce: A23F2BCA452DDE01
+
+   The server has to take 8 octects of the client nonce, append the octects 
+   of the ASCII string "WebSocket" and then append 8 octects of a randomly 
+   generated server nonce (eg 15F0D2278BCD457F).  The server nonce and the
+   16 octet MD5 hash (eg Ee7eBe0c369cBf255a4451Fc58D7Cc4f) of the combined 
+   octects must be sent in a Hello frame as the first websocket frame from 
+   the server to the client:
+   
+      8F18 15F0D2278BCD457F Ee7eBe0c369cBf255a4451Fc58D7Cc4f
+
+   The server must then wait for the Hello frame from the client described
+   below and verify it's contents before notifying the application that the
+   websocket connection has been established.  However, a server application 
+   may send websocket messages after the Hello frame without waiting for 
+   notification that the connection has been established.
+   

@@ -505,22 +506,6 @@
 Internet-Draft           The WebSocket protocol             October 2010

-   spaces, the server will try to divide by zero, which is usually fatal
-   (a correct handshake will always have at least one space).
-
-   The third piece of information is given after the fields, in the last
-   eight bytes of the handshake, expressed here as they would be seen if
-   interpreted as UTF-8:
-
-        Tm[K T2u
-
-   The concatenation of the number obtained from processing the |Sec-
-   WebSocket-Key1| field, expressed as a big-endian 32 bit number, the
-   number obtained from processing the |Sec-WebSocket-Key2| field, again
-   expressed as a big-endian 32 bit number, and finally the eight bytes
-   at the end of the handshake, form a 128 bit string whose MD5 sum is
-   then used by the server to prove that it read the handshake.
-
 
    The handshake from the server is much simpler than the client
    handshake.  The first line is an HTTP Status-Line, with the status
@@ -531,7 +516,6 @@
    The fields follow.  Two of the fields are just for compatibility with
    HTTP:
 
-
         Upgrade: WebSocket
         Connection: Upgrade
 
@@ -539,7 +523,6 @@
    echoing the origin and stating the exact host, port, resource name,
    and whether the connection is expected to be encrypted:
 
-
         Sec-WebSocket-Origin: http://example.com
         Sec-WebSocket-Location: ws://example.com/
 
@@ -570,19 +553,26 @@
 
-   After the fields, the server sends the aforementioned MD5 sum, a 16
-   byte (128 bit) value, shown here as if interpreted as UTF-8:
+   After the fields, the server sends the aforementioned Hello frame 
+   containing the 8 octects of the server nonce followed by the 16 
+   octects of the MD5 digest.
+
+   After receiving the server handshake, the client must wait for the
+   following Hello frame and verify that the contents. The digest value 
+   depends on both the client and server nonces, as described above.
+   If it doesn't match what the client is expecting, the client must 
+   disconnect.   Only after verifying the contents of the Hello frame
+   may the client application be notified of an open connection. 
+
+   The first websocket frame sent by the client to the server must be
+   a Hello frame containing the 128 bit MD5 digest of the 8 octects of the
+   server nonce followed by the octects of the ASCII string "WebSocket" 
+   followed by the 8 octects of the client nonce: 
+   
+        8F10 33122035D11258Fd7c764314580e539c
 
-        fQJ,fN/4F4!~K~MH
+     
 
-   This value depends on what the client sends, as described above.  If
-   it doesn't match what the client is expecting, the client would
-   disconnect.
-
-   Having part of the handshake appear after the fields ensures that
-   both the server and the client verify that the connection is not
-   being interrupted by an HTTP intermediary such as a man-in-the-middle
-   cache or proxy.
 
 1.4.  Closing handshake
 
@@ -739,6 +729,9 @@
    the selected subprotocol values in its response for the connection to
    be established.
 
+   Subprotocol names are restricted to use the ASCII characters A-Z, a-z,
+   0-9, '/', '_' and '-'.
+
    These subprotocol names do not need to be registered, but if a
    subprotocol is intended to be implemented by multiple independent
    WebSocket servers, potential clashes with the names of subprotocols
@@ -941,7 +934,11 @@
    10.  If /resource name/ is the empty string, set it to a single
         character U+002F SOLIDUS (/).
 
-   11.  If /url/ has a <query> component, then append a single U+003F
+   11.  If /resource name/ contains the character ':' or any white space
+        characters or any characters with codes <= U+0020, then the URL 
+        is invalid.
+
+   12.  If /url/ has a <query> component, then append a single U+003F
         QUESTION MARK character (?) to /resource name/, followed by the
         value of the <query> component.
 
@@ -953,7 +950,7 @@
 Internet-Draft           The WebSocket protocol             October 2010

-   12.  Return /host/, /port/, /resource name/, and /secure/.
+   13.  Return /host/, /port/, /resource name/, and /secure/.
 
 3.2.  Constructing WebSocket URLs
 
@@ -1091,10 +1088,10 @@
       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-------+-+-------------+-------------------------------+
-     |M|R|R|R| opcode|R| Payload len |    Extended payload length    |
-     |O|S|S|S|  (4)  |S|     (7)     |             (16/63)           |
-     |R|V|V|V|       |V|             |   (if payload len==126/127)   |
-     |E|1|2|3|       |4|             |                               |
+     |F|R|R|R| opcode|R| Payload len |    Extended payload length    |
+     |I|S|S|S|  (4)  |S|     (7)     |             (16/63)           |
+     |N|V|V|V|       |V|             |   (if payload len==126/127)   |
+     | |1|2|3|       |4|             |                               |
      +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
      |     Extended payload length continued, if payload len == 127  |
      + - - - - - - - - - - - - - - - +-------------------------------+
@@ -1177,7 +1174,7 @@
 Internet-Draft           The WebSocket protocol             October 2010

-      ws-frame               = frame-more
+      ws-frame               = frame-fin
                                frame-rsv1
                                frame-rsv2
                                frame-rsv3
@@ -1187,8 +1184,8 @@
                                frame-extension
                                application-data;
 
-      frame-more             = %x0 ; final frame of message
-                             / %x1 ; more frames of this message follow
+      frame-fin              = %x1 ; final frame of message
+                             / %x0 ; more frames of this message follow
 
       frame-rsv1             = %x0 ; 1 bit, must be 0
 
@@ -1202,7 +1199,8 @@
                              / %x3 ; pong
                              / %x4 ; text frame
                              / %x5 ; binary frame
-                             / %x6-F ; reserved
+                             / %x6-E ; reserved
+                             / %xF ; Hello frame
 
       frame-rsv4             = %x0 ; 1 bit, must be 0
 
@@ -1222,8 +1220,8 @@
 
    The following rules apply to fragmentation:
 
-   o  An unfragmented message consists of a single frame with the MORE
-      bit clear and an opcode other than 0.
+   o  An unfragmented message consists of a single frame with the FIN
+      bit set and an opcode other than 0.

@@ -1233,10 +1231,10 @@
 Internet-Draft           The WebSocket protocol             October 2010

-   o  A fragmented message consists of a single frame with the MORE bit
-      set and an opcode other than 0, followed by zero or more frames
-      with the MORE bit set and the opcode set to 0, and terminated by a
-      single frame with the MORE bit clear and an opcode of 0.  Its
+   o  A fragmented message consists of a single frame with the FIN bit
+      clear and an opcode other than 0, followed by zero or more frames
+      with the FIN bit clear and the opcode set to 0, and terminated by a
+      single frame with the FIN bit set and an opcode of 0.  Its
       content is the concatenation of the application data from each of
       those frames in order.
 
@@ -1257,9 +1255,9 @@
 
 4.4.  Control Frames
 
-   Control frames have opcodes of 0x01 (Close), 0x02 (Ping), or 0x03
-   (Pong).  Control frames are used to communicate state about the
-   websocket.
+   Control frames have opcodes of 0x01 (Close), 0x02 (Ping), 0x03
+   (Pong) or 0x0f (Hello).  Control frames are used to communicate 
+   state about the websocket.
 
    All control frames MUST be 125 bytes or less in length and MUST NOT
    be fragmented.
@@ -1320,19 +1318,36 @@
       The payload data is arbitrary binary data whose interpretation is
       solely up to the application layer.
 
+
+4.4.2.  Hello
+
+   The Hello message contains an opcode of 0x0F and must be the first
+   frame sent on any WebSocket connection.
+
+   A Hello message sent from the server to the client must contain 24 
+   octets of data, comprising of the 8 octects of the server nonce and 
+   the 16 octects of the MD5 digest of the 41 octets of the client 
+   nonce, plus the ASCII string "WebSocket", plus the server nonce.
+
+   A Hello message sent from the client to the server must contain 16
+   octets of data, comprising the MD5 digest of the 41 octets of the
+   server nonce, plust the ASCII string "WebSocket", plust the client 
+   nonce.
+
+
 4.6.  Examples

    o  A single-frame text message
 
-      *  0x04 0x05 "Hello"
+      *  0x84 0x05 "Hello"
 
    o  A fragmented text message
 
-      *  0x84 0x03 "Hel"
+      *  0x04 0x03 "Hel"
 
-      *  0x00 0x02 "lo"
+      *  0x80 0x02 "lo"
 
    o  Ping request and response
 
@@ -1345,17 +1360,17 @@
 Internet-Draft           The WebSocket protocol             October 2010

-      *  0x02 0x05 "Hello"
+      *  0x82 0x05 "Hello"
 
-      *  0x03 0x05 "Hello"
+      *  0x83 0x05 "Hello"
 
    o  256 bytes binary message in a single frame
 
-      *  0x05 0x7E 0x0100 [256 bytes of binary data]
+      *  0x85 0x7E 0x0100 [256 bytes of binary data]
 
    o  64KiB binary message in a single frame
 
-      *  0x05 0x7F 0x0000000000010000 [65536 bytes of binary data]
+      *  0x85 0x7F 0x0000000000010000 [65536 bytes of binary data]
 
 4.7.  Extensibility
 
@@ -1522,8 +1537,10 @@
         User agents must use the Server Name Indication extension in the
         TLS handshake.  [RFC4366]
 
-   6.   Send the UTF-8 string "GET" followed by a UTF-8-encoded U+0020
-        SPACE character to the remote side (the server).
+   6.   Send the HTTP method as a UTF-8 string followed by a 
+        UTF-8-encoded U+0020 SPACE character to the remote side (the server).
+        If the client has not otherwise specified a method, then the 
+        method used should be "GET".
 
         Send the /resource name/ value, encoded as UTF-8.
 
@@ -1554,7 +1571,7 @@
         "Origin:", a U+0020 SPACE character, and the /origin/ value, to
         /fields/.
 
-   15.  Add the string "Sec-WebSocket-Draft: 2" to /fields/.
+   15.  Add the string "Sec-WebSocket-Draft: 3" to /fields/.
 
    16.  If there is no /protocols/, then skip this step.
 
@@ -1591,31 +1608,11 @@
         continuation lines (e.g. containing no U+000A LINE FEED
         characters.)
 
-   19.  Let /spaces_1/ be a random integer from 1 to 12 inclusive.
-
-        Let /spaces_2/ be a random integer from 1 to 12 inclusive.
-
-        EXAMPLE: For example, 5 and 9.
-
-   20.  Let /max_1/ be the largest integer not greater than
-        4,294,967,295 divided by /spaces_1/.
-
-        Let /max_2/ be the largest integer not greater than
-        4,294,967,295 divided by /spaces_2/.
+   19.  Let /client nonce/ be a random 64 bit integer.
 
-        EXAMPLE: Continuing the example, 858,993,459 and 477,218,588.
+        EXAMPLE expressed as a hexidecimal number :
 
-   21.  Let /number_1/ be a random integer from 0 to /max_1/ inclusive.
-
-        Let /number_2/ be a random integer from 0 to /max_2/ inclusive.
-
-        EXAMPLE: For example, 777,007,543 and 114,997,259.
-
-   22.  Let /product_1/ be the result of multiplying /number_1/ and
-        /spaces_1/ together.
-
-        Let /product_2/ be the result of multiplying /number_2/ and
-        /spaces_2/ together.
+           A23F2BCA452DDE01

@@ -1625,49 +1622,12 @@
 Internet-Draft           The WebSocket protocol             October 2010

-        EXAMPLE: Continuing the example, 3,885,037,715 and
-        1,034,975,331.
-
-   23.  Let /key_1/ be a string consisting of /product_1/, expressed in
-        base ten using the numerals in the range U+0030 DIGIT ZERO (0)
-        to U+0039 DIGIT NINE (9).
-
-        Let /key_2/ be a string consisting of /product_2/, expressed in
-        base ten using the numerals in the range U+0030 DIGIT ZERO (0)
-        to U+0039 DIGIT NINE (9).
-
-        EXAMPLE: Continuing the example, "3885037715" and "1034975331".
-
-   24.  Insert between one and twelve random characters from the ranges
-        U+0021 to U+002F and U+003A to U+007E into /key_1/ at random
-        positions.
-
-        Insert between one and twelve random characters from the ranges
-        U+0021 to U+002F and U+003A to U+007E into /key_2/ at random
-        positions.
-
-        NOTE: This corresponds to random printable ASCII characters
-        other than the digits and the U+0020 SPACE character.
-
-        EXAMPLE: Continuing the example, this could lead to "P388O503D&
-        ul7{K%gX(%715" and "1N?|kUT0or3o4I97N5-S3O31".
-
-   25.  Insert /spaces_1/ U+0020 SPACE characters into /key_1/ at random
-        positions other than the start or end of the string.
-
-        Insert /spaces_2/ U+0020 SPACE characters into /key_2/ at random
-        positions other than the start or end of the string.
-
-        EXAMPLE: Continuing the example, this could lead to "P388 O503D&
-        ul7 {K%gX( %7  15" and "1 N ?|k UT0or 3o  4 I97N 5-S3O 31".
-
    26.  Add the string consisting of the concatenation of the string
-        "Sec-WebSocket-Key1:", a U+0020 SPACE character, and the /key_1/
-        value, to /fields/.
-
-        Add the string consisting of the concatenation of the string
-        "Sec-WebSocket-Key2:", a U+0020 SPACE character, and the /key_2/
-        value, to /fields/.
+        "Sec-WebSocket-Nonce:", a U+0020 SPACE character, and the /client nonce/
+        value expressed as a base 16 using numerals in the range U+0030 
+        DIGIT ZERO (0) to U+0039 DIGIT  NINE (9) and letters in the 
+        range U+0041 LATIN CAPITAL LETTER A to U+0046 LATIN CAPITAL 
+        LETTER F , to /fields/.
 
    27.  For each string in /fields/, in a random order: send the string,
         encoded as UTF-8, followed by a UTF-8-encoded U+000D CARRIAGE
@@ -1686,14 +1646,6 @@
    28.  Send a UTF-8-encoded U+000D CARRIAGE RETURN U+000A LINE FEED
         character pair (CRLF).
 
-   29.  Let /key_3/ be a string consisting of eight random bytes (or
-        equivalently, a random 64 bit unsigned integer encoded in big-
-        endian order).
-
-        EXAMPLE: For example, 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58.
-
-   30.  Send /key_3/ to the server.
-
    31.  Read bytes from the server until either the connection closes,
         or a 0x0A byte is read.  Let /field/ be these bytes, including
         the 0x0A byte.
@@ -1909,31 +1861,44 @@
            Ignore it.

-   45.  Let /challenge/ be the concatenation of /number_1/, expressed as
-        a big-endian 32 bit integer, /number_2/, expressed as a big-
-        endian 32 bit integer, and the eight bytes of /key_3/ in the
-        order they were sent on the wire.
-
-        EXAMPLE: Using the examples given earlier, this leads to the 16
-        bytes 0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22
-        0x2D 0x5A 0x3F 0x47 0x58.
-
-   46.  Let /expected/ be the MD5 fingerprint of /challenge/ as a big-
-        endian 128 bit string.  [RFC1321]
-
-        EXAMPLE: Using the examples given earlier, this leads to the 16
-        bytes 0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A
-        0x55 0x5E 0x77 0x65 0x75.  In UTF-8, these bytes correspond to
-        the string "0st3Rl&q-2ZU^weu".
-
-   47.  Read sixteen bytes from the server.  Let /reply/ be those bytes.
+   47.  Read twenty six bytes from the server.  Let /server hello/ be those bytes.
 
         If the connection closes before these bytes are received, then
         fail the WebSocket connection and abort these steps.
 
-   48.  If /reply/ does not exactly equal /expected/, then fail the
-        WebSocket connection and abort these steps.
+   48.  If the first octet of /server hello/ is not 0x8f then fail the WebSocket
+        connection and abort these steps.
+        
+        If the second octet of /server hello/ is not 0x18 then fail the WebSocket
+        connection and abort these steps.
+
+   49.  Let /server nonce/ be the 8 octets starting from the third octet of 
+        /server hello/
+
+        EXAMPLE expressed as a hexidecimal number:
+
+            15F0D2278BCD457F
+
+        Let /server digest/ be the 16 octets starting from the eleventh
+        octet of /server hello/
 
+   50.  Let /server expected/ be the 16 octets of MD5 digest of the 
+        concatination of /client nonce/, the ASCII string "WebSocket" and
+        /server nonce/
+
+        EXAMPLE expressed as a hexidecimal number:
+
+            Ee7eBe0c369cBf255a4451Fc58D7Cc4f
+
+   51.  If /server digest/ does not equal /server expected/ then fail
+        the WebSocket connection and abort these steps.
+
+   52.  Let /client digest/ be the 16 octets of MD4 digest of the 
+        concatination of /server nonce/, the ASCII string "WebSocket" and
+        /client nonce/.
+
+   53.  Send the octects 0x8f, 0x10 and /client digest/
+   
    49.  If the /defer cookies/ flag is not set, apply the cookies in the
         /list of cookies/.
 
@@ -2004,7 +1969,7 @@
 
-   1.  The three-character UTF-8 string "GET".
+   1.  A UTF-8 string which is a HTTP method such as "GET" or "WEBSOCKET"
 
    2.  A UTF-8-encoded U+0020 SPACE character (0x20 byte).
 
@@ -2020,7 +1985,9 @@
    3.  A string consisting of all the bytes up to the next UTF-8-encoded
        U+0020 SPACE character (0x20 byte).  The result of decoding this
        string as a UTF-8 string is the name of the resource requested by
-       the server.  If the server only supports one resource, then this
+       the server and must be a valid resource name according to Section 3.3.
+
+       If the server only supports one resource, then this
        can safely be ignored; the client verifies that the right
        resource is supported based on the information included in the
        server's own handshake.  The resource name will begin with U+002F
@@ -2136,9 +2103,7 @@
       server supports, to avoid integrity errors once the connection is
       established.
 
-   |Sec-WebSocket-Key1|
-
-   |Sec-WebSocket-Key2|
+   |Sec-WebSocket-Nonce|
       The values provide the information required for computing the
       server's handshake, as described in the next section.
 
@@ -2207,7 +2172,6 @@
 
         /secure flag/
 
-
            True if the connection is encrypted or if the server expected
            it to be encrypted; false otherwise.
 
@@ -2228,8 +2192,8 @@
 
-        /key_1/
-           The value of the "Sec-WebSocket-Key1" field in the client's
+        /client nonce/
+           The value of the "Sec-WebSocket-Nonce" field in the client's
            handshake.

@@ -2241,54 +2205,18 @@
 Internet-Draft           The WebSocket protocol             October 2010

-        /key_2/
-           The value of the "Sec-WebSocket-Key2" field in the client's
-           handshake.
+        /server nonce/
+           An 64 bit random integer generated by the server.
+
+           EXAMPLE expressed in hexidecimal:
 
-        /key_3/
-           The eight random bytes sent after the first 0x0D 0x0A 0x0D
-           0x0A sequence in the client's handshake.
+               15F0D2278BCD457F
 
    3.   Let /location/ be the string that results from constructing a
         WebSocket URL from /host/, /port/, /resource name/, and /secure
         flag/.
 
-   4.   Let /key-number_1/ be the digits (characters in the range U+0030
-        DIGIT ZERO (0) to U+0039 DIGIT NINE (9)) in /key_1/, interpreted
-        as a base ten integer, ignoring all other characters in /key_1/.
-
-        Let /key-number_2/ be the digits (characters in the range U+0030
-        DIGIT ZERO (0) to U+0039 DIGIT NINE (9)) in /key_2/, interpreted
-        as a base ten integer, ignoring all other characters in /key_2/.
-
-           EXAMPLE: For example, assume that the client handshake was:
-
-
-              GET / HTTP/1.1
-              Connection: Upgrade
-              Host: example.com
-              Upgrade: WebSocket
-              Sec-WebSocket-Key1: 3e6b263  4 17 80
-              Origin: http://example.com
-              Sec-WebSocket-Key2: 17  9 G`ZD9   2 2b 7X 3 /r90
-
-              WjN}|M(6
-
-           The /key-number_1/ would be the number 3,626,341,780, and the
-           /key-number_2/ would be the number 1,799,227,390.
-
-           In this example, incidentally, /key_3/ is "WjN}|M(6", or 0x57
-           0x6A 0x4E 0x7D 0x7C 0x4D 0x28 0x36.
-
-   5.   Let /spaces_1/ be the number of U+0020 SPACE characters in
-        /key_1/.
-
-        Let /spaces_2/ be the number of U+0020 SPACE characters in
-        /key_2/.
-
-        If either /spaces_1/ or /spaces_2/ is zero, then abort the
-        WebSocket connection.  This is a symptom of a cross-protocol
-        attack.
+   

@@ -2297,40 +2225,14 @@
 Internet-Draft           The WebSocket protocol             October 2010

-        EXAMPLE: In the example above, /spaces_1/ would be 4 and
-        /spaces_2/ would be 10.
-
-   6.   If /key-number_1/ is not an integral multiple of /spaces_1/,
-        then abort the WebSocket connection.
+   4.   Let /server digest/ be the 16 octets of MD5 digest of the 
+        concatination of /client nonce/, the ASCII string "WebSocket" and
+        /server nonce/
 
-        If /key-number_2/ is not an integral multiple of /spaces_2/,
-        then abort the WebSocket connection.
+        EXAMPLE expressed in hexidecimal:
 
-        NOTE: This can only happen if the client is not a conforming
-        WebSocket client.
+            Ee7eBe0c369cBf255a4451Fc58D7Cc4f
 
-   7.   Let /part_1/ be /key-number_1/ divided by /spaces_1/.
-
-        Let /part_2/ be /key-number_2/ divided by /spaces_2/.
-
-        EXAMPLE: In the example above, /part_1/ would be 906,585,445 and
-        /part_2/ would be 179,922,739.
-
-   8.   Let /challenge/ be the concatenation of /part_1/, expressed as a
-        big-endian 32 bit integer, /part_2/, expressed as a big-endian
-        32 bit integer, and the eight bytes of /key_3/ in the order they
-        were sent on the wire.
-
-        EXAMPLE: In the example above, this would be the 16 bytes 0x36
-        0x09 0x65 0x65 0x0A 0xB9 0x67 0x33 0x57 0x6A 0x4E 0x7D 0x7C 0x4D
-        0x28 0x36.
-
-   9.   Let /response/ be the MD5 fingerprint of /challenge/ as a big-
-        endian 128 bit string.  [RFC1321]
-
-        EXAMPLE: In the example above, this would be the 16 bytes 0x6E
-        0x60 0x39 0x65 0x42 0x6B 0x39 0x7A 0x24 0x52 0x38 0x70 0x4F 0x74
-        0x56 0x62, or "n`9eBk9z$R8pOtVb" in UTF-8.
 
    10.  Send the following line, terminated by the two characters U+000D
         CARRIAGE RETURN and U+000A LINE FEED (CRLF) and encoded as
@@ -2384,7 +2286,40 @@
 
    12.  Send two bytes 0x0D 0x0A (UTF-8 CRLF).
 
-   13.  Send /response/.
+   13.  Send the octets 0x8F, 0x18, /server nonce/ and /server digest/.
+
+   14.  The *WebSocket connection is accepted*.  Now the server may 
+        send messages to the connection as described in the next section.
+
+   15.  Read eighteen octets from the server.  Let /client hello/ be those bytes.
+
+        If the connection closes before these bytes are received, then
+        fail the WebSocket connection and abort these steps.
+
+   48.  If the first octet of /client hello/ is not 0x8f then fail the WebSocket
+        connection and abort these steps.
+        
+        If the second octet of /client hello/ is not 0x10 then fail the WebSocket
+        connection and abort these steps.
+
+   50.  Let /client expected/ be the 16 octets of MD5 digest of the 
+        concatination of /server nonce/, the ASCII string "WebSocket" and
+        /client nonce/
+
+        EXAMPLE expressed as a hexidecimal number:
+
+            33122035D11258Fd7c764314580e539c
+
+        Let /client digest/ be the 16 octets starting from the third
+        octet of /client hello/
+
+   51.  If /client digest/ does not equal /client expected/ then fail
+        the WebSocket connection and abort these steps.
+
+   52.  The *WebSocket connection is established*.  Now the server
+        may send and receive to and from the connection as described in
+        the next section.
+

---

From: Dave Cridland <[email-masked]>
Date: Wed, 08 Dec 2010 09:33:47 +0000

> again... please feel free to swap out Upgrade for CONNECT if that is

I think your bit-flipping is good, as it can only serve to make the  
framing more stable. I certainly don't see any argument against,  
whereas I can see the argument for. As such, I think this is a good  
idea and should be done.

I think the method for checking the websocket support in the server  
and "choking" any transparent intermediaries (of the type described  
in Adam's paper) needn't be Hello frames. That's why my proposal is  
essentially yours, but with a 101/CONNECT exchange in lieu of a Hello  
frame exchange - this should provide the utility of both methods with  
no difference in RTT counts at startup. In addition since the CONNECT  
is no longer unilaterally sent, it should never appear at the  
end-server as an HTTP request - its sole purpose is to look  
sufficiently like one to a naïve intermediary - as such the arguments  
against it cease to apply.

Hence:

RTT@RX
0.5	Mandatory:	 [C->S] Upgrade	 "Do you support websockets?"
1.0	Mandatory:	 [S->C] 101		 "Yes, yes I do. Here's my proof."
1.0	Optional:		 [S->C] <frame>	 "I'm starting to send frames now."
1.5	Mandatory:	 [C->S] CONNECT	 "OK, so let's choke out the  
intermediaries we don't know about and exchange."
1.5	Optional:		 [C->S] <frame>	 "I start sending frames here."

Dave.

---

From: Greg Wilkins <[email-masked]>
Date: Wed, 8 Dec 2010 11:10:54 +0100

Dave,

I certainly agree that your CONNECT and the Hello frame proposals are
very similar in nature. Essentially they are sending something at the
start of frame transfers that is designed to throw off silly
intermediaries. However, I still slightly favour Hello frames for
several reasons (some that need to be tested experimentally):

I think that eventually we will go to a dedicated port.  Using a Hello
frame and putting more usable information in there there is something
that will work well on a dedicated port.

While CONNECT has been shown the throw off many intermediaries, there
is a suggestion that at least some ignore the CONNECT method.   Thus
it may not give as much security as initially appears.    Sending a
HTTP request with chunking may be a better way to trick more
intermediaries.

I expect think high bits in the framing will be very successful in
preventing intermediaries scanning for HTTP - but that is an assertion
that needs to be well tested.

I guess fundamentally I'm a little against your CONNECT idea because
it is kind of a heuristic trick to get around specific intermediary
flaws.  It does not feel good to include such tricks in protocol
design - specially when we there are still several proposals that may
be able to address the problem without such devices.

My preference would be to develop the protocol as far as we can
without such tricks, and then at the end if we still not convinced
that we have a safe protocol, we can add such things at the end.
Willy has frequently suggestion Connection:close as a similar HTTP,
their is your CONNECT proposal and maybe something can be done with
HTTP/1.1 chunking.

cheers

On 8 December 2010 10:33, Dave Cridland <[email-masked]> wrote:
> I think your bit-flipping is good, as it can only serve to make the framing
> more stable. I certainly don't see any argument against, whereas I can see
> the argument for. As such, I think this is a good idea and should be done.
>
> I think the method for checking the websocket support in the server and
> "choking" any transparent intermediaries (of the type described in Adam's
> paper) needn't be Hello frames. That's why my proposal is essentially yours,
> but with a 101/CONNECT exchange in lieu of a Hello frame exchange - this
> should provide the utility of both methods with no difference in RTT counts
> at startup. In addition since the CONNECT is no longer unilaterally sent, it
> should never appear at the end-server as an HTTP request - its sole purpose
> is to look sufficiently like one to a naïve intermediary - as such the
> arguments against it cease to apply.
>
> Hence:
>
> RTT@RX

---

From: "Simon Pieters" <[email-masked]>
Date: Wed, 08 Dec 2010 12:07:21 +0100

> handshake, as it would fit into the WebSockets protocol.

At the risk of distracting more, I'll provide some quick comments.

> 1.2.  Protocol overview

I didn't look at the non-normative sections.

>    "/secure/ flag" as defined in that section.

The WebSocket API passes the following "parameters" to the "establish a  
WebSocket connection" algorithm:

[[
Establish a WebSocket connection to a host host, on port port (if one was  
specified), from origin, with the flag secure, with resource name as the  
resource name, with protocols as the (possibly empty) list of protocols,  
and with the defer cookies flag set. [WSP]
]]

i.e. host, port, origin, secure, resource name, protocols, defer cookies.  
The URL is *not* passed.

>        MUST fail the WebSocket connection and abort these steps.

The WebSocket API validates the URL.

> %0CInternet-Draft           The WebSocket protocol            December  
> 2010
>
>
>        high load.
>
> %0CInternet-Draft           The WebSocket protocol            December  
> 2010
>
>

The current draft says which bytes should be put on the wire exactly. I  
prefer the current draft over referencing RFC2616 since doing the latter  
makes many variations conforming which can cause interop problems.

>         MUST be websocket.invalid:443.  The HTTP version MUST be at

Why at least 1.1 and not exactly 1.1?

>    3.   The request MUST contain a "HOST" header whose value is equal to

"HOST" or "Host"?

>         context in which the code establishing the connection is

The value must be /origin/ that is passed to the algorithm. The WebSocket  
API has requirements on what /origin/ is.

> %0CInternet-Draft           The WebSocket protocol            December  
> 2010
>
>

Why URL? Current handshake uses /resource name/.

>         /token/ and /quoted-string/ are as given in [RFC2616].

MAY? This should be MUST if /protocols/ is not empty, with the value of  
/protocols/ joined with U+0020, or MUST NOT if /protocols/ is empty.

>         definitions of /token/ and /quoted-string/ are as given in

There are no extensions defined yet, right? Are vendor-proprietary  
extensions allowed or not?

>         as defined by the appropriate specifications.  [RFC2109]

MAY? Which cookies? Current draft has more precise rules here.

>    The server's response is detailed in the next section.

*Sending* the server's response is detailed in the next section. Reading  
it is not.

>    Specifically,

Why not put this as part of the algorithm? See step 31 to 51 in the  
current draft. It misses a lot of critical details present in the current  
draft, like actually invoking _fail the WebSocket connection_, defining  
*the WebSocket connection is established*, applying cookies, and other  
things.

> %0CInternet-Draft           The WebSocket protocol            December  
> 2010
>
>

I haven't looked at this section.

-- 
Simon Pieters
Opera Software

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Wed, 8 Dec 2010 07:42:04 -0800

2010/12/8 Simon Pieters <[email-masked]>

> On Tue, 07 Dec 2010 19:01:34 +0100, Ian Fette (イアンフェッティ) <
> [email-masked]> wrote:
>
> resource name, with protocols as the (possibly empty) list of protocols, and
> with the defer cookies flag set. [WSP]
> ]]
>

This needs to be parsed from the Sec-WebSocket-URL header. I will clarify.
(or, if we decide not to mask host, then it may change slightly.)

> The WebSocket API validates the URL.

I'm not sure I understand your comment. Are you saying it's validated
client-side? Even if so, the HTML5 clients are not necessarily the only
users of the protocol. I think it's reasonable to leave validation text in
for servers, if the browser also validates which it should, then there
shouldn't be any problem. Or am I mis-interpreting?

> makes many variations conforming which can cause interop problems.
And this was a source of contention for many people.

> Why at least 1.1 and not exactly 1.1?

Is there any particular reason to exclude future versions? I don't know if
it will really matter, happy to change if people want it to be exactly 1.1.

>>   3.   The request MUST contain a "HOST" header whose value is equal to

Typo, Host. Thanks.

> API has requirements on what /origin/ is.

Ok, here I wasn't sure as again, the HTML5 WebSocket API is not necessarily
the only thing implementing the protocol. Perhaps I can change it though to
simply reference the definition in the HTML5 spec for HTML clients, and
leave the somewhat more generic description for other non-HTML clients?
Thoughts? E.g. it's not clear referencing the HTML5 API exactly would be
appropriate if a plugin wished to implement the API.

> Why URL? Current handshake uses /resource name/.

Because the current handshake also has the Host and resource as part of the
GET, and the new handshake using CONNECT doesn't have that, so it has to go
somewhere. At that point, it becomes a question of adding a host and
resource name header, or adding a single URL header. Adding a single URL
header seems cleaner.

> /protocols/ joined with U+0020, or MUST NOT if /protocols/ is empty.

I was trying to describe the requirements for a handshake. The header is
optional in that the protocols field is not a required component. I also
thought we had moved towards agreement on getting away from re-defining
header parsing in this spec and instead  referencing 2616, e.g.
Sec-WebSocket-Protocol: chat, superchat, "my, cool, thing"

> extensions allowed or not?

There's one at the end of the spec (compression) in -03. And vendor
proprietary extensions would certainly be allowed.

> MAY? Which cookies? Current draft has more precise rules here.

Again, MAY as this is not required for a successful handshake. I'm happy to
throw in a MUST for browser clients specifically, but it seems like that
ought to be in the HTML spec and not the protocol spec. The protocol spec
should really be specifying the protocol for all clients, and what is
allowed to be sent over that protocol. Instructions specific to a particular
client seem like they belong with the specification for that client, e.g.
the HTML spec should specify what cookies must be sent with a WebSocket
request for browsers, not the protocol spec.

> *Sending* the server's response is detailed in the next section. Reading it
> is not.

It seemed somewhat duplicative to describe the exact same thing twice. It's
something I find quite frustrating in -03. I want to know what the format of
the handshake is, I don't want a precise set of steps each side must take --
that is much harder to interpret, and frankly I doubt people will code it
exactly as written.

> Why not put this as part of the algorithm? See step 31 to 51 in the current
> draft. It misses a lot of critical details present in the current draft,
> like actually invoking _fail the WebSocket connection_, defining *the
> WebSocket connection is established*, applying cookies, and other things.
>

It is. As for applying cookies, text welcome.

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Wed, 8 Dec 2010 07:43:22 -0800

2010/12/7 Adam Barth <[email-masked]>

> the remainder of the handshake as detailed by Ian.

So, we're still spinning a little bit and I would really like to make
progress. If we drop the host-obfuscation, would people be comfortable at
least putting the rest out as a -04 that we can iterate on? I would like to
be able to claim at least some progress before we all turn into pumpkins for
the end of the year :)

-Ian

---

From: Joe Mason <[email-masked]>
Date: Wed, 8 Dec 2010 10:49:17 -0500

> -----Original Message-----
> From: [email-masked] [mailto:[email-masked]] On Behalf Of
> Greg Wilkins
> Sent: Wednesday, December 08, 2010 5:11 AM
> To: Dave Cridland
> Cc: Server-Initiated HTTP
> Subject: Re: [hybi] CONNECT handshake text
> 

What information do you want to put in a Hello frame that couldn't be put into a header (-like-structure) in the CONNECT?  Why wouldn't CONNECT on a dedicated port work just as well?

Joe

---------------------------------------------------------------------
This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

---

From: John Tamplin <[email-masked]>
Date: Wed, 8 Dec 2010 10:58:23 -0500

> the argument for. As such, I think this is a good idea and should be done.

Relying on a FINAL bit being set to actually accomplish anything means
relying on frames not being fragmented.  Maybe you can require that
initial HELLO frames are not fragmented by calling them control frames
(I still think having to explicitly define which opcodes are control
frames rather than having one opcode for control frames makes this and
other things harder than it should be), but can we really be sure that
transparent proxies aren't going to search unknown requests for a
synchronization point that looks like the start of an HTTP request?
If so, then having a high bit set isn't going to stop that.

---

From: Adam Barth <[email-masked]>
Date: Wed, 8 Dec 2010 10:31:12 -0800

> www.innocentbystander.com   allowing the attacker to bypass same

Yes.

> If the server hosting these domains is WS aware, then this is not a problem.

Correct.

> any packets sent by the client from easily being interpreted as HTTP.

The issue with that approach is now you're exploring the error states
of the server rather than confining yourself to a syntax for which we
can predict the server's behavior.  It's likely that existing servers
have a wide variety of error states, and it's difficult for us to be
certain of how they behave.

> again... please feel free to swap out Upgrade for CONNECT if that is

Thanks for your willingness to compromise.

Adam

---

From: "Simon Pieters" <[email-masked]>
Date: Wed, 08 Dec 2010 19:55:05 +0100

> (or, if we decide not to mask host, then it may change slightly.)

I don't follow... The WebSocket API spec says to parse the URL passed to  
the WebSocket() constructor and invoke "establish a WebSocket connection"  
with the above parameters -- it does not pass the URL to the algorithm.

> client-side?

Yes. See http://dev.w3.org/html5/websockets/#dom-websocket

> Even if so, the HTML5 clients are not necessarily the only

We're discussing the section which covers client-side requirements, not  
the server-side requirements.

> appropriate if a plugin wished to implement the API.

I'm not saying you should reference the WebSocket API spec. I'm saying you  
should do what the current spec does and expect the input parameter  
/origin/ to be correct. See  
http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-03#section-11

> resource name header, or adding a single URL header. Adding a single URL

OK. Then you either need to change section 11 to say to pass /URL/ to  
"establish a WebSocket connection" and get the WebSocket API spec changed,  
or let the input parameters be the same as in -03 and invoke "*construct a  
WebSocket URL* from a /host/, a /port/, a /resource name/, and a /secure/  
flag" to get the URL.

> Sec-WebSocket-Protocol: chat, superchat, "my, cool, thing"

So space should be allowed in a subprotocol then? I assume backslash  
escaping is also necessary? My knee-jerk reaction is that using the above  
syntax instead of the simpler separate-with-U+0020 will lead to more bugs  
in server impls.

> proprietary extensions would certainly be allowed.

Ok.

> request for browsers, not the protocol spec.

Ok. Then I guess a list of cookies is also needed as an input parameter to  
"establish a WebSocket connection" (and section 11 changed as appropriate)  
so that the WebSocket API spec can say which cookies to pass to the  
algorithm. I'd still like the protocol spec to say that if there are  
cookies passed to the algorithm, then they must be sent.

> that is much harder to interpret, and frankly I doubt people will code it

Well at Opera we implemented it exactly as written. Browser vendors are  
often anal about interoperability these days. Having loose rules leads to  
interop problems down the road with some sites just working in the most  
popular browser and the other browsers need to reverse engineer it to  
figure out what to do to be compatible instead of just implementing the  
spec.

>> current

See -03, step 44 and step 51.

>> I haven't looked at this section.

Cheers,
-- 
Simon Pieters
Opera Software

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Wed, 8 Dec 2010 11:55:16 -0800

> On Wed, 08 Dec 2010 16:42:04 +0100, Ian Fette (イアンフェッティ) <
> We're discussing the section which covers client-side requirements, not the
> server-side requirements.

But we shouldn't make the assumption that the HTML5 spec documents the only
client, IMO.

> should do what the current spec does and expect the input parameter /origin/
> to be correct. See

Apologies. I now understand a lot of the confusion. I neglected to update
Section 11. I agree that as it stands, this is in conflict, and will fix.

> WebSocket URL* from a /host/, a /port/, a /resource name/, and a /secure/
Agreed, sorry, I neglected to update Section 11. I will ensure these two are
in sync. Whether we keep a URL or a seprate host and resource name depends a
bit on whether we go the UPGRADE+CONNECT or CONNECT route, but either way
the two sections do need to agree. Sorry I didn't understand your point the
first time around.

> syntax instead of the simpler separate-with-U+0020 will lead to more bugs in
> server impls.

It's already allowed in certain HTTP headers. The intent was to re-use
existing HTTP header parsing code rather than defining yet another format
for HTTP headers. E.g. see Pragma in HTTP. It's defined as
Pragma            = "Pragma" ":" 1#pragma-directive
pragma-directive  = "no-cache" | extension-pragma
extension-pragma  = token [ "=" ( token | quoted-string ) ]

So this basically gives a comma separated list of words or quoted strings
and browsers already have code to parse this. It seems easier to re-use this
than implement yet another set of parsing semantics.

> algorithm. I'd still like the protocol spec to say that if there are cookies
> passed to the algorithm, then they must be sent.
>
>
That seems reasonable, I will make changes to that effect.

>>> it
> popular browser and the other browsers need to reverse engineer it to figure
> out what to do to be compatible instead of just implementing the spec.
>
>
>
>>
>>>
>>>   Specifically,
>>>

---

From: Maciej Stachowiak <[email-masked]>
Date: Wed, 08 Dec 2010 11:26:38 -0800

On Dec 8, 2010, at 7:42 AM, Ian Fette (イアンフェッティ) wrote:

> On Tue, 07 
> %0CInternet-Draft           The WebSocket protocol            December 2010
> 
> 
> 
> The current draft says which bytes should be put on the wire exactly. I prefer the current draft over referencing RFC2616 since doing the latter makes many variations conforming which can cause interop problems.
> 
> 

I believe the contention was about restricting handshake parsing to reject the client handshake unless it meets very specific requirements which are tighter than the full syntax for an HTTP request.

I don't think anyone had a serious objection to restricting what the client may send to be a subset of RFC2616-compliant requests.

I believe it is actively harmful to give client implementations an extra degree of freedom here, and there is no particular benefit to the extra flexibility.

In other words, make the generation of the client handshake precise, and let the server parsing be flexible (to the degree that is compatible with security requirements).

Regards,
Maciej

---

From: Joe Mason <[email-masked]>
Date: Wed, 8 Dec 2010 15:42:28 -0500

> From: [email-masked] [mailto:[email-masked]] On Behalf Of Maciej Stachowiak
> Sent: Wednesday, December 08, 2010 2:27 PM
> To: [email-masked]
> Cc: [email-masked]
> > > The current draft says which bytes should be put on the wire exactly. I prefer the current draft over 
> > > referencing RFC2616 since doing the latter makes many variations conforming which can cause interop 
> > > problems.
> > 
> I believe the contention was about restricting handshake parsing to reject the client handshake unless it 
> meets very specific requirements which are tighter than the full syntax for an HTTP request.
>

How about spelling that out specifically in the draft?  "The handshake must send the following bytes, which form a valid HTTP request as specified by [RFC2616]"

Joe

---

From: "Pat McManus @Mozilla" <[email-masked]>
Date: Wed, 08 Dec 2010 15:47:55 -0500

On Wed, 2010-12-08 at 15:42 -0500, Joe Mason wrote:

> How about spelling that out specifically in the draft?  "The handshake
> must send the following bytes, which form a valid HTTP request as
> specified by [RFC2616]"

you can restrict what bytes the client can send, but you cannot say that
it is exactly what the WS server will receive. While this is still HTTP,
an HTTP intermediary can rearrange those bytes in any way that is HTTP
compliant (and realistically, many that are not - but are normal
expected uses of HTTP on today's Internet.).

-Patrick

-- 
http://www.getfirefox.com/

---

From: Maciej Stachowiak <[email-masked]>
Date: Wed, 08 Dec 2010 14:41:20 -0800

> expected uses of HTTP on today's Internet.).

The section we were discussing is the description of what the client must send. It doesn't talk at all about what the server should expect or how the server should process what it receives.

Regards,
Maciej

---

From: Joe Mason <[email-masked]>
Date: Wed, 8 Dec 2010 17:48:34 -0500

> From: Maciej Stachowiak [mailto:[email-masked]]
> Sent: Wednesday, December 08, 2010 5:41 PM
> To: Pat McManus @Mozilla
> Cc: Joe Mason; [email-masked]; [email-masked]
> The section we were discussing is the description of what the client
> must send. It doesn't talk at all about what the server should expect
> or how the server should process what it receives.

However, we do need to note in the server section that the handshake message may be transformed by intermediaries, so the server MUST (not SHOULD) be more lenient.

Joe

---

From: Julian Reschke <[email-masked]>
Date: Thu, 09 Dec 2010 01:05:06 +0100

On 08.12.2010 23:41, Maciej Stachowiak wrote:
> ...
> ...

Not sure why we would *want* to restrict the client to a subset of the 
HTTP syntax when sending, if the recipient will need to grok all of HTTP 
syntax anyway...

---

From: Ian Fette (イアンフェッティ) <[email-masked]>
Date: Wed, 8 Dec 2010 16:14:53 -0800

Personally, I agree on not restricting. If a client or intermediary wants to
add extra headers (e.g. user-agent, accept-language etc etc etc) I don't see
why we would want to restrict it. Even in the old protocol header order
wasn't defined. All the browsers (and server libraries) already have code to
parse headers, to the extent we aren't inventing any new header formats I
don't see why it's problematic to say "Look for the following headers".

-Ian

On Wed, Dec 8, 2010 at 4:05 PM, Julian Reschke <[email-masked]>wrote:

>> The section we were discussing is the description of what the client must
>> send. It doesn't talk at all about what the server should expect or how the
>> server should process what it receives.
>> ...
>>
>
> Not sure why we would *want* to restrict the client to a subset of the HTTP
> syntax when sending, if the recipient will need to grok all of HTTP syntax
> anyway...
>