draft-ietf-hybi-thewebsocketprotocol-17.txt   rfc6455.txt 
HyBi Working Group I. Fette Internet Engineering Task Force (IETF) I. Fette
Internet-Draft Google, Inc. Request for Comments: 6455 Google, Inc.
Intended status: Standards Track A. Melnikov Category: Standards Track A. Melnikov
Expires: April 2, 2012 Isode Ltd ISSN: 2070-1721 Isode Ltd.
September 30, 2011 December 2011
The WebSocket protocol The WebSocket Protocol
draft-ietf-hybi-thewebsocketprotocol-17
Abstract Abstract
The WebSocket protocol enables two-way communication between a client The WebSocket Protocol enables two-way communication between a client
running untrusted code running in a controlled environment to a running untrusted code in a controlled environment to a remote host
remote host that has opted-in to communications from that code. The that has opted-in to communications from that code. The security
security model used for this is the Origin-based security model model used for this is the origin-based security model commonly used
commonly used by Web browsers. The protocol consists of an opening by web browsers. The protocol consists of an opening handshake
handshake followed by basic message framing, layered over TCP. The followed by basic message framing, layered over TCP. The goal of
goal of this technology is to provide a mechanism for browser-based this technology is to provide a mechanism for browser-based
applications that need two-way communication with servers that does applications that need two-way communication with servers that does
not rely on opening multiple HTTP connections (e.g. using not rely on opening multiple HTTP connections (e.g., using
XMLHttpRequest or <iframe>s and long polling). XMLHttpRequest or <iframe>s and long polling).
Please send feedback to the hybi@ietf.org mailing list. Status of This Memo
Status of this Memo
This Internet-Draft is submitted in full conformance with the
provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering This is an Internet Standards Track document.
Task Force (IETF). Note that other groups may also distribute
working documents as Internet-Drafts. The list of current Internet-
Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months This document is a product of the Internet Engineering Task Force
and may be updated, replaced, or obsoleted by other documents at any (IETF). It represents the consensus of the IETF community. It has
time. It is inappropriate to use Internet-Drafts as reference received public review and has been approved for publication by the
material or to cite them other than as "work in progress." Internet Engineering Steering Group (IESG). Further information on
Internet Standards is available in Section 2 of RFC 5741.
This Internet-Draft will expire on April 2, 2012. Information about the current status of this document, any errata,
and how to provide feedback on it may be obtained at
http://www.rfc-editor.org/info/rfc6455.
Copyright Notice Copyright Notice
Copyright (c) 2011 IETF Trust and the persons identified as the Copyright (c) 2011 IETF Trust and the persons identified as the
document authors. All rights reserved. document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal This document is subject to BCP 78 and the IETF Trust's Legal
Provisions Relating to IETF Documents Provisions Relating to IETF Documents
(http://trustee.ietf.org/license-info) in effect on the date of (http://trustee.ietf.org/license-info) in effect on the date of
publication of this document. Please review these documents publication of this document. Please review these documents
carefully, as they describe your rights and restrictions with respect carefully, as they describe your rights and restrictions with respect
to this document. Code Components extracted from this document must to this document. Code Components extracted from this document must
include Simplified BSD License text as described in Section 4.e of include Simplified BSD License text as described in Section 4.e of
the Trust Legal Provisions and are provided without warranty as the Trust Legal Provisions and are provided without warranty as
described in the Simplified BSD License. described in the Simplified BSD License.
Table of Contents Table of Contents
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 5 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.1. Background . . . . . . . . . . . . . . . . . . . . . . . . 5 1.1. Background . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2. Protocol Overview . . . . . . . . . . . . . . . . . . . . 6 1.2. Protocol Overview . . . . . . . . . . . . . . . . . . . . 5
1.3. Opening Handshake . . . . . . . . . . . . . . . . . . . . 7 1.3. Opening Handshake . . . . . . . . . . . . . . . . . . . . 6
1.4. Closing Handshake . . . . . . . . . . . . . . . . . . . . 10 1.4. Closing Handshake . . . . . . . . . . . . . . . . . . . . 9
1.5. Design Philosophy . . . . . . . . . . . . . . . . . . . . 10 1.5. Design Philosophy . . . . . . . . . . . . . . . . . . . . 9
1.6. Security Model . . . . . . . . . . . . . . . . . . . . . . 11 1.6. Security Model . . . . . . . . . . . . . . . . . . . . . . 10
1.7. Relationship to TCP and HTTP . . . . . . . . . . . . . . . 12 1.7. Relationship to TCP and HTTP . . . . . . . . . . . . . . . 11
1.8. Establishing a Connection . . . . . . . . . . . . . . . . 12 1.8. Establishing a Connection . . . . . . . . . . . . . . . . 11
1.9. Subprotocols Using the WebSocket protocol . . . . . . . . 12 1.9. Subprotocols Using the WebSocket Protocol . . . . . . . . 12
2. Conformance Requirements . . . . . . . . . . . . . . . . . . . 14 2. Conformance Requirements . . . . . . . . . . . . . . . . . . . 12
2.1. Terminology and other conventions . . . . . . . . . . . . 14 2.1. Terminology and Other Conventions . . . . . . . . . . . . 13
3. WebSocket URIs . . . . . . . . . . . . . . . . . . . . . . . . 16 3. WebSocket URIs . . . . . . . . . . . . . . . . . . . . . . . . 14
4. Opening Handshake . . . . . . . . . . . . . . . . . . . . . . 17 4. Opening Handshake . . . . . . . . . . . . . . . . . . . . . . 14
4.1. Client Requirements . . . . . . . . . . . . . . . . . . . 17 4.1. Client Requirements . . . . . . . . . . . . . . . . . . . 14
4.2. Server-side Requirements . . . . . . . . . . . . . . . . . 22 4.2. Server-Side Requirements . . . . . . . . . . . . . . . . . 20
4.2.1. Reading the Client's Opening Handshake . . . . . . . . 23 4.2.1. Reading the Client's Opening Handshake . . . . . . . . 21
4.2.2. Sending the Server's Opening Handshake . . . . . . . . 24 4.2.2. Sending the Server's Opening Handshake . . . . . . . . 22
4.3. Collected ABNF for new header fields used in handshake . . 27 4.3. Collected ABNF for New Header Fields Used in Handshake . . 25
4.4. Supporting multiple versions of WebSocket protocol . . . . 28 4.4. Supporting Multiple Versions of WebSocket Protocol . . . . 26
5. Data Framing . . . . . . . . . . . . . . . . . . . . . . . . . 30 5. Data Framing . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 30 5.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . . 27
5.2. Base Framing Protocol . . . . . . . . . . . . . . . . . . 30 5.2. Base Framing Protocol . . . . . . . . . . . . . . . . . . 28
5.3. Client-to-Server Masking . . . . . . . . . . . . . . . . . 35 5.3. Client-to-Server Masking . . . . . . . . . . . . . . . . . 32
5.4. Fragmentation . . . . . . . . . . . . . . . . . . . . . . 36 5.4. Fragmentation . . . . . . . . . . . . . . . . . . . . . . 33
5.5. Control Frames . . . . . . . . . . . . . . . . . . . . . . 38 5.5. Control Frames . . . . . . . . . . . . . . . . . . . . . . 36
5.5.1. Close . . . . . . . . . . . . . . . . . . . . . . . . 38 5.5.1. Close . . . . . . . . . . . . . . . . . . . . . . . . 36
5.5.2. Ping . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.5.2. Ping . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.5.3. Pong . . . . . . . . . . . . . . . . . . . . . . . . . 39 5.5.3. Pong . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.6. Data Frames . . . . . . . . . . . . . . . . . . . . . . . 40 5.6. Data Frames . . . . . . . . . . . . . . . . . . . . . . . 38
5.7. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 40 5.7. Examples . . . . . . . . . . . . . . . . . . . . . . . . . 38
5.8. Extensibility . . . . . . . . . . . . . . . . . . . . . . 41 5.8. Extensibility . . . . . . . . . . . . . . . . . . . . . . 39
6. Sending and Receiving Data . . . . . . . . . . . . . . . . . . 42 6. Sending and Receiving Data . . . . . . . . . . . . . . . . . . 39
6.1. Sending Data . . . . . . . . . . . . . . . . . . . . . . . 42 6.1. Sending Data . . . . . . . . . . . . . . . . . . . . . . . 39
6.2. Receiving Data . . . . . . . . . . . . . . . . . . . . . . 42 6.2. Receiving Data . . . . . . . . . . . . . . . . . . . . . . 40
7. Closing the connection . . . . . . . . . . . . . . . . . . . . 44 7. Closing the Connection . . . . . . . . . . . . . . . . . . . . 41
7.1. Definitions . . . . . . . . . . . . . . . . . . . . . . . 44 7.1. Definitions . . . . . . . . . . . . . . . . . . . . . . . 41
7.1.1. Close the WebSocket Connection . . . . . . . . . . . . 44 7.1.1. Close the WebSocket Connection . . . . . . . . . . . . 41
7.1.2. Start the WebSocket Closing Handshake . . . . . . . . 44 7.1.2. Start the WebSocket Closing Handshake . . . . . . . . 42
7.1.3. The WebSocket Closing Handshake is Started . . . . . . 44 7.1.3. The WebSocket Closing Handshake is Started . . . . . . 42
7.1.4. The WebSocket Connection is Closed . . . . . . . . . . 45 7.1.4. The WebSocket Connection is Closed . . . . . . . . . . 42
7.1.5. The WebSocket Connection Close Code . . . . . . . . . 45 7.1.5. The WebSocket Connection Close Code . . . . . . . . . 42
7.1.6. The WebSocket Connection Close Reason . . . . . . . . 45 7.1.6. The WebSocket Connection Close Reason . . . . . . . . 43
7.1.7. Fail the WebSocket Connection . . . . . . . . . . . . 46 7.1.7. Fail the WebSocket Connection . . . . . . . . . . . . 43
7.2. Abnormal Closures . . . . . . . . . . . . . . . . . . . . 46 7.2. Abnormal Closures . . . . . . . . . . . . . . . . . . . . 44
7.2.1. Client-Initiated Closure . . . . . . . . . . . . . . . 46 7.2.1. Client-Initiated Closure . . . . . . . . . . . . . . . 44
7.2.2. Server-Initiated Closure . . . . . . . . . . . . . . . 47 7.2.2. Server-Initiated Closure . . . . . . . . . . . . . . . 44
7.2.3. Recovering From Abnormal Closure . . . . . . . . . . . 47 7.2.3. Recovering from Abnormal Closure . . . . . . . . . . . 44
7.3. Normal Closure of Connections . . . . . . . . . . . . . . 47 7.3. Normal Closure of Connections . . . . . . . . . . . . . . 45
7.4. Status Codes . . . . . . . . . . . . . . . . . . . . . . . 47 7.4. Status Codes . . . . . . . . . . . . . . . . . . . . . . . 45
7.4.1. Defined Status Codes . . . . . . . . . . . . . . . . . 48 7.4.1. Defined Status Codes . . . . . . . . . . . . . . . . . 45
7.4.2. Reserved Status Code Ranges . . . . . . . . . . . . . 49 7.4.2. Reserved Status Code Ranges . . . . . . . . . . . . . 47
8. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 51 8. Error Handling . . . . . . . . . . . . . . . . . . . . . . . . 48
8.1. Handling Errors in UTF-8 Encoded Data . . . . . . . . . . 51 8.1. Handling Errors in UTF-8-Encoded Data . . . . . . . . . . 48
9. Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 52 9. Extensions . . . . . . . . . . . . . . . . . . . . . . . . . . 48
9.1. Negotiating Extensions . . . . . . . . . . . . . . . . . . 52 9.1. Negotiating Extensions . . . . . . . . . . . . . . . . . . 48
9.2. Known Extensions . . . . . . . . . . . . . . . . . . . . . 53 9.2. Known Extensions . . . . . . . . . . . . . . . . . . . . . 50
10. Security Considerations . . . . . . . . . . . . . . . . . . . 54 10. Security Considerations . . . . . . . . . . . . . . . . . . . 50
10.1. Non-Browser Clients . . . . . . . . . . . . . . . . . . . 54 10.1. Non-Browser Clients . . . . . . . . . . . . . . . . . . . 50
10.2. Origin Considerations . . . . . . . . . . . . . . . . . . 54 10.2. Origin Considerations . . . . . . . . . . . . . . . . . . 50
10.3. Attacks On Infrastructure (Masking) . . . . . . . . . . . 55 10.3. Attacks On Infrastructure (Masking) . . . . . . . . . . . 51
10.4. Implementation-Specific Limits . . . . . . . . . . . . . . 56 10.4. Implementation-Specific Limits . . . . . . . . . . . . . . 52
10.5. WebSocket client authentication . . . . . . . . . . . . . 56 10.5. WebSocket Client Authentication . . . . . . . . . . . . . 53
10.6. Connection confidentiality and integrity . . . . . . . . . 57 10.6. Connection Confidentiality and Integrity . . . . . . . . . 53
10.7. Handling of invalid data . . . . . . . . . . . . . . . . . 57 10.7. Handling of Invalid Data . . . . . . . . . . . . . . . . . 53
10.8. Use of SHA-1 by the WebSocket handshake . . . . . . . . . 57 10.8. Use of SHA-1 by the WebSocket Handshake . . . . . . . . . 54
11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 59 11. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 54
11.1. Registration of new URI Schemes . . . . . . . . . . . . . 59 11.1. Registration of New URI Schemes . . . . . . . . . . . . . 54
11.1.1. Registration of "ws" Scheme . . . . . . . . . . . . . 59 11.1.1. Registration of "ws" Scheme . . . . . . . . . . . . . 54
11.1.2. Registration of "wss" Scheme . . . . . . . . . . . . . 60 11.1.2. Registration of "wss" Scheme . . . . . . . . . . . . . 55
11.2. Registration of the "WebSocket" HTTP Upgrade Keyword . . . 61 11.2. Registration of the "WebSocket" HTTP Upgrade Keyword . . . 56
11.3. Registration of new HTTP Header Fields . . . . . . . . . . 61 11.3. Registration of New HTTP Header Fields . . . . . . . . . . 57
11.3.1. Sec-WebSocket-Key . . . . . . . . . . . . . . . . . . 62 11.3.1. Sec-WebSocket-Key . . . . . . . . . . . . . . . . . . 57
11.3.2. Sec-WebSocket-Extensions . . . . . . . . . . . . . . . 62 11.3.2. Sec-WebSocket-Extensions . . . . . . . . . . . . . . . 58
11.3.3. Sec-WebSocket-Accept . . . . . . . . . . . . . . . . . 63 11.3.3. Sec-WebSocket-Accept . . . . . . . . . . . . . . . . . 58
11.3.4. Sec-WebSocket-Protocol . . . . . . . . . . . . . . . . 64 11.3.4. Sec-WebSocket-Protocol . . . . . . . . . . . . . . . . 59
11.3.5. Sec-WebSocket-Version . . . . . . . . . . . . . . . . 64 11.3.5. Sec-WebSocket-Version . . . . . . . . . . . . . . . . 60
11.4. WebSocket Extension Name Registry . . . . . . . . . . . . 65 11.4. WebSocket Extension Name Registry . . . . . . . . . . . . 61
11.5. WebSocket Subprotocol Name Registry . . . . . . . . . . . 66 11.5. WebSocket Subprotocol Name Registry . . . . . . . . . . . 61
11.6. WebSocket Version Number Registry . . . . . . . . . . . . 67 11.6. WebSocket Version Number Registry . . . . . . . . . . . . 62
11.7. WebSocket Close Code Number Registry . . . . . . . . . . . 68 11.7. WebSocket Close Code Number Registry . . . . . . . . . . . 64
11.8. WebSocket Opcode Registry . . . . . . . . . . . . . . . . 70 11.8. WebSocket Opcode Registry . . . . . . . . . . . . . . . . 65
11.9. WebSocket Framing Header Bits Registry . . . . . . . . . . 71 11.9. WebSocket Framing Header Bits Registry . . . . . . . . . . 66
12. Using the WebSocket protocol from Other Specifications . . . . 72 12. Using the WebSocket Protocol from Other Specifications . . . . 66
13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 73 13. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . 67
14. References . . . . . . . . . . . . . . . . . . . . . . . . . . 74 14. References . . . . . . . . . . . . . . . . . . . . . . . . . . 68
14.1. Normative References . . . . . . . . . . . . . . . . . . . 74 14.1. Normative References . . . . . . . . . . . . . . . . . . . 68
14.2. Informative References . . . . . . . . . . . . . . . . . . 75 14.2. Informative References . . . . . . . . . . . . . . . . . . 69
Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . . 77
1. Introduction 1. Introduction
1.1. Background 1.1. Background
_This section is non-normative._ _This section is non-normative._
Historically, creating Web applications that need bidirectional Historically, creating web applications that need bidirectional
communication between a client and a server (e.g., instant messaging communication between a client and a server (e.g., instant messaging
and gaming applications) has required an abuse of HTTP to poll the and gaming applications) has required an abuse of HTTP to poll the
server for updates while sending upstream notifications as distinct server for updates while sending upstream notifications as distinct
HTTP calls.[RFC6202] HTTP calls [RFC6202].
This results in a variety of problems: This results in a variety of problems:
o The server is forced to use a number of different underlying TCP o The server is forced to use a number of different underlying TCP
connections for each client: one for sending information to the connections for each client: one for sending information to the
client, and a new one for each incoming message. client and a new one for each incoming message.
o The wire protocol has a high overhead, with each client-to-server o The wire protocol has a high overhead, with each client-to-server
message having an HTTP header. message having an HTTP header.
o The client-side script is forced to maintain a mapping from the o The client-side script is forced to maintain a mapping from the
outgoing connections to the incoming connection to track replies. outgoing connections to the incoming connection to track replies.
A simpler solution would be to use a single TCP connection for A simpler solution would be to use a single TCP connection for
traffic in both directions. This is what the WebSocket protocol traffic in both directions. This is what the WebSocket Protocol
provides. Combined with the WebSocket API, it provides an provides. Combined with the WebSocket API [WSAPI], it provides an
alternative to HTTP polling for two-way communication from a Web page alternative to HTTP polling for two-way communication from a web page
to a remote server. [WSAPI] to a remote server.
The same technique can be used for a variety of Web applications: The same technique can be used for a variety of web applications:
games, stock tickers, multiuser applications with simultaneous games, stock tickers, multiuser applications with simultaneous
editing, user interfaces exposing server-side services in real time, editing, user interfaces exposing server-side services in real time,
etc. etc.
The WebSocket protocol is designed to supersede existing The WebSocket Protocol is designed to supersede existing
bidirectional communication technologies which use HTTP as a bidirectional communication technologies that use HTTP as a transport
transport layer to benefit from existing infrastructure (proxies, layer to benefit from existing infrastructure (proxies, filtering,
filtering, authentication). Such technologies were implemented as authentication). Such technologies were implemented as trade-offs
trade-offs between efficiency and reliability because HTTP was not between efficiency and reliability because HTTP was not initially
initially meant to be used for bidirectional communication (see meant to be used for bidirectional communication (see [RFC6202] for
[RFC6202] for further discussion). The WebSocket protocol attempts further discussion). The WebSocket Protocol attempts to address the
to address the goals of existing bidirectional HTTP technologies in goals of existing bidirectional HTTP technologies in the context of
the context of the existing HTTP infrastructure; as such, it is the existing HTTP infrastructure; as such, it is designed to work
designed to work over HTTP ports 80 and 443 as well as to support over HTTP ports 80 and 443 as well as to support HTTP proxies and
HTTP proxies and intermediaries, even if this implies some complexity intermediaries, even if this implies some complexity specific to the
specific to the current environment. However, the design does not current environment. However, the design does not limit WebSocket to
limit WebSocket to HTTP, and future implementations could use a HTTP, and future implementations could use a simpler handshake over a
simpler handshake over a dedicated port without revinventing the dedicated port without reinventing the entire protocol. This last
entire protocol. This last point is important because the traffic point is important because the traffic patterns of interactive
patterns of interactive messaging do not closely match standard HTTP messaging do not closely match standard HTTP traffic and can induce
traffic and can induce unusual loads on some components. unusual loads on some components.
1.2. Protocol Overview 1.2. Protocol Overview
_This section is non-normative._ _This section is non-normative._
The protocol has two parts: a handshake, and then the data transfer. The protocol has two parts: a handshake and the data transfer.
The handshake from the client looks as follows: The handshake from the client looks as follows:
GET /chat HTTP/1.1 GET /chat HTTP/1.1
Host: server.example.com Host: server.example.com
Upgrade: websocket Upgrade: websocket
Connection: Upgrade Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Protocol: chat, superchat
skipping to change at page 6, line 38 skipping to change at page 5, line 38
HTTP/1.1 101 Switching Protocols HTTP/1.1 101 Switching Protocols
Upgrade: websocket Upgrade: websocket
Connection: Upgrade Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat Sec-WebSocket-Protocol: chat
The leading line from the client follows the Request-Line format. The leading line from the client follows the Request-Line format.
The leading line from the server follows the Status-Line format. The The leading line from the server follows the Status-Line format. The
Request-Line and Status-Line productions are defined in [RFC2616]. Request-Line and Status-Line productions are defined in [RFC2616].
After the leading line in both cases come an unordered set of header An unordered set of header fields comes after the leading line in
fields. The meaning of these header fields is specified in Section 4 both cases. The meaning of these header fields is specified in
of this document. Additional header fields may also be present, such Section 4 of this document. Additional header fields may also be
as cookies [RFC6265]. The format and parsing of headers is as present, such as cookies [RFC6265]. The format and parsing of
defined in [RFC2616]. headers is as defined in [RFC2616].
Once the client and server have both sent their handshakes, and if Once the client and server have both sent their handshakes, and if
the handshake was successful, then the data transfer part starts. the handshake was successful, then the data transfer part starts.
This is a two-way communication channel where each side can, This is a two-way communication channel where each side can,
independently from the other, send data at will. independently from the other, send data at will.
Clients and servers, after a successful handshake, transfer data back After a successful handshake, clients and servers transfer data back
and forth in conceptual units referred to in this specification as and forth in conceptual units referred to in this specification as
"messages". On the wire a message is composed of one or more frames. "messages". On the wire, a message is composed of one or more
The WebSocket message does not necessarily correspond to a particular frames. The WebSocket message does not necessarily correspond to a
network layer framing, as a fragmented message may be coalesced or particular network layer framing, as a fragmented message may be
split by an intermediary. coalesced or split by an intermediary.
A frame has an associated type. Each frame belonging to the same A frame has an associated type. Each frame belonging to the same
message contain the same type of data. Broadly speaking, there are message contains the same type of data. Broadly speaking, there are
types for textual data, which is interpreted as UTF-8 [RFC3629] text, types for textual data (which is interpreted as UTF-8 [RFC3629]
binary data (whose interpretation is left up to the application), and text), binary data (whose interpretation is left up to the
control frames, which are not intended to carry data for the application), and control frames (which are not intended to carry
application, but instead for protocol-level signaling, such as to data for the application but instead for protocol-level signaling,
signal that the connection should be closed. This version of the such as to signal that the connection should be closed). This
protocol defines six frame types and leaves ten reserved for future version of the protocol defines six frame types and leaves ten
use. reserved for future use.
1.3. Opening Handshake 1.3. Opening Handshake
_This section is non-normative._ _This section is non-normative._
The opening handshake is intended to be compatible with HTTP-based The opening handshake is intended to be compatible with HTTP-based
server-side software and intermediaries, so that a single port can be server-side software and intermediaries, so that a single port can be
used by both HTTP clients talking to that server and WebSocket used by both HTTP clients talking to that server and WebSocket
clients talking to that server. To this end, the WebSocket client's clients talking to that server. To this end, the WebSocket client's
handshake is an HTTP Upgrade request: handshake is an HTTP Upgrade request:
skipping to change at page 7, line 47 skipping to change at page 6, line 46
In compliance with [RFC2616], header fields in the handshake may be In compliance with [RFC2616], header fields in the handshake may be
sent by the client in any order, so the order in which different sent by the client in any order, so the order in which different
header fields are received is not significant. header fields are received is not significant.
The "Request-URI" of the GET method [RFC2616] is used to identify the The "Request-URI" of the GET method [RFC2616] is used to identify the
endpoint of the WebSocket connection, both to allow multiple domains endpoint of the WebSocket connection, both to allow multiple domains
to be served from one IP address and to allow multiple WebSocket to be served from one IP address and to allow multiple WebSocket
endpoints to be served by a single server. endpoints to be served by a single server.
The client includes the hostname in the Host header field of its The client includes the hostname in the |Host| header field of its
handshake as per [RFC2616], so that both the client and the server handshake as per [RFC2616], so that both the client and the server
can verify that they agree on which host is in use. can verify that they agree on which host is in use.
Additional header fields are used to select options in the WebSocket Additional header fields are used to select options in the WebSocket
protocol. Typical options available in this version are the Protocol. Typical options available in this version are the
subprotocol selector (|Sec-WebSocket-Protocol|), list of extensions subprotocol selector (|Sec-WebSocket-Protocol|), list of extensions
support by the client (|Sec-WebSocket-Extensions|), |Origin| header support by the client (|Sec-WebSocket-Extensions|), |Origin| header
field, etc. The |Sec-WebSocket-Protocol| request-header field can be field, etc. The |Sec-WebSocket-Protocol| request-header field can be
used to indicate what subprotocols (application-level protocols used to indicate what subprotocols (application-level protocols
layered over the WebSocket protocol) are acceptable to the client. layered over the WebSocket Protocol) are acceptable to the client.
The server selects one or none of the acceptable protocols and echoes The server selects one or none of the acceptable protocols and echoes
that value in its handshake to indicate that it has selected that that value in its handshake to indicate that it has selected that
protocol. protocol.
Sec-WebSocket-Protocol: chat Sec-WebSocket-Protocol: chat
The |Origin| header field [I-D.ietf-websec-origin] is used to protect The |Origin| header field [RFC6454] is used to protect against
against unauthorized cross-origin use of a WebSocket server by unauthorized cross-origin use of a WebSocket server by scripts using
scripts using the |WebSocket| API in a Web browser. The server is the WebSocket API in a web browser. The server is informed of the
informed of the script origin generating the WebSocket connection script origin generating the WebSocket connection request. If the
request. If the server does not wish to accept connections from this server does not wish to accept connections from this origin, it can
origin, it can choose to reject the connection by sending an choose to reject the connection by sending an appropriate HTTP error
appropriate HTTP error code. This header field is sent by browser code. This header field is sent by browser clients; for non-browser
clients, for non-browser clients this header field may be sent if it clients, this header field may be sent if it makes sense in the
makes sense in the context of those clients. context of those clients.
Finally, the server has to prove to the client that it received the Finally, the server has to prove to the client that it received the
client's WebSocket handshake, so that the server doesn't accept client's WebSocket handshake, so that the server doesn't accept
connections that are not WebSocket connections. This prevents an connections that are not WebSocket connections. This prevents an
attacker from tricking a WebSocket server by sending it carefully- attacker from tricking a WebSocket server by sending it carefully
crafted packets using |XMLHttpRequest| [XMLHttpRequest] or a |form| crafted packets using XMLHttpRequest [XMLHttpRequest] or a form
submission. submission.
To prove that the handshake was received, the server has to take two 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 pieces of information and combine them to form a response. The first
piece of information comes from the |Sec-WebSocket-Key| header field piece of information comes from the |Sec-WebSocket-Key| header field
in the client handshake: in the client handshake:
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
For this header field, the server has to take the value (as present For this header field, the server has to take the value (as present
in the header field, e.g. the base64-encoded [RFC4648] version minus in the header field, e.g., the base64-encoded [RFC4648] version minus
any leading and trailing whitespace), and concatenate this with the any leading and trailing whitespace) and concatenate this with the
Globally Unique Identifier (GUID, [RFC4122]) "258EAFA5-E914-47DA- Globally Unique Identifier (GUID, [RFC4122]) "258EAFA5-E914-47DA-
95CA-C5AB0DC85B11" in string form, which is unlikely to be used by 95CA-C5AB0DC85B11" in string form, which is unlikely to be used by
network endpoints that do not understand the WebSocket protocol. A network endpoints that do not understand the WebSocket Protocol. A
SHA-1 hash (160 bits), base64-encoded (see Section 4 of [RFC4648]), SHA-1 hash (160 bits) [FIPS.180-3], base64-encoded (see Section 4 of
of this concatenation is then returned in the server's handshake [RFC4648]), of this concatenation is then returned in the server's
[FIPS.180-2.2002]. handshake.
Concretely, if as in the example above, |Sec-WebSocket-Key| header Concretely, if as in the example above, the |Sec-WebSocket-Key|
field had the value "dGhlIHNhbXBsZSBub25jZQ==", the server would header field had the value "dGhlIHNhbXBsZSBub25jZQ==", the server
concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form would concatenate the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA- to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
C5AB0DC85B11". The server would then take the SHA-1 hash of this, 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 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 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value is
then base64-encoded (see Section 4 of [RFC4648]), to give the value then base64-encoded (see Section 4 of [RFC4648]), to give the value
"s3pPLMBiTxaQ9kYGzzhZRbK+xOo=". This value would then be echoed in "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=". This value would then be echoed in
the |Sec-WebSocket-Accept| header field. the |Sec-WebSocket-Accept| header field.
The handshake from the server is much simpler than the client The handshake from the server is much simpler than the client
handshake. The first line is an HTTP Status-Line, with the status handshake. The first line is an HTTP Status-Line, with the status
code 101: code 101:
HTTP/1.1 101 Switching Protocols HTTP/1.1 101 Switching Protocols
Any status code other than 101 indicates that the WebSocket handshake Any status code other than 101 indicates that the WebSocket handshake
has not completed, and that the semantics of HTTP still apply. The has not completed and that the semantics of HTTP still apply. The
headers follow the status code. headers follow the status code.
The |Connection| and |Upgrade| header fields complete the HTTP The |Connection| and |Upgrade| header fields complete the HTTP
Upgrade. The |Sec-WebSocket-Accept| header field indicates whether Upgrade. The |Sec-WebSocket-Accept| header field indicates whether
the server is willing to accept the connection. If present, this the server is willing to accept the connection. If present, this
header field must include a hash of the client's nonce sent in |Sec- header field must include a hash of the client's nonce sent in
WebSocket-Key| along with a predefined GUID. Any other value must |Sec-WebSocket-Key| along with a predefined GUID. Any other value
not be interpreted as an acceptance of the connection by the server. must not be interpreted as an acceptance of the connection by the
server.
HTTP/1.1 101 Switching Protocols HTTP/1.1 101 Switching Protocols
Upgrade: websocket Upgrade: websocket
Connection: Upgrade Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
These fields are checked by the |WebSocket| client for scripted These fields are checked by the WebSocket client for scripted pages.
pages. If the |Sec-WebSocket-Accept| value does not match the If the |Sec-WebSocket-Accept| value does not match the expected
expected value, or if the header field is missing, or if the HTTP value, if the header field is missing, or if the HTTP status code is
status code is not 101, the connection will not be established and not 101, the connection will not be established, and WebSocket frames
WebSocket frames will not be sent. will not be sent.
Option fields can also be included. In this version of the protocol, Option fields can also be included. In this version of the protocol,
the main option field is |Sec-WebSocket-Protocol|, which indicates the main option field is |Sec-WebSocket-Protocol|, which indicates
the subprotocol that the server has selected. WebSocket clients the subprotocol that the server has selected. WebSocket clients
verify that the server included one of the values as was specified in verify that the server included one of the values that was specified
the WebSocket client's handshake. A server that speaks multiple in the WebSocket client's handshake. A server that speaks multiple
subprotocols has to make sure it selects one based on the client's subprotocols has to make sure it selects one based on the client's
handshake and specifies it in its handshake. handshake and specifies it in its handshake.
Sec-WebSocket-Protocol: chat Sec-WebSocket-Protocol: chat
The server can also set cookie-related option fields to _set_ The server can also set cookie-related option fields to _set_
cookies, as described in [RFC6265]. cookies, as described in [RFC6265].
1.4. Closing Handshake 1.4. Closing Handshake
_This section is non-normative._ _This section is non-normative._
The closing handshake is far simpler than the opening handshake. The closing handshake is far simpler than the opening handshake.
Either peer can send a control frame with data containing a specified Either peer can send a control frame with data containing a specified
control sequence to begin the closing handshake (detailed in control sequence to begin the closing handshake (detailed in
Section 5.5.1). Upon receiving such a frame, the other peer sends a Section 5.5.1). Upon receiving such a frame, the other peer sends a
close frame in response, if it hasn't already sent one. Upon Close frame in response, if it hasn't already sent one. Upon
receiving _that_ control frame, the first peer then closes the receiving _that_ control frame, the first peer then closes the
connection, safe in the knowledge that no further data is connection, safe in the knowledge that no further data is
forthcoming. forthcoming.
After sending a control frame indicating the connection should be After sending a control frame indicating the connection should be
closed, a peer does not send any further data; after receiving a closed, a peer does not send any further data; after receiving a
control frame indicating the connection should be closed, a peer control frame indicating the connection should be closed, a peer
discards any further data received. discards any further data received.
It is safe for both peers to initiate this handshake simultaneously. It is safe for both peers to initiate this handshake simultaneously.
The closing handshake is intended to complement the TCP closing The closing handshake is intended to complement the TCP closing
handshake (FIN/ACK), on the basis that the TCP closing handshake is handshake (FIN/ACK), on the basis that the TCP closing handshake is
not always reliable end-to-end, especially in the presence of not always reliable end-to-end, especially in the presence of
intercepting proxies and other intermediaries. intercepting proxies and other intermediaries.
By sending a close frame and waiting for a close frame in response, By sending a Close frame and waiting for a Close frame in response,
certain cases are avoided where data may be unnecessarily lost. For certain cases are avoided where data may be unnecessarily lost. For
instance, on some platforms, if a socket is closed with data in the instance, on some platforms, if a socket is closed with data in the
receive queue, a RST packet is sent, which will then cause recv() to receive queue, a RST packet is sent, which will then cause recv() to
fail for the party that received the RST, even if there was data fail for the party that received the RST, even if there was data
waiting to be read. waiting to be read.
1.5. Design Philosophy 1.5. Design Philosophy
_This section is non-normative._ _This section is non-normative._
The WebSocket protocol is designed on the principle that there should The WebSocket Protocol is designed on the principle that there should
be minimal framing (the only framing that exists is to make the be minimal framing (the only framing that exists is to make the
protocol frame-based instead of stream-based, and to support a protocol frame-based instead of stream-based and to support a
distinction between Unicode text and binary frames). It is expected distinction between Unicode text and binary frames). It is expected
that metadata would be layered on top of WebSocket by the application that metadata would be layered on top of WebSocket by the application
layer, in the same way that metadata is layered on top of TCP by the layer, in the same way that metadata is layered on top of TCP by the
application layer (e.g., HTTP). application layer (e.g., HTTP).
Conceptually, WebSocket is really just a layer on top of TCP that Conceptually, WebSocket is really just a layer on top of TCP that
does the following: does the following:
o adds a Web "origin"-based security model for browsers o adds a web origin-based security model for browsers
o adds an addressing and protocol naming mechanism to support o adds an addressing and protocol naming mechanism to support
multiple services on one port and multiple host names on one IP multiple services on one port and multiple host names on one IP
address; address
o layers a framing mechanism on top of TCP to get back to the IP o layers a framing mechanism on top of TCP to get back to the IP
packet mechanism that TCP is built on, but without length limits packet mechanism that TCP is built on, but without length limits
o includes an additional closing handshake in-band that is designed o includes an additional closing handshake in-band that is designed
to work in the presence of proxies and other intermediaries to work in the presence of proxies and other intermediaries
Other than that, WebSocket adds nothing. Basically it is intended to Other than that, WebSocket adds nothing. Basically it is intended to
be as close to just exposing raw TCP to script as possible given the be as close to just exposing raw TCP to script as possible given the
constraints of the Web. It's also designed in such a way that its constraints of the Web. It's also designed in such a way that its
servers can share a port with HTTP servers, by having its handshake servers can share a port with HTTP servers, by having its handshake
be a valid HTTP Upgrade request mechanism also. One could be a valid HTTP Upgrade request. One could conceptually use other
conceptually use other protocols to establish client-server protocols to establish client-server messaging, but the intent of
messaging, but the intent of WebSockets was to provide a relatively WebSockets is to provide a relatively simple protocol that can
simple protocol that can coexist with HTTP and deployed HTTP coexist with HTTP and deployed HTTP infrastructure (such as proxies)
infrastructure (such as proxies) that is as close to TCP as is safe and that is as close to TCP as is safe for use with such
for use with such infrastructure given security considerations, with infrastructure given security considerations, with targeted additions
targeted additions to simplify usage and make simple things simple to simplify usage and keep simple things simple (such as the addition
(such as the addition of message semantics). of message semantics).
The protocol is intended to be extensible; future versions will The protocol is intended to be extensible; future versions will
likely introduce additional concepts such as multiplexing. likely introduce additional concepts such as multiplexing.
1.6. Security Model 1.6. Security Model
_This section is non-normative._ _This section is non-normative._
The WebSocket protocol uses the origin model used by Web browsers to The WebSocket Protocol uses the origin model used by web browsers to
restrict which Web pages can contact a WebSocket server when the restrict which web pages can contact a WebSocket server when the
WebSocket protocol is used from a Web page. Naturally, when the WebSocket Protocol is used from a web page. Naturally, when the
WebSocket protocol is used by a dedicated client directly (i.e. not WebSocket Protocol is used by a dedicated client directly (i.e., not
from a Web page through a Web browser), the origin model is not from a web page through a web browser), the origin model is not
useful, as the client can provide any arbitrary origin string. useful, as the client can provide any arbitrary origin string.
This protocol is intended to fail to establish a connection with This protocol is intended to fail to establish a connection with
servers of pre-existing protocols like SMTP [RFC5321] and HTTP, while servers of pre-existing protocols like SMTP [RFC5321] and HTTP, while
allowing HTTP servers to opt-in to supporting this protocol if allowing HTTP servers to opt-in to supporting this protocol if
desired. This is achieved by having a strict and elaborate desired. This is achieved by having a strict and elaborate handshake
handshake, and by limiting the data that can be inserted into the and by limiting the data that can be inserted into the connection
connection before the handshake is finished (thus limiting how much before the handshake is finished (thus limiting how much the server
the server can be influenced). can be influenced).
It is similarly intended to fail to establish a connection when data It is similarly intended to fail to establish a connection when data
from other protocols, especially HTTP, is sent to a WebSocket server, from other protocols, especially HTTP, is sent to a WebSocket server,
for example as might happen if an HTML |form| were submitted to a for example, as might happen if an HTML "form" were submitted to a
WebSocket server. This is primarily achieved by requiring that the WebSocket server. This is primarily achieved by requiring that the
server prove that it read the handshake, which it can only do if the server prove that it read the handshake, which it can only do if the
handshake contains the appropriate parts which themselves can only be handshake contains the appropriate parts, which can only be sent by a
sent by a WebSocket handshake. In particular, at the time of writing WebSocket client. In particular, at the time of writing of this
of this specification, fields starting with |Sec-| cannot be set by specification, fields starting with |Sec-| cannot be set by an
an attacker from a Web browser using only HTML and JavaScript APIs attacker from a web browser using only HTML and JavaScript APIs such
such as |XMLHttpRequest| [XMLHttpRequest]. as XMLHttpRequest [XMLHttpRequest].
1.7. Relationship to TCP and HTTP 1.7. Relationship to TCP and HTTP
_This section is non-normative._ _This section is non-normative._
The WebSocket protocol is an independent TCP-based protocol. Its The WebSocket Protocol is an independent TCP-based protocol. Its
only relationship to HTTP is that its handshake is interpreted by only relationship to HTTP is that its handshake is interpreted by
HTTP servers as an Upgrade request. HTTP servers as an Upgrade request.
By default the WebSocket protocol uses port 80 for regular WebSocket By default, the WebSocket Protocol uses port 80 for regular WebSocket
connections and port 443 for WebSocket connections tunneled over TLS connections and port 443 for WebSocket connections tunneled over
[RFC2818]. Transport Layer Security (TLS) [RFC2818].
1.8. Establishing a Connection 1.8. Establishing a Connection
_This section is non-normative._ _This section is non-normative._
When a connection is to be made to a port that is shared by an HTTP When a connection is to be made to a port that is shared by an HTTP
server (a situation that is quite likely to occur with traffic to server (a situation that is quite likely to occur with traffic to
ports 80 and 443), the connection will appear to the HTTP server to ports 80 and 443), the connection will appear to the HTTP server to
be a regular GET request with an Upgrade offer. In relatively simple be a regular GET request with an Upgrade offer. In relatively simple
setups with just one IP address and a single server for all traffic setups with just one IP address and a single server for all traffic
to a single hostname, this might allow a practical way for systems to a single hostname, this might allow a practical way for systems
based on the WebSocket protocol to be deployed. In more elaborate based on the WebSocket Protocol to be deployed. In more elaborate
setups (e.g. with load balancers and multiple servers), a dedicated setups (e.g., with load balancers and multiple servers), a dedicated
set of hosts for WebSocket connections separate from the HTTP servers set of hosts for WebSocket connections separate from the HTTP servers
is probably easier to manage. At the time of writing of this is probably easier to manage. At the time of writing of this
specification, it should be noted that connections on port 80 and 443 specification, it should be noted that connections on ports 80 and
have significantly different success rates, with connections on port 443 have significantly different success rates, with connections on
443 being significantly more likely to succeed, though this may port 443 being significantly more likely to succeed, though this may
change with time. change with time.
1.9. Subprotocols Using the WebSocket protocol 1.9. Subprotocols Using the WebSocket Protocol
_This section is non-normative._ _This section is non-normative._
The client can request that the server use a specific subprotocol by The client can request that the server use a specific subprotocol by
including the |Sec-WebSocket-Protocol| field in its handshake. If it including the |Sec-WebSocket-Protocol| field in its handshake. If it
is specified, the server needs to include the same field and one of is specified, the server needs to include the same field and one of
the selected subprotocol values in its response for the connection to the selected subprotocol values in its response for the connection to
be established. be established.
These subprotocol names should be registered as per Section 11.5. To These subprotocol names should be registered as per Section 11.5. To
avoid potential collisions, it is recommended to use names that avoid potential collisions, it is recommended to use names that
contain the ASCII version of the domain name of the subprotocol's contain the ASCII version of the domain name of the subprotocol's
originator. For example, if Example Corporation were to create a originator. For example, if Example Corporation were to create a
skipping to change at page 13, line 21 skipping to change at page 12, line 26
avoid potential collisions, it is recommended to use names that avoid potential collisions, it is recommended to use names that
contain the ASCII version of the domain name of the subprotocol's contain the ASCII version of the domain name of the subprotocol's
originator. For example, if Example Corporation were to create a originator. For example, if Example Corporation were to create a
Chat subprotocol to be implemented by many servers around the Web, Chat subprotocol to be implemented by many servers around the Web,
they could name it "chat.example.com". If the Example Organization they could name it "chat.example.com". If the Example Organization
called their competing subprotocol "chat.example.org", then the two called their competing subprotocol "chat.example.org", then the two
subprotocols could be implemented by servers simultaneously, with the subprotocols could be implemented by servers simultaneously, with the
server dynamically selecting which subprotocol to use based on the server dynamically selecting which subprotocol to use based on the
value sent by the client. value sent by the client.
Subprotocols can be versioned in backwards-incompatible ways by Subprotocols can be versioned in backward-incompatible ways by
changing the subprotocol name, e.g. going from "bookings.example.net" changing the subprotocol name, e.g., going from
to "v2.bookings.example.net". These subprotocols would be considered "bookings.example.net" to "v2.bookings.example.net". These
completely separate by WebSocket clients. Backwards-compatible subprotocols would be considered completely separate by WebSocket
versioning can be implemented by reusing the same subprotocol string clients. Backward-compatible versioning can be implemented by
but carefully designing the actual subprotocol to support this kind reusing the same subprotocol string but carefully designing the
of extensibility. actual subprotocol to support this kind of extensibility.
2. Conformance Requirements 2. Conformance Requirements
All diagrams, examples, and notes in this specification are non- All diagrams, examples, and notes in this specification are non-
normative, as are all sections explicitly marked non-normative. normative, as are all sections explicitly marked non-normative.
Everything else in this specification is normative. Everything else in this specification is normative.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in RFC2119. [RFC2119] document are to be interpreted as described in [RFC2119].
Requirements phrased in the imperative as part of algorithms (such as Requirements phrased in the imperative as part of algorithms (such as
"strip any leading space characters" or "return false and abort these "strip any leading space characters" or "return false and abort these
steps") are to be interpreted with the meaning of the key word steps") are to be interpreted with the meaning of the key word
("must", "should", "may", etc) used in introducing the algorithm. ("MUST", "SHOULD", "MAY", etc.) used in introducing the algorithm.
Conformance requirements phrased as algorithms or specific steps MAY Conformance requirements phrased as algorithms or specific steps MAY
be implemented in any manner, so long as the end result is be implemented in any manner, so long as the end result is
equivalent. (In particular, the algorithms defined in this equivalent. (In particular, the algorithms defined in this
specification are intended to be easy to follow, and not intended to specification are intended to be easy to follow and not intended to
be performant.) be performant.)
2.1. Terminology and other conventions 2.1. Terminology and Other Conventions
_ASCII_ shall mean the character-encoding scheme defined in _ASCII_ shall mean the character-encoding scheme defined in
[ANSI.X3-4.1986]. [ANSI.X3-4.1986].
This document makes reference to UTF-8 values and uses UTF-8 This document makes reference to UTF-8 values and uses UTF-8
notational formats as defined in STD 63 [RFC3629]. notational formats as defined in STD 63 [RFC3629].
Key Terms such as named algorithms or definitions are indicated like Key terms such as named algorithms or definitions are indicated like
_this_. _this_.
Names of header fields or variables are indicated like |this|. Names of header fields or variables are indicated like |this|.
Variable values are indicated like /this/. Variable values are indicated like /this/.
This document references the procedure to _Fail the WebSocket This document references the procedure to _Fail the WebSocket
Connection_. This procedure is defined in Section 7.1.7. Connection_. This procedure is defined in Section 7.1.7.
_Converting a string to ASCII lowercase_ means replacing all _Converting a string to ASCII lowercase_ means replacing all
characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER characters in the range U+0041 to U+005A (i.e., LATIN CAPITAL LETTER
A to LATIN CAPITAL LETTER Z) with the corresponding characters in the A to LATIN CAPITAL LETTER Z) with the corresponding characters in the
range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL range U+0061 to U+007A (i.e., LATIN SMALL LETTER A to LATIN SMALL
LETTER Z). LETTER Z).
Comparing two strings in an _ASCII case-insensitive_ manner means Comparing two strings in an _ASCII case-insensitive_ manner means
comparing them exactly, code point for code point, except that the comparing them exactly, code point for code point, except that the
characters in the range U+0041 to U+005A (i.e. LATIN CAPITAL LETTER characters in the range U+0041 to U+005A (i.e., LATIN CAPITAL LETTER
A to LATIN CAPITAL LETTER Z) and the corresponding characters in the A to LATIN CAPITAL LETTER Z) and the corresponding characters in the
range U+0061 to U+007A (i.e. LATIN SMALL LETTER A to LATIN SMALL range U+0061 to U+007A (i.e., LATIN SMALL LETTER A to LATIN SMALL
LETTER Z) are considered to also match. LETTER Z) are considered to also match.
The term "URI" is used in this document as defined in [RFC3986]. The term "URI" is used in this document as defined in [RFC3986].
When an implementation is required to _send_ data as part of the When an implementation is required to _send_ data as part of the
WebSocket protocol, the implementation MAY delay the actual WebSocket Protocol, the implementation MAY delay the actual
transmission arbitrarily, e.g. buffering data so as to send fewer IP transmission arbitrarily, e.g., buffering data so as to send fewer IP
packets. packets.
Note that this document uses both [RFC5234] and [RFC2616] variants of Note that this document uses both [RFC5234] and [RFC2616] variants of
ABNF in different sections. ABNF in different sections.
3. WebSocket URIs 3. WebSocket URIs
This specification defines two URI schemes, using the ABNF syntax This specification defines two URI schemes, using the ABNF syntax
defined in RFC 5234 [RFC5234], and terminology and ABNF productions defined in RFC 5234 [RFC5234], and terminology and ABNF productions
defined by the URI specification RFC 3986 [RFC3986]. defined by the URI specification RFC 3986 [RFC3986].
skipping to change at page 16, line 22 skipping to change at page 14, line 22
wss-URI = "wss:" "//" host [ ":" port ] path [ "?" query ] wss-URI = "wss:" "//" host [ ":" port ] path [ "?" query ]
host = <host, defined in [RFC3986], Section 3.2.2> host = <host, defined in [RFC3986], Section 3.2.2>
port = <port, defined in [RFC3986], Section 3.2.3> port = <port, defined in [RFC3986], Section 3.2.3>
path = <path-abempty, defined in [RFC3986], Section 3.3> path = <path-abempty, defined in [RFC3986], Section 3.3>
query = <query, defined in [RFC3986], Section 3.4> query = <query, defined in [RFC3986], Section 3.4>
The port component is OPTIONAL; the default for "ws" is port 80, The port component is OPTIONAL; the default for "ws" is port 80,
while the default for "wss" is port 443. while the default for "wss" is port 443.
The URI is called "secure" (and it said that "the secure flag is The URI is called "secure" (and it is said that "the secure flag is
set") if the scheme component matches "wss" case-insensitively. set") if the scheme component matches "wss" case-insensitively.
The "resource-name" (also known as /resource name/ in Section 4.1) The "resource-name" (also known as /resource name/ in Section 4.1)
can be constructed by concatenating can be constructed by concatenating the following:
o "/" if the path component is empty o "/" if the path component is empty
o the path component o the path component
o "?" if the query component is non-empty o "?" if the query component is non-empty
o the query component o the query component
Fragment identifiers are meaningless in the context of WebSocket Fragment identifiers are meaningless in the context of WebSocket URIs
URIs, and MUST NOT be used on these URIs. The character "#" in URIs and MUST NOT be used on these URIs. As with any URI scheme, the
MUST be escaped as %23 if used as part of the query component. character "#", when not indicating the start of a fragment, MUST be
escaped as %23.
4. Opening Handshake 4. Opening Handshake
4.1. Client Requirements 4.1. Client Requirements
To _Establish a WebSocket Connection_, a client opens a connection To _Establish a WebSocket Connection_, a client opens a connection
and sends a handshake as defined in this section. A connection is and sends a handshake as defined in this section. A connection is
defined to initially be in a CONNECTING state. A client will need to defined to initially be in a CONNECTING state. A client will need to
supply a /host/, /port/, /resource name/, and a /secure/ flag, which supply a /host/, /port/, /resource name/, and a /secure/ flag, which
are the components of a WebSocket URI as discussed in Section 3, are the components of a WebSocket URI as discussed in Section 3,
along with a list of /protocols/ and /extensions/ to be used. along with a list of /protocols/ and /extensions/ to be used.
Additionally, if the client is a web browser, it supplies /origin/. Additionally, if the client is a web browser, it supplies /origin/.
Clients running in controlled environments, e.g. browsers on mobile Clients running in controlled environments, e.g., browsers on mobile
handsets tied to specific carriers, MAY offload the management of the handsets tied to specific carriers, MAY offload the management of the
connection to another agent on the network. In such a situation, the connection to another agent on the network. In such a situation, the
client for the purposes of this specification is considered to client for the purposes of this specification is considered to
include both the handset software and any such agents. include both the handset software and any such agents.
When the client is to _Establish a WebSocket Connection_ given a set When the client is to _Establish a WebSocket Connection_ given a set
of (/host/, /port/, /resource name/, and /secure/ flag), along with a of (/host/, /port/, /resource name/, and /secure/ flag), along with a
list of /protocols/ and /extensions/ to be used, and an /origin/ in list of /protocols/ and /extensions/ to be used, and an /origin/ in
the case of web browsers, it MUST open a connection, send an opening the case of web browsers, it MUST open a connection, send an opening
handshake, and read the server's handshake in response. The exact handshake, and read the server's handshake in response. The exact
requirements of how the connection should be opened, what should be requirements of how the connection should be opened, what should be
sent in the opening handshake, and how the server's response should sent in the opening handshake, and how the server's response should
be interpreted, are as follows in this section. In the following be interpreted are as follows in this section. In the following
text, we will use terms from Section 3 such as "/host/" and "/secure/ text, we will use terms from Section 3, such as "/host/" and
flag" as defined in that section. "/secure/ flag" as defined in that section.
1. The components of the WebSocket URI passed into this algorithm 1. The components of the WebSocket URI passed into this algorithm
(/host/, /port/, /resource name/ and /secure/ flag) MUST be valid (/host/, /port/, /resource name/, and /secure/ flag) MUST be
according to the specification of WebSocket URIs specified in valid according to the specification of WebSocket URIs specified
Section 3. If any of the components are invalid, the client MUST in Section 3. If any of the components are invalid, the client
_Fail the WebSocket Connection_ and abort these steps. MUST _Fail the WebSocket Connection_ and abort these steps.
2. If the client already has a WebSocket connection to the remote 2. If the client already has a WebSocket connection to the remote
host (IP address) identified by /host/ and port /port/ pair, even host (IP address) identified by /host/ and port /port/ pair, even
if the remote host is known by another name, the client MUST wait if the remote host is known by another name, the client MUST wait
until that connection has been established or for that connection until that connection has been established or for that connection
to have failed. There MUST be no more than one connection in a to have failed. There MUST be no more than one connection in a
CONNECTING state. If multiple connections to the same IP address CONNECTING state. If multiple connections to the same IP address
are attempted simultaneously, the client MUST serialize them so are attempted simultaneously, the client MUST serialize them so
that there is no more than one connection at a time running that there is no more than one connection at a time running
through the following steps. through the following steps.
If the client cannot determine the IP address of the remote host If the client cannot determine the IP address of the remote host
(for example because all communication is being done through a (for example, because all communication is being done through a
proxy server that performs DNS queries itself), then the client proxy server that performs DNS queries itself), then the client
MUST assume for the purposes of this step that each host name MUST assume for the purposes of this step that each host name
refers to a distinct remote host, and instead the client SHOULD refers to a distinct remote host, and instead the client SHOULD
limit the total number of simultaneous pending connections to a limit the total number of simultaneous pending connections to a
reasonably low number (e.g., the client might allow simultaneous reasonably low number (e.g., the client might allow simultaneous
pending connections to a.example.com and b.example.com, but if pending connections to a.example.com and b.example.com, but if
thirty simultaneous connections to a single host are requested, thirty simultaneous connections to a single host are requested,
that may not be allowed). For example in a Web browser context, that may not be allowed). For example, in a web browser context,
the client needs to consider the number of tabs the user has open the client needs to consider the number of tabs the user has open
in setting a limit to the number of simultaneous pending in setting a limit to the number of simultaneous pending
connections. connections.
NOTE: This makes it harder for a script to perform a denial of NOTE: This makes it harder for a script to perform a denial-of-
service attack by just opening a large number of WebSocket service attack by just opening a large number of WebSocket
connections to a remote host. A server can further reduce the connections to a remote host. A server can further reduce the
load on itself when attacked by pausing before closing the load on itself when attacked by pausing before closing the
connection, as that will reduce the rate at which the client connection, as that will reduce the rate at which the client
reconnects. reconnects.
NOTE: There is no limit to the number of established WebSocket NOTE: There is no limit to the number of established WebSocket
connections a client can have with a single remote host. Servers connections a client can have with a single remote host. Servers
can refuse to accept connections from hosts/IP addresses with an can refuse to accept connections from hosts/IP addresses with an
excessive number of existing connections, or disconnect resource- excessive number of existing connections or disconnect resource-
hogging connections when suffering high load. hogging connections when suffering high load.
3. _Proxy Usage_: If the client is configured to use a proxy when 3. _Proxy Usage_: If the client is configured to use a proxy when
using the WebSocket protocol to connect to host /host/ and port using the WebSocket Protocol to connect to host /host/ and port
/port/, then the client SHOULD connect to that proxy and ask it /port/, then the client SHOULD connect to that proxy and ask it
to open a TCP connection to the host given by /host/ and the port to open a TCP connection to the host given by /host/ and the port
given by /port/. given by /port/.
EXAMPLE: For example, if the client uses an HTTP proxy for all EXAMPLE: For example, if the client uses an HTTP proxy for all
traffic, then if it was to try to connect to port 80 on server 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 example.com, it might send the following lines to the proxy
server: server:
CONNECT example.com:80 HTTP/1.1 CONNECT example.com:80 HTTP/1.1
skipping to change at page 19, line 18 skipping to change at page 17, line 5
proxies are encouraged to use a SOCKS5 [RFC1928] proxy for proxies are encouraged to use a SOCKS5 [RFC1928] proxy for
WebSocket connections, if available, or failing that, to prefer WebSocket connections, if available, or failing that, to prefer
the proxy configured for HTTPS connections over the proxy the proxy configured for HTTPS connections over the proxy
configured for HTTP connections. configured for HTTP connections.
For the purpose of proxy autoconfiguration scripts, the URI to For the purpose of proxy autoconfiguration scripts, the URI to
pass the function MUST be constructed from /host/, /port/, pass the function MUST be constructed from /host/, /port/,
/resource name/, and the /secure/ flag using the definition of a /resource name/, and the /secure/ flag using the definition of a
WebSocket URI as given in Section 3. WebSocket URI as given in Section 3.
NOTE: The WebSocket protocol can be identified in proxy NOTE: The WebSocket Protocol can be identified in proxy
autoconfiguration scripts from the scheme ("ws" for unencrypted autoconfiguration scripts from the scheme ("ws" for unencrypted
connections and "wss" for encrypted connections). connections and "wss" for encrypted connections).
4. If the connection could not be opened, either because a direct 4. If the connection could not be opened, either because a direct
connection failed or because any proxy used returned an error, connection failed or because any proxy used returned an error,
then the client MUST _Fail the WebSocket Connection_ and abort then the client MUST _Fail the WebSocket Connection_ and abort
the connection attempt. the connection attempt.
5. If /secure/ is true, the client MUST perform a TLS handshake over 5. If /secure/ is true, the client MUST perform a TLS handshake over
the connection after opening the connection and before sending the connection after opening the connection and before sending
the handshake data [RFC2818]. If this fails (e.g. the server's the handshake data [RFC2818]. If this fails (e.g., the server's
certificate could not be verified), then the client MUST _Fail certificate could not be verified), then the client MUST _Fail
the WebSocket Connection_ and abort the connection. Otherwise, the WebSocket Connection_ and abort the connection. Otherwise,
all further communication on this channel MUST run through the all further communication on this channel MUST run through the
encrypted tunnel. [RFC5246] encrypted tunnel [RFC5246].
Clients MUST use the Server Name Indication extension in the TLS Clients MUST use the Server Name Indication extension in the TLS
handshake. [RFC6066] handshake [RFC6066].
Once a connection to the server has been established (including a Once a connection to the server has been established (including a
connection via a proxy or over a TLS-encrypted tunnel), the client connection via a proxy or over a TLS-encrypted tunnel), the client
MUST send an opening handshake to the server. The handshake consists MUST send an opening handshake to the server. The handshake consists
of an HTTP upgrade request, along with a list of required and of an HTTP Upgrade request, along with a list of required and
optional header fields. The requirements for this handshake are as optional header fields. The requirements for this handshake are as
follows. follows.
1. The handshake MUST be a valid HTTP request as specified by 1. The handshake MUST be a valid HTTP request as specified by
[RFC2616]. [RFC2616].
2. The Method of the request MUST be GET and the HTTP version MUST 2. The method of the request MUST be GET, and the HTTP version MUST
be at least 1.1. be at least 1.1.
For example, if the WebSocket URI is "ws://example.com/chat", For example, if the WebSocket URI is "ws://example.com/chat",
The first line sent should be "GET /chat HTTP/1.1" the first line sent should be "GET /chat HTTP/1.1".
3. The "Request-URI" part of the request MUST match the /resource 3. The "Request-URI" part of the request MUST match the /resource
name/ Section 3 (a relative URI), or be an absolute http/https name/ defined in Section 3 (a relative URI) or be an absolute
URI that, when parsed, has a /resource name/, /host/ and /port/ http/https URI that, when parsed, has a /resource name/, /host/,
that match the corresponding ws/wss URI. and /port/ that match the corresponding ws/wss URI.
4. The request MUST contain a "Host" header field whose value is 4. The request MUST contain a |Host| header field whose value
equal to /host/. contains /host/ plus optionally ":" followed by /port/ (when not
using the default port).
5. The request MUST contain an "Upgrade" header field whose value 5. The request MUST contain an |Upgrade| header field whose value
is equal to "websocket". MUST include the "websocket" keyword.
6. The request MUST contain a "Connection" header field whose value 6. The request MUST contain a |Connection| header field whose value
MUST include the "Upgrade" token. MUST include the "Upgrade" token.
7. The request MUST include a header field with the name "Sec- 7. The request MUST include a header field with the name
WebSocket-Key". The value of this header field MUST be a nonce |Sec-WebSocket-Key|. The value of this header field MUST be a
consisting of a randomly selected 16-byte value that has been nonce consisting of a randomly selected 16-byte value that has
base64-encoded (see Section 4 of [RFC4648]). The nonce MUST be been base64-encoded (see Section 4 of [RFC4648]). The nonce
selected randomly for each connection. MUST be selected randomly for each connection.
NOTE: As an example, if the randomly selected value was the NOTE: As an example, if the randomly selected value was the
sequence of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 sequence of bytes 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09
0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, the value of the header 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f 0x10, the value of the header
field would be "AQIDBAUGBwgJCgsMDQ4PEC==" field would be "AQIDBAUGBwgJCgsMDQ4PEC=="
8. The request MUST include a header field with the name "Origin" 8. The request MUST include a header field with the name |Origin|
[I-D.ietf-websec-origin] if the request is coming from a browser [RFC6454] if the request is coming from a browser client. If
client. If the connection is from a non-browser client, the the connection is from a non-browser client, the request MAY
request MAY include this header field if the semantics of that include this header field if the semantics of that client match
client match the use-case described here for browser clients. the use-case described here for browser clients. The value of
The value of this header field is the ASCII serialization of this header field is the ASCII serialization of origin of the
origin of the context in which the code establishing the context in which the code establishing the connection is
connection is running. See [I-D.ietf-websec-origin] for the running. See [RFC6454] for the details of how this header field
details of how this header field value is constructed. value is constructed.
As an example, if code downloaded from www.example.com attempts As an example, if code downloaded from www.example.com attempts
to establish a connection to ww2.example.com, the value of the to establish a connection to ww2.example.com, the value of the
header field would be "http://www.example.com". header field would be "http://www.example.com".
9. The request MUST include a header field with the name "Sec- 9. The request MUST include a header field with the name
WebSocket-Version". The value of this header field MUST be 13. |Sec-WebSocket-Version|. The value of this header field MUST be
_Note: Although drafts -09, -10, -11 and -12 were published, as 13.
they were mostly comprised of editorial changes and
clarifications and not changes to the wire protocol, values 9,
10, 11 and 12 were not used as valid values for Sec-WebSocket-
Version. These values were reserved in the IANA registry but
were not and will not be used._
10. The request MAY include a header field with the name "Sec- NOTE: Although draft versions of this document (-09, -10, -11,
WebSocket-Protocol". If present, this value indicates one or and -12) were posted (they were mostly comprised of editorial
more comma separated subprotocol the client wishes to speak, changes and clarifications and not changes to the wire
protocol), values 9, 10, 11, and 12 were not used as valid
values for Sec-WebSocket-Version. These values were reserved in
the IANA registry but were not and will not be used.
10. The request MAY include a header field with the name
|Sec-WebSocket-Protocol|. If present, this value indicates one
or more comma-separated subprotocol the client wishes to speak,
ordered by preference. The elements that comprise this value ordered by preference. The elements that comprise this value
MUST be non-empty strings with characters in the range U+0021 to MUST be non-empty strings with characters in the range U+0021 to
U+007E not including separator characters as defined in U+007E not including separator characters as defined in
[RFC2616], and MUST all be unique strings. The ABNF for the [RFC2616] and MUST all be unique strings. The ABNF for the
value of this header field is 1#token, where the definitions of value of this header field is 1#token, where the definitions of
constructs and rules are as given in [RFC2616]. constructs and rules are as given in [RFC2616].
11. The request MAY include a header field with the name "Sec- 11. The request MAY include a header field with the name
WebSocket-Extensions". If present, this value indicates the |Sec-WebSocket-Extensions|. If present, this value indicates
protocol-level extension(s) the client wishes to speak. The the protocol-level extension(s) the client wishes to speak. The
interpretation and format of this header field is described in interpretation and format of this header field is described in
Section 9.1. Section 9.1.
12. The request MAY include any other header fields, for example 12. The request MAY include any other header fields, for example,
cookies [RFC6265] and/or authentication related header fields cookies [RFC6265] and/or authentication-related header fields
such as Authorization header field [RFC2616], which are such as the |Authorization| header field [RFC2616], which are
processed according to documents that define them. processed according to documents that define them.
Once the client's opening handshake has been sent, the client MUST Once the client's opening handshake has been sent, the client MUST
wait for a response from the server before sending any further data. wait for a response from the server before sending any further data.
The client MUST validate the server's response as follows: The client MUST validate the server's response as follows:
1. If the status code received from the server is not 101, the 1. If the status code received from the server is not 101, the
client handles the response per HTTP [RFC2616] procedures, in client handles the response per HTTP [RFC2616] procedures. In
particular the client might perform authentication if it receives particular, the client might perform authentication if it
401 status code, the server might redirect the client using a 3xx receives a 401 status code; the server might redirect the client
status code (but clients are not required to follow them), etc. using a 3xx status code (but clients are not required to follow
Otherwise, proceed as follows. them), etc. Otherwise, proceed as follows.
2. If the response lacks an "Upgrade" header field or the "Upgrade" 2. If the response lacks an |Upgrade| header field or the |Upgrade|
header field contains a value that is not an ASCII case- header field contains a value that is not an ASCII case-
insensitive match for the value "websocket", the client MUST insensitive match for the value "websocket", the client MUST
_Fail the WebSocket Connection _. _Fail the WebSocket Connection_.
3. If the response lacks a "Connection" header field or the 3. If the response lacks a |Connection| header field or the
"Connection" header field doesn't contain a token that is an |Connection| header field doesn't contain a token that is an
ASCII case-insensitive match for the value "Upgrade", the client ASCII case-insensitive match for the value "Upgrade", the client
MUST _Fail the WebSocket Connection_. MUST _Fail the WebSocket Connection_.
4. If the response lacks a "Sec-WebSocket-Accept" header field or 4. If the response lacks a |Sec-WebSocket-Accept| header field or
the "Sec-WebSocket-Accept" contains a value other than the the |Sec-WebSocket-Accept| contains a value other than the
base64-encoded SHA-1 of the concatenation of the "Sec-WebSocket- base64-encoded SHA-1 of the concatenation of the |Sec-WebSocket-
Key" (as a string, not base64-decoded) with the string "258EAFA5- Key| (as a string, not base64-decoded) with the string "258EAFA5-
E914-47DA-95CA-C5AB0DC85B11", but ignoring any leading and E914-47DA-95CA-C5AB0DC85B11" but ignoring any leading and
trailing whitespace, the client MUST _Fail the WebSocket trailing whitespace, the client MUST _Fail the WebSocket
Connection_ Connection_.
5. If the response includes a "Sec-WebSocket-Extensions" header 5. If the response includes a |Sec-WebSocket-Extensions| header
field, and this header field indicates the use of an extension field and this header field indicates the use of an extension
that was not present in the client' handshake (the server has that was not present in the client's handshake (the server has
indicated an extension not requested by the client), the client indicated an extension not requested by the client), the client
MUST _Fail the WebSocket Connection_. (The parsing of this MUST _Fail the WebSocket Connection_. (The parsing of this
header field to determine which extensions are requested is header field to determine which extensions are requested is
discussed in Section 9.1.) discussed in Section 9.1.)
6. If the response includes a "Sec-WebSocket-Protocol" header field, 6. If the response includes a |Sec-WebSocket-Protocol| header field
and this header field indicates the use of a subprotocol that was and this header field indicates the use of a subprotocol that was
not present in the client' handshake (the server has indicated a not present in the client's handshake (the server has indicated a
subprotocol not requested by the client), the client MUST _Fail subprotocol not requested by the client), the client MUST _Fail
the WebSocket Connection_. the WebSocket Connection_.
If the server's response does not conform to the requirements for the If the server's response does not conform to the requirements for the
server's handshake as defined in this section and in Section 4.2.2, server's handshake as defined in this section and in Section 4.2.2,
the client MUST _Fail the WebSocket Connection_. the client MUST _Fail the WebSocket Connection_.
Please note that according to [RFC2616] all header field names in Please note that according to [RFC2616], all header field names in
both HTTP requests and HTTP responses are case-insensitive. both HTTP requests and HTTP responses are case-insensitive.
If the server's response is validated as provided for above, it is If the server's response is validated as provided for above, it is
said that _The WebSocket Connection is Established_ and that the said that _The WebSocket Connection is Established_ and that the
WebSocket Connection is in the OPEN state. The _Extensions In Use_ WebSocket Connection is in the OPEN state. The _Extensions In Use_
is defined to be a (possibly empty) string, the value of which is is defined to be a (possibly empty) string, the value of which is
equal to the value of the |Sec-WebSocket-Extensions| header field equal to the value of the |Sec-WebSocket-Extensions| header field
supplied by the server's handshake, or the null value if that header supplied by the server's handshake or the null value if that header
field was not present in the server's handshake. The _Subprotocol In field was not present in the server's handshake. The _Subprotocol In
Use_ is defined to be the value of the |Sec-WebSocket-Protocol| Use_ is defined to be the value of the |Sec-WebSocket-Protocol|
header field in the server's handshake, or the null value if that header field in the server's handshake or the null value if that
header field was not present in the server's handshake. header field was not present in the server's handshake.
Additionally, if any header fields in the server's handshake indicate Additionally, if any header fields in the server's handshake indicate
that cookies should be set (as defined by [RFC6265]), these cookies that cookies should be set (as defined by [RFC6265]), these cookies
are referred to as _Cookies Set During the Server's Opening are referred to as _Cookies Set During the Server's Opening
Handshake_. Handshake_.
4.2. Server-side Requirements 4.2. Server-Side Requirements
Servers MAY offload the management of the connection to other agents Servers MAY offload the management of the connection to other agents
on the network, for example load balancers and reverse proxies. In on the network, for example, load balancers and reverse proxies. In
such a situation, the server for the purposes of this specification such a situation, the server for the purposes of this specification
is considered to include all parts of the server-side infrastructure is considered to include all parts of the server-side infrastructure
from the first device to terminate the TCP connection all the way to from the first device to terminate the TCP connection all the way to
the server that processes requests and sends responses. the server that processes requests and sends responses.
EXAMPLE: For example, a data center might have a server that responds EXAMPLE: A data center might have a server that responds to WebSocket
to WebSocket requests with an appropriate handshake, and then passes requests with an appropriate handshake and then passes the connection
the connection to another server to actually process the data frames. to another server to actually process the data frames. For the
For the purposes of this specification, the "server" is the purposes of this specification, the "server" is the combination of
combination of both computers. both computers.
4.2.1. Reading the Client's Opening Handshake 4.2.1. Reading the Client's Opening Handshake
When a client starts a WebSocket connection, it sends its part of the When a client starts a WebSocket connection, it sends its part of the
opening handshake. The server must parse at least part of this opening handshake. The server must parse at least part of this
handshake in order to obtain the necessary information to generate handshake in order to obtain the necessary information to generate
the server part of the handshake. the server part of the handshake.
The client's opening handshake consists of the following parts. If The client's opening handshake consists of the following parts. If
the server, while reading the handshake, finds that the client did the server, while reading the handshake, finds that the client did
not send a handshake that matches the description below (note that as not send a handshake that matches the description below (note that as
per [RFC2616] the order of the header fields is not important), per [RFC2616], the order of the header fields is not important),
including but not limited to any violations of the ABNF grammar including but not limited to any violations of the ABNF grammar
specified for the components of the handshake, the server MUST stop specified for the components of the handshake, the server MUST stop
processing the client's handshake, and return an HTTP response with processing the client's handshake and return an HTTP response with an
an appropriate error code (such as 400 Bad Request). appropriate error code (such as 400 Bad Request).
1. An HTTP/1.1 or higher GET request, including a "Request-URI" 1. An HTTP/1.1 or higher GET request, including a "Request-URI"
[RFC2616] that should be interpreted as a /resource name/ [RFC2616] that should be interpreted as a /resource name/
Section 3 (or an absolute HTTP/HTTPS URI containing the defined in Section 3 (or an absolute HTTP/HTTPS URI containing
/resource name/). the /resource name/).
2. A "Host" header field containing the server's authority. 2. A |Host| header field containing the server's authority.
3. An "Upgrade" header field containing the value "websocket", 3. An |Upgrade| header field containing the value "websocket",
treated as an ASCII case-insensitive value. treated as an ASCII case-insensitive value.
4. A "Connection" header field that includes the token "Upgrade", 4. A |Connection| header field that includes the token "Upgrade",
treated as an ASCII case-insensitive value. treated as an ASCII case-insensitive value.
5. A "Sec-WebSocket-Key" header field with a base64-encoded (see 5. A |Sec-WebSocket-Key| header field with a base64-encoded (see
Section 4 of [RFC4648]) value that, when decoded, is 16 bytes in Section 4 of [RFC4648]) value that, when decoded, is 16 bytes in
length. length.
6. A "Sec-WebSocket-Version" header field, with a value of 13. 6. A |Sec-WebSocket-Version| header field, with a value of 13.
7. Optionally, an "Origin" header field. This header field is sent 7. Optionally, an |Origin| header field. This header field is sent
by all browser clients. A connection attempt lacking this by all browser clients. A connection attempt lacking this
header field SHOULD NOT be interpreted as coming from a browser header field SHOULD NOT be interpreted as coming from a browser
client. client.
8. Optionally, a "Sec-WebSocket-Protocol" header field, with a list 8. Optionally, a |Sec-WebSocket-Protocol| header field, with a list
of values indicating which protocols the client would like to of values indicating which protocols the client would like to
speak, ordered by preference. speak, ordered by preference.
9. Optionally, a "Sec-WebSocket-Extensions" header field, with a 9. Optionally, a |Sec-WebSocket-Extensions| header field, with a
list of values indicating which extensions the client would like list of values indicating which extensions the client would like
to speak. The interpretation of this header field is discussed to speak. The interpretation of this header field is discussed
in Section 9.1. in Section 9.1.
10. Optionally, other header fields, such as those used to send 10. Optionally, other header fields, such as those used to send
cookies or request authentication to a server. Unknown header cookies or request authentication to a server. Unknown header
fields are ignored, as per [RFC2616]. fields are ignored, as per [RFC2616].
4.2.2. Sending the Server's Opening Handshake 4.2.2. Sending the Server's Opening Handshake
When a client establishes a WebSocket connection to a server, the When a client establishes a WebSocket connection to a server, the
server MUST complete the following steps to accept the connection and server MUST complete the following steps to accept the connection and
send the server's opening handshake. send the server's opening handshake.
1. If the connection is happening on an HTTPS (HTTP-over-TLS) port, 1. If the connection is happening on an HTTPS (HTTP-over-TLS) port,
perform a TLS handshake over the connection. If this fails (e.g. perform a TLS handshake over the connection. If this fails
the client indicated a host name in the extended client hello (e.g., the client indicated a host name in the extended client
"server_name" extension that the server does not host), then hello "server_name" extension that the server does not host),
close the connection; otherwise, all further communication for then close the connection; otherwise, all further communication
the connection (including the server's handshake) MUST run for the connection (including the server's handshake) MUST run
through the encrypted tunnel. [RFC5246] through the encrypted tunnel [RFC5246].
2. The server can perform additional client authentication, for 2. The server can perform additional client authentication, for
example by returning a 401 status code with the corresponding example, by returning a 401 status code with the corresponding
WWW-Authenticate header field as described in [RFC2616]. |WWW-Authenticate| header field as described in [RFC2616].
3. The server MAY redirect the client using a 3xx status code 3. The server MAY redirect the client using a 3xx status code
[RFC2616]. Note that this step can happen together with, before [RFC2616]. Note that this step can happen together with, before,
or after the optional authentication step described above. or after the optional authentication step described above.
4. Establish the following information: 4. Establish the following information:
/origin/ /origin/
The |Origin| header field in the client's handshake indicates The |Origin| header field in the client's handshake indicates
the origin of the script establishing the connection. The the origin of the script establishing the connection. The
origin is serialized to ASCII and converted to lowercase. The origin is serialized to ASCII and converted to lowercase. The
server MAY use this information as part of a determination of server MAY use this information as part of a determination of
whether to accept the incoming connection. If the server does whether to accept the incoming connection. If the server does
not validate the origin, it will accept connections from not validate the origin, it will accept connections from
anywhere. If the server does not wish to accept this anywhere. If the server does not wish to accept this
connection, it MUST return an appropriate HTTP error code connection, it MUST return an appropriate HTTP error code
(e.g. 403 Forbidden) and abort the WebSocket handshake (e.g., 403 Forbidden) and abort the WebSocket handshake
described in this section. For more detail, refer to described in this section. For more detail, refer to
Section 10. Section 10.
/key/ /key/
The |Sec-WebSocket-Key| header field in the client's handshake The |Sec-WebSocket-Key| header field in the client's handshake
includes a base64-encoded value that, if decoded, is 16 bytes includes a base64-encoded value that, if decoded, is 16 bytes
in length. This (encoded) value is used in the creation of in length. This (encoded) value is used in the creation of
the server's handshake to indicate an acceptance of the the server's handshake to indicate an acceptance of the
connection. It is not necessary for the server to base64- connection. It is not necessary for the server to base64-
decode the "Sec-WebSocket-Key" value. decode the |Sec-WebSocket-Key| value.
/version/ /version/
The |Sec-WebSocket-Version| header field in the client's The |Sec-WebSocket-Version| header field in the client's
handshake includes the version of the WebSocket protocol the handshake includes the version of the WebSocket Protocol with
client is attempting to communicate with. If this version which the client is attempting to communicate. If this
does not match a version understood by the server, the server version does not match a version understood by the server, the
MUST abort the websocket handshake described in this section server MUST abort the WebSocket handshake described in this
and instead send an appropriate HTTP error code (such as 426 section and instead send an appropriate HTTP error code (such
Upgrade Required), and a |Sec-WebSocket-Version| header field as 426 Upgrade Required) and a |Sec-WebSocket-Version| header
indicating the version(s) the server is capable of field indicating the version(s) the server is capable of
understanding. understanding.
/resource name/ /resource name/
An identifier for the service provided by the server. If the An identifier for the service provided by the server. If the
server provides multiple services, then the value should be server provides multiple services, then the value should be
derived from the resource name given in the client's handshake derived from the resource name given in the client's handshake
from the Request-URI [RFC2616] of the GET method. If the in the "Request-URI" [RFC2616] of the GET method. If the
requested service is not available, the server MUST send an requested service is not available, the server MUST send an
appropriate HTTP error code (such as 404 Not Found) and abort appropriate HTTP error code (such as 404 Not Found) and abort
the WebSocket handshake. the WebSocket handshake.
/subprotocol/ /subprotocol/
Either a single value representing the subprotocol the server Either a single value representing the subprotocol the server
is ready to use or null. The value chosen MUST be derived is ready to use or null. The value chosen MUST be derived
from the client's handshake, specifically by selecting one of from the client's handshake, specifically by selecting one of
the values from the "Sec-WebSocket-Protocol" field that the the values from the |Sec-WebSocket-Protocol| field that the
server is willing to use for this connection (if any). If the server is willing to use for this connection (if any). If the
client's handshake did not contain such a header field, or if client's handshake did not contain such a header field or if
the server does not agree to any of the client's requested the server does not agree to any of the client's requested
subprotocols, the only acceptable value is null. The absence subprotocols, the only acceptable value is null. The absence
of such a field is equivalent to the null value (meaning that of such a field is equivalent to the null value (meaning that
if the server does not wish to agree to one of the suggested if the server does not wish to agree to one of the suggested
subprotocols, it MUST NOT send back a |Sec-WebSocket-Protocol| subprotocols, it MUST NOT send back a |Sec-WebSocket-Protocol|
header field in its response). The empty string is not the header field in its response). The empty string is not the
same as the null value for these purposes, and is not a legal same as the null value for these purposes and is not a legal
value for this field. The ABNF for the value of this header value for this field. The ABNF for the value of this header
field is (token), where the definitions of constructs and field is (token), where the definitions of constructs and
rules are as given in [RFC2616]. rules are as given in [RFC2616].
/extensions/ /extensions/
A (possibly empty) list representing the protocol-level A (possibly empty) list representing the protocol-level
extensions the server is ready to use. If the server supports extensions the server is ready to use. If the server supports
multiple extensions, then the value MUST be derived from the multiple extensions, then the value MUST be derived from the
client's handshake, specifically by selecting one or more of client's handshake, specifically by selecting one or more of
the values from the "Sec-WebSocket-Extensions" field. The the values from the |Sec-WebSocket-Extensions| field. The
absence of such a field is equivalent to the null value. 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 empty string is not the same as the null value for these
purposes. Extensions not listed by the client MUST NOT be purposes. Extensions not listed by the client MUST NOT be
listed. The method by which these values should be selected listed. The method by which these values should be selected
and interpreted is discussed in Section 9.1. and interpreted is discussed in Section 9.1.
5. If the server chooses to accept the incoming connection, it MUST 5. If the server chooses to accept the incoming connection, it MUST
reply with a valid HTTP response indicating the following. reply with a valid HTTP response indicating the following.
1. A Status-Line with a 101 response code as per RFC 2616 1. A Status-Line with a 101 response code as per RFC 2616
[RFC2616]. Such a response could look like "HTTP/1.1 101 [RFC2616]. Such a response could look like "HTTP/1.1 101
Switching Protocols" Switching Protocols".
2. An "Upgrade" header field with value "websocket" as per RFC 2. An |Upgrade| header field with value "websocket" as per RFC
2616 [RFC2616]. 2616 [RFC2616].
3. A "Connection" header field with value "Upgrade" 3. A |Connection| header field with value "Upgrade".
4. A "Sec-WebSocket-Accept" header field. The value of this 4. A |Sec-WebSocket-Accept| header field. The value of this
header field is constructed by concatenating /key/, defined header field is constructed by concatenating /key/, defined
above in Paragraph 4 of Section 4.2.2, with the string above in step 4 in Section 4.2.2, with the string "258EAFA5-
"258EAFA5-E914-47DA-95CA-C5AB0DC85B11", taking the SHA-1 hash E914-47DA-95CA-C5AB0DC85B11", taking the SHA-1 hash of this
of this concatenated value to obtain a 20-byte value, and concatenated value to obtain a 20-byte value and base64-
base64-encoding (see Section 4 of [RFC4648]) this 20-byte encoding (see Section 4 of [RFC4648]) this 20-byte hash.
hash.
The ABNF [RFC2616] of this header field is defined as The ABNF [RFC2616] of this header field is defined as
follows: follows:
Sec-WebSocket-Accept = base64-value-non-empty Sec-WebSocket-Accept = base64-value-non-empty
base64-value-non-empty = (1*base64-data [ base64-padding ]) | base64-value-non-empty = (1*base64-data [ base64-padding ]) |
base64-padding base64-padding
base64-data = 4base64-character base64-data = 4base64-character
base64-padding = (2base64-character "==") | base64-padding = (2base64-character "==") |
(3base64-character "=") (3base64-character "=")
base64-character = ALPHA | DIGIT | "+" | "/" base64-character = ALPHA | DIGIT | "+" | "/"
NOTE: As an example, if the value of the "Sec-WebSocket-Key" NOTE: As an example, if the value of the |Sec-WebSocket-Key| header
header field in the client's handshake were field in the client's handshake were "dGhlIHNhbXBsZSBub25jZQ==", the
"dGhlIHNhbXBsZSBub25jZQ==", the server would append the server would append the string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
string "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" to form the to form the string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA-
string "dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA- C5AB0DC85B11". The server would then take the SHA-1 hash of this
C5AB0DC85B11". The server would then take the SHA-1 hash of string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90
this string, giving the value 0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea. This value
0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe is then base64-encoded, to give the value
0xc4 0xea. This value is then base64-encoded, to give the "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned in the
value "s3pPLMBiTxaQ9kYGzzhZRbK+xOo=", which would be returned |Sec-WebSocket-Accept| header field.
in the "Sec-WebSocket-Accept" header field.
5. Optionally, a "Sec-WebSocket-Protocol" header field, with a 5. Optionally, a |Sec-WebSocket-Protocol| header field, with a
value /subprotocol/ as defined in Paragraph 4 of value /subprotocol/ as defined in step 4 in Section 4.2.2.
Section 4.2.2.
6. Optionally, a "Sec-WebSocket-Extensions" header field, with a 6. Optionally, a |Sec-WebSocket-Extensions| header field, with a
value /extensions/ as defined in Paragraph 4 of value /extensions/ as defined in step 4 in Section 4.2.2. If
Section 4.2.2. If multiple extensions are to be used, they multiple extensions are to be used, they can all be listed in
can all be listed in a single Sec-WebSocket-Extensions header a single |Sec-WebSocket-Extensions| header field or split
field, or split between multiple instances of the Sec- between multiple instances of the |Sec-WebSocket-Extensions|
WebSocket-Extensions header field. header field.
This completes the server's handshake. If the server finishes these This completes the server's handshake. If the server finishes these
steps without aborting the WebSocket handshake, the server considers steps without aborting the WebSocket handshake, the server considers
the WebSocket connection to be established and that the WebSocket the WebSocket connection to be established and that the WebSocket
connection is in the OPEN state. At this point, the server may begin connection is in the OPEN state. At this point, the server may begin
sending (and receiving) data. sending (and receiving) data.
4.3. Collected ABNF for new header fields used in handshake 4.3. Collected ABNF for New Header Fields Used in Handshake
This section is using ABNF syntax/rules from Section 2.1 of This section is using ABNF syntax/rules from Section 2.1 of
[RFC2616], including "implied *LWS rule". [RFC2616], including the "implied *LWS rule".
Note that the following ABNF conventions are used in this section: Note that the following ABNF conventions are used in this section.
Some names of the rules correspond to names of the corresponding Some names of the rules correspond to names of the corresponding
header fields. Such rules express values of the corresponding header header fields. Such rules express values of the corresponding header
fields, for example the Sec-WebSocket-Key ABNF rule describes syntax fields, for example, the Sec-WebSocket-Key ABNF rule describes syntax
of the Sec-WebSocket-Key header field value. ABNF rules with the of the |Sec-WebSocket-Key| header field value. ABNF rules with the
"-Client" suffix in the name are only used in requests sent by the "-Client" suffix in the name are only used in requests sent by the
client to the server; ABNF rules with the "-Server" suffix in the client to the server; ABNF rules with the "-Server" suffix in the
name are only used in responses sent by the server to the client. name are only used in responses sent by the server to the client.
For example, the ABNF rule Sec-WebSocket-Protocol-Client describes For example, the ABNF rule Sec-WebSocket-Protocol-Client describes
syntax of the Sec-WebSocket-Protocol header field value sent by the syntax of the |Sec-WebSocket-Protocol| header field value sent by the
client to the server. client to the server.
The following new header field can be sent during the handshake from The following new header fields can be sent during the handshake from
the client to the server: the client to the server:
Sec-WebSocket-Key = base64-value-non-empty Sec-WebSocket-Key = base64-value-non-empty
Sec-WebSocket-Extensions = extension-list Sec-WebSocket-Extensions = extension-list
Sec-WebSocket-Protocol-Client = 1#token Sec-WebSocket-Protocol-Client = 1#token
Sec-WebSocket-Version-Client = version Sec-WebSocket-Version-Client = version
base64-value-non-empty = (1*base64-data [ base64-padding ]) | base64-value-non-empty = (1*base64-data [ base64-padding ]) |
base64-padding base64-padding
base64-data = 4base64-character base64-data = 4base64-character
base64-padding = (2base64-character "==") | base64-padding = (2base64-character "==") |
(3base64-character "=") (3base64-character "=")
base64-character = ALPHA | DIGIT | "+" | "/" base64-character = ALPHA | DIGIT | "+" | "/"
extension-list = 1#extension extension-list = 1#extension
extension = extension-token *( ";" extension-param ) extension = extension-token *( ";" extension-param )
extension-token = registered-token extension-token = registered-token
registered-token = token registered-token = token
extension-param = token [ "=" (token | quoted-string) ] extension-param = token [ "=" (token | quoted-string) ]
;When using the quoted-string syntax variant, the value ; When using the quoted-string syntax variant, the value
;after quoted-string unescaping MUST conform to the 'token' ABNF. ; after quoted-string unescaping MUST conform to the
NZDIGIT = "1" | "2" | "3" | "4" | "5" | "6" | ; 'token' ABNF.
"7" | "8" | "9" NZDIGIT = "1" | "2" | "3" | "4" | "5" | "6" |
version = DIGIT | (NZDIGIT DIGIT) | "7" | "8" | "9"
("1" DIGIT DIGIT) | ("2" DIGIT DIGIT) version = DIGIT | (NZDIGIT DIGIT) |
; Limited to 0-255 range, with no leading zeros ("1" DIGIT DIGIT) | ("2" DIGIT DIGIT)
; Limited to 0-255 range, with no leading zeros
The following new header field can be sent during the handshake from The following new header fields can be sent during the handshake from
the server to the client: the server to the client:
Sec-WebSocket-Extensions = extension-list Sec-WebSocket-Extensions = extension-list
Sec-WebSocket-Accept = base64-value-non-empty Sec-WebSocket-Accept = base64-value-non-empty
Sec-WebSocket-Protocol-Server = token Sec-WebSocket-Protocol-Server = token
Sec-WebSocket-Version-Server = 1#version Sec-WebSocket-Version-Server = 1#version
4.4. Supporting multiple versions of WebSocket protocol 4.4. Supporting Multiple Versions of WebSocket Protocol
This section provides some guidance on supporting multiple versions This section provides some guidance on supporting multiple versions
of the WebSocket protocol in clients and servers. of the WebSocket Protocol in clients and servers.
Using the WebSocket version advertisement capability (the "Sec- Using the WebSocket version advertisement capability (the
WebSocket-Version" header field) client can initially request the |Sec-WebSocket-Version| header field), a client can initially request
version of the WebSocket protocol that it prefers (which doesn't the version of the WebSocket Protocol that it prefers (which doesn't
necessarily have to be the latest supported by the client). If the necessarily have to be the latest supported by the client). If the
server supports the requested version and the handshake message is server supports the requested version and the handshake message is
otherwise valid, the server will accept that version. If the server otherwise valid, the server will accept that version. If the server
doesn't support the requested version, it MUST respond with a Sec- doesn't support the requested version, it MUST respond with a
WebSocket-Version header field (or multiple Sec-WebSocket-Version |Sec-WebSocket-Version| header field (or multiple
header fields) containing all versions it is willing to use. At this |Sec-WebSocket-Version| header fields) containing all versions it is
point, if the client supports one of the advertised versions, it can willing to use. At this point, if the client supports one of the
repeat the WebSocket handshake using a new version value. advertised versions, it can repeat the WebSocket handshake using a
new version value.
The following example demonstrates version negotiation described The following example demonstrates version negotiation described
above: above:
GET /chat HTTP/1.1 GET /chat HTTP/1.1
Host: server.example.com Host: server.example.com
Upgrade: websocket Upgrade: websocket
Connection: Upgrade Connection: Upgrade
... ...
Sec-WebSocket-Version: 25 Sec-WebSocket-Version: 25
The response from the server might look as follows: The response from the server might look as follows:
HTTP/1.1 400 Bad Request HTTP/1.1 400 Bad Request
... ...
Sec-WebSocket-Version: 13, 8, 7 Sec-WebSocket-Version: 13, 8, 7
Note that the last response from the server might also look like: Note that the last response from the server might also look like:
HTTP/1.1 400 Bad Request HTTP/1.1 400 Bad Request
... ...
Sec-WebSocket-Version: 13 Sec-WebSocket-Version: 13
Sec-WebSocket-Version: 8, 7 Sec-WebSocket-Version: 8, 7
The client now repeats the handshake that conforms to version 13: The client now repeats the handshake that conforms to version 13:
GET /chat HTTP/1.1 GET /chat HTTP/1.1
Host: server.example.com Host: server.example.com
Upgrade: websocket Upgrade: websocket
Connection: Upgrade Connection: Upgrade
... ...
Sec-WebSocket-Version: 13 Sec-WebSocket-Version: 13
5. Data Framing 5. Data Framing
5.1. Overview 5.1. Overview
In the WebSocket protocol, data is transmitted using a sequence of In the WebSocket Protocol, data is transmitted using a sequence of
frames. To avoid confusing network intermediaries (such as frames. To avoid confusing network intermediaries (such as
intercepting proxies) and for security reasons that are further intercepting proxies) and for security reasons that are further
discussed in Section 10.3, a client MUST mask all frames that it discussed in Section 10.3, a client MUST mask all frames that it
sends to the server (see Section 5.3 for further details). (Note sends to the server (see Section 5.3 for further details). (Note
that masking is done whether or not the WebSocket protocol is running that masking is done whether or not the WebSocket Protocol is running
over TLS.) The server MUST close the connection upon receiving a over TLS.) The server MUST close the connection upon receiving a
frame that is not masked. In this case, a server MAY send a close frame that is not masked. In this case, a server MAY send a Close
frame with a status code of 1002 (protocol error) as defined in frame with a status code of 1002 (protocol error) as defined in
Section 7.4.1. A server MUST NOT mask any frames that it sends to Section 7.4.1. A server MUST NOT mask any frames that it sends to
the client. A client MUST close a connection if it detects a masked the client. A client MUST close a connection if it detects a masked
frame. In this case, it MAY use the status code 1002 (protocol frame. In this case, it MAY use the status code 1002 (protocol
error) as defined in Section 7.4.1. (These rules might be relaxed in error) as defined in Section 7.4.1. (These rules might be relaxed in
a future specification.) a future specification.)
The base framing protocol defines a frame type with an opcode, a The base framing protocol defines a frame type with an opcode, a
payload length, and designated locations for extension and payload length, and designated locations for "Extension data" and
application data, which together define the _payload_ data. Certain "Application data", which together define the "Payload data".
bits and opcodes are reserved for future expansion of the protocol. Certain bits and opcodes are reserved for future expansion of the
protocol.
A data frame MAY be transmitted by either the client or the server at A data frame MAY be transmitted by either the client or the server at
any time after opening handshake completion and before that endpoint any time after opening handshake completion and before that endpoint
has sent a close frame (Section 5.5.1). has sent a Close frame (Section 5.5.1).
5.2. Base Framing Protocol 5.2. Base Framing Protocol
This wire format for the data transfer part is described by the ABNF This wire format for the data transfer part is described by the ABNF
[RFC5234] given in detail in this section. (Note that unlike in [RFC5234] given in detail in this section. (Note that, unlike in
other sections of this document the ABNF in this section is operating other sections of this document, the ABNF in this section is
on groups of bits. The length of each group of bits is indicated in operating on groups of bits. The length of each group of bits is
a comment. When encoded on the wire the most significant bit is the indicated in a comment. When encoded on the wire, the most
leftmost in the ABNF). A high level overview of the framing is given significant bit is the leftmost in the ABNF). A high-level overview
in the following figure. In a case of conflict between the figure of the framing is given in the following figure. In a case of
below and the ABNF specified later in this section, the figure is conflict between the figure below and the ABNF specified later in
authoritative. this section, the figure is authoritative.
0 1 2 3 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 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
+-+-+-+-+-------+-+-------------+-------------------------------+ +-+-+-+-+-------+-+-------------+-------------------------------+
|F|R|R|R| opcode|M| Payload len | Extended payload length | |F|R|R|R| opcode|M| Payload len | Extended payload length |
|I|S|S|S| (4) |A| (7) | (16/64) | |I|S|S|S| (4) |A| (7) | (16/64) |
|N|V|V|V| |S| | (if payload len==126/127) | |N|V|V|V| |S| | (if payload len==126/127) |
| |1|2|3| |K| | | | |1|2|3| |K| | |
+-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - + +-+-+-+-+-------+-+-------------+ - - - - - - - - - - - - - - - +
| Extended payload length continued, if payload len == 127 | | Extended payload length continued, if payload len == 127 |
skipping to change at page 31, line 31 skipping to change at page 28, line 47
| Payload Data continued ... | | Payload Data continued ... |
+---------------------------------------------------------------+ +---------------------------------------------------------------+
FIN: 1 bit FIN: 1 bit
Indicates that this is the final fragment in a message. The first Indicates that this is the final fragment in a message. The first
fragment MAY also be the final fragment. fragment MAY also be the final fragment.
RSV1, RSV2, RSV3: 1 bit each RSV1, RSV2, RSV3: 1 bit each
MUST be 0 unless an extension is negotiated which defines meanings MUST be 0 unless an extension is negotiated that defines meanings
for non-zero values. If a nonzero value is received and none of for non-zero values. If a nonzero value is received and none of
the negotiated extensions defines the meaning of such a nonzero the negotiated extensions defines the meaning of such a nonzero
value, the receiving endpoint MUST _Fail the WebSocket value, the receiving endpoint MUST _Fail the WebSocket
Connection_. Connection_.
Opcode: 4 bits Opcode: 4 bits
Defines the interpretation of the payload data. If an unknown Defines the interpretation of the "Payload data". If an unknown
opcode is received, the receiving endpoint MUST _Fail the opcode is received, the receiving endpoint MUST _Fail the
WebSocket Connection_. The following values are defined. WebSocket Connection_. The following values are defined.
* %x0 denotes a continuation frame * %x0 denotes a continuation frame
* %x1 denotes a text frame * %x1 denotes a text frame
* %x2 denotes a binary frame * %x2 denotes a binary frame
* %x3-7 are reserved for further non-control frames * %x3-7 are reserved for further non-control frames
skipping to change at page 32, line 4 skipping to change at page 29, line 20
* %x0 denotes a continuation frame * %x0 denotes a continuation frame
* %x1 denotes a text frame * %x1 denotes a text frame
* %x2 denotes a binary frame * %x2 denotes a binary frame
* %x3-7 are reserved for further non-control frames * %x3-7 are reserved for further non-control frames
* %x8 denotes a connection close * %x8 denotes a connection close
* %x9 denotes a ping * %x9 denotes a ping
* %xA denotes a pong * %xA denotes a pong
* %xB-F are reserved for further control frames * %xB-F are reserved for further control frames
Mask: 1 bit Mask: 1 bit
Defines whether the payload data is masked. If set to 1, a Defines whether the "Payload data" is masked. If set to 1, a
masking key is present in masking-key, and this is used to unmask masking key is present in masking-key, and this is used to unmask
the payload data as per Section 5.3. All frames sent from client the "Payload data" as per Section 5.3. All frames sent from
to server have this bit set to 1. client to server have this bit set to 1.
Payload length: 7 bits, 7+16 bits, or 7+64 bits Payload length: 7 bits, 7+16 bits, or 7+64 bits
The length of the payload data, in bytes: if 0-125, that is the The length of the "Payload data", in bytes: if 0-125, that is the
payload length. If 126, the following 2 bytes interpreted as a 16 payload length. If 126, the following 2 bytes interpreted as a
bit unsigned integer are the payload length. If 127, the 16-bit unsigned integer are the payload length. If 127, the
following 8 bytes interpreted as a 64-bit unsigned integer (the following 8 bytes interpreted as a 64-bit unsigned integer (the
most significant bit MUST be 0) are the payload length. Multibyte most significant bit MUST be 0) are the payload length. Multibyte
length quantities are expressed in network byte order. Note that length quantities are expressed in network byte order. Note that
in all case the minimal number of bytes MUST be used to encode the in all cases, the minimal number of bytes MUST be used to encode
length, for example the length of a 124 byte long string can't be the length, for example, the length of a 124-byte-long string
encoded as the sequence 126, 0, 124. The payload length is the can't be encoded as the sequence 126, 0, 124. The payload length
length of the extension data + the length of the application data. is the length of the "Extension data" + the length of the
The length of the extension data may be zero, in which case the "Application data". The length of the "Extension data" may be
payload length is the length of the application data. zero, in which case the payload length is the length of the
"Application data".
Masking-key: 0 or 4 bytes Masking-key: 0 or 4 bytes
All frames sent from the client to the server are masked by a 32- All frames sent from the client to the server are masked by a
bit value that is contained within the frame. This field is 32-bit value that is contained within the frame. This field is
present if the mask bit is set to 1, and is absent if the mask bit present if the mask bit is set to 1 and is absent if the mask bit
is set to 0. See Section 5.3 for further information on client- is set to 0. See Section 5.3 for further information on client-
to-server masking. to-server masking.
Payload data: (x+y) bytes Payload data: (x+y) bytes
The payload data is defined as extension data concatenated with The "Payload data" is defined as "Extension data" concatenated
application data. with "Application data".
Extension data: x bytes Extension data: x bytes
The extension data is 0 bytes unless an extension has been The "Extension data" is 0 bytes unless an extension has been
negotiated. Any extension MUST specify the length of the negotiated. Any extension MUST specify the length of the
extension data, or how that length may be calculated, and how the "Extension data", or how that length may be calculated, and how
extension use MUST be negotiated during the opening handshake. If the extension use MUST be negotiated during the opening handshake.
present, the extension data is included in the total payload If present, the "Extension data" is included in the total payload
length. length.
Application data: y bytes Application data: y bytes
Arbitrary application data, taking up the remainder of the frame Arbitrary "Application data", taking up the remainder of the frame
after any extension data. The length of the application data is after any "Extension data". The length of the "Application data"
equal to the payload length minus the length of the extension is equal to the payload length minus the length of the "Extension
data. data".
The base framing protocol is formally defined by the following ABNF The base framing protocol is formally defined by the following ABNF
[RFC5234]. It is important to note that the representation of this [RFC5234]. It is important to note that the representation of this
data is binary, not ASCII characters. As such, a field with a length data is binary, not ASCII characters. As such, a field with a length
of 1 bit that takes values %x0 / %x1 is represented as a single bit of 1 bit that takes values %x0 / %x1 is represented as a single bit
whose value is 0 or 1, not a full byte (octet) that stands for the whose value is 0 or 1, not a full byte (octet) that stands for the
characters "0" or "1" in the ASCII encoding. A field with a length characters "0" or "1" in the ASCII encoding. A field with a length
of 4 bits with values between %x0-F again is represented by 4 bits, of 4 bits with values between %x0-F again is represented by 4 bits,
again NOT by an ASCII character or full byte (octet) with these again NOT by an ASCII character or full byte (octet) with these
values. [RFC5234] does not specify a character encoding - " Rules values. [RFC5234] does not specify a character encoding: "Rules
resolve into a string of terminal values, sometimes called resolve into a string of terminal values, sometimes called
characters. In ABNF, a character is merely a non-negative integer. characters. In ABNF, a character is merely a non-negative integer.
In certain contexts, a specific mapping (encoding) of values into a In certain contexts, a specific mapping (encoding) of values into a
character set (such as ASCII) will be specified." Here, the character set (such as ASCII) will be specified." Here, the
specified encoding is a binary encoding where each terminal value is specified encoding is a binary encoding where each terminal value is
encoded in the specified number of bits, which varies for each field. encoded in the specified number of bits, which varies for each field.
ws-frame = frame-fin ; 1 bit in length ws-frame = frame-fin ; 1 bit in length
frame-rsv1 ; 1 bit in length frame-rsv1 ; 1 bit in length
frame-rsv2 ; 1 bit in length frame-rsv2 ; 1 bit in length
frame-rsv3 ; 1 bit in length frame-rsv3 ; 1 bit in length
frame-opcode ; 4 bits in length frame-opcode ; 4 bits in length
frame-masked ; 1 bit in length frame-masked ; 1 bit in length
frame-payload-length ; 7 bits in length frame-payload-length ; either 7, 7+16,
[ frame-masking-key ] ; 16 or 64 bits in length ; or 7+64 bits in
frame-payload-data ; n * 8 bits in length, ; length
; where n >= 0 [ frame-masking-key ] ; 32 bits in length
frame-payload-data ; n*8 bits in
; length, where
; n >= 0
frame-fin = %x0 ; more frames of this message follow frame-fin = %x0 ; more frames of this message follow
/ %x1 ; final frame of this message / %x1 ; final frame of this message
; 1 bit in length ; 1 bit in length
frame-rsv1 = %x0 / %x1 frame-rsv1 = %x0 / %x1
; 1 bit in length, MUST be 0 unless negotiated ; 1 bit in length, MUST be 0 unless
; otherwise ; negotiated otherwise
frame-rsv2 = %x0 / %x1 frame-rsv2 = %x0 / %x1
; 1 bit in length, MUST be 0 unless negotiated ; 1 bit in length, MUST be 0 unless
; otherwise ; negotiated otherwise
frame-rsv3 = %x0 / %x1 frame-rsv3 = %x0 / %x1
; 1 bit in length, MUST be 0 unless negotiated ; 1 bit in length, MUST be 0 unless
; otherwise ; negotiated otherwise
frame-opcode = frame-opcode-non-control / frame-opcode = frame-opcode-non-control /
frame-opcode-control frame-opcode-control /
frame-opcode-cont
frame-opcode-non-control= %x1 ; text frame frame-opcode-cont = %x0 ; frame continuation
/ %x2 ; binary frame
/ %x3-7
; reserved for further non-control frames
frame-opcode-control = %x8 ; connection close frame-opcode-non-control= %x1 ; text frame
/ %x9 ; ping / %x2 ; binary frame
/ %xA ; pong / %x3-7
/ %xB-F ; reserved for further control frames ; 4 bits in length,
; 4 bits in length ; reserved for further non-control frames
frame-masked = %x0 frame-opcode-control = %x8 ; connection close
; frame is not masked, no frame-masking-key / %x9 ; ping
/ %x1 / %xA ; pong
; frame is masked, frame-masking-key present / %xB-F ; reserved for further control
; 1 bit in length ; frames
; 4 bits in length
frame-payload-length = %x00-7D frame-masked = %x0
/ %x7E frame-payload-length-16 ; frame is not masked, no frame-masking-key
/ %x7F frame-payload-length-63 / %x1
; 7 bits in length ; frame is masked, frame-masking-key present
; 1 bit in length
frame-payload-length-16 = %x0000-FFFF ; 16 bits in length frame-payload-length = ( %x00-7D )
/ ( %x7E frame-payload-length-16 )
/ ( %x7F frame-payload-length-63 )
; 7, 7+16, or 7+64 bits in length,
; respectively
frame-payload-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF frame-payload-length-16 = %x0000-FFFF ; 16 bits in length
; 64 bits in length
frame-masking-key = 4( %0x00-FF ) frame-payload-length-63 = %x0000000000000000-7FFFFFFFFFFFFFFF
; present only if frame-masked is 1 ; 64 bits in length
; 32 bits in length
frame-payload-data = (frame-masked-extension-data frame-masking-key = 4( %x00-FF )
frame-masked-application-data) ; present only if frame-masked is 1
; frame-masked 1 ; 32 bits in length
/ (frame-unmasked-extension-data
frame-unmasked-application-data)
; frame-masked 0
frame-masked-extension-data = *( %x00-FF ) frame-payload-data = (frame-masked-extension-data
; reserved for future extensibility frame-masked-application-data)
; n*8 bits in length , where n >= 0 ; when frame-masked is 1
/ (frame-unmasked-extension-data
frame-unmasked-application-data)
; when frame-masked is 0
frame-masked-application-data = *( %x00-FF ) frame-masked-extension-data = *( %x00-FF )
; n*8 bits in length, where n >= 0 ; reserved for future extensibility
; n*8 bits in length, where n >= 0
frame-unmasked-extension-data = *( %x00-FF ) frame-masked-application-data = *( %x00-FF )
; reserved for future extensibility ; n*8 bits in length, where n >= 0
; n*8 bits in length, where n >= 0
frame-unmasked-application-data = *( %x00-FF ) frame-unmasked-extension-data = *( %x00-FF )
; n*8 bits in length, where n >= 0 ; reserved for future extensibility
; n*8 bits in length, where n >= 0
frame-unmasked-application-data = *( %x00-FF )
; n*8 bits in length, where n >= 0
5.3. Client-to-Server Masking 5.3. Client-to-Server Masking
A masked frame MUST have the field frame-masked set to 1, as defined A masked frame MUST have the field frame-masked set to 1, as defined
in Section 5.2. in Section 5.2.
The masking key is contained completely within the frame, as defined The masking key is contained completely within the frame, as defined
in Section 5.2 as frame-masking-key. It is used to mask the payload in Section 5.2 as frame-masking-key. It is used to mask the "Payload
data defined in the same section as frame-payload-data, which data" defined in the same section as frame-payload-data, which
includes extension and application data. includes "Extension data" and "Application data".
The masking key is a 32-bit value chosen at random by the client. The masking key is a 32-bit value chosen at random by the client.
When preparing a masked frame, the client MUST pick a fresh masking When preparing a masked frame, the client MUST pick a fresh masking
key from the set of allowed 32-bit values. The masking key needs to key from the set of allowed 32-bit values. The masking key needs to
be unpredictable, thus the masking key MUST be derived from a strong be unpredictable; thus, the masking key MUST be derived from a strong
source of entropy, and the masking key for a given frame MUST NOT source of entropy, and the masking key for a given frame MUST NOT
make it simple for a server/proxy to predict the masking key for a make it simple for a server/proxy to predict the masking key for a
subsequent frame. The unpredictability of the masking key is subsequent frame. The unpredictability of the masking key is
essential to prevent the author of malicious applications from essential to prevent authors of malicious applications from selecting
selecting the bytes that appear on the wire. RFC 4086 [RFC4086] the bytes that appear on the wire. RFC 4086 [RFC4086] discusses what
discusses what entails a suitable source of entropy for security- entails a suitable source of entropy for security-sensitive
sensitive applications. applications.
The masking does not affect the length of the payload data. To The masking does not affect the length of the "Payload data". To
convert masked data into unmasked data, or vice versa, the following convert masked data into unmasked data, or vice versa, the following
algorithm is applied. The same algorithm applies regardless of the algorithm is applied. The same algorithm applies regardless of the
direction of the translation - e.g. the same steps are applied to direction of the translation, e.g., the same steps are applied to
mask the data as to unmask the data. mask the data as to unmask the data.
Octet i of the transformed data ("transformed-octet-i") is the XOR of Octet i of the transformed data ("transformed-octet-i") is the XOR of
octet i of the original data ("original-octet-i") with octet at index octet i of the original data ("original-octet-i") with octet at index
i modulo 4 of the masking key ("masking-key-octet-j"): i modulo 4 of the masking key ("masking-key-octet-j"):
j = i MOD 4 j = i MOD 4
transformed-octet-i = original-octet-i XOR masking-key-octet-j transformed-octet-i = original-octet-i XOR masking-key-octet-j
The payload length, indicated in the framing as frame-payload-length, The payload length, indicated in the framing as frame-payload-length,
does NOT include the length of the masking key. It is the length of does NOT include the length of the masking key. It is the length of
the payload data, e.g. the number of bytes following the masking key. the "Payload data", e.g., the number of bytes following the masking
key.
5.4. Fragmentation 5.4. Fragmentation
The primary purpose of fragmentation is to allow sending a message The primary purpose of fragmentation is to allow sending a message
that is of unknown size when the message is started without having to that is of unknown size when the message is started without having to
buffer that message. If messages couldn't be fragmented, then an buffer that message. If messages couldn't be fragmented, then an
endpoint would have to buffer the entire message so its length could endpoint would have to buffer the entire message so its length could
be counted before first byte is sent. With fragmentation, a server be counted before the first byte is sent. With fragmentation, a
or intermediary may choose a reasonable size buffer, and when the server or intermediary may choose a reasonable size buffer and, when
buffer is full write a fragment to the network. the buffer is full, write a fragment to the network.
A secondary use-case for fragmentation is for multiplexing, where it A secondary use-case for fragmentation is for multiplexing, where it
is not desirable for a large message on one logical channel to is not desirable for a large message on one logical channel to
monopolize the output channel, so the MUX needs to be free to split monopolize the output channel, so the multiplexing needs to be free
the message into smaller fragments to better share the output to split the message into smaller fragments to better share the
channel. (Note that the multiplexing extension is not described in output channel. (Note that the multiplexing extension is not
this document.) described in this document.)
Unless specified otherwise by an extension, frames have no semantic Unless specified otherwise by an extension, frames have no semantic
meaning. An intermediary might coalesce and/or split frames, if no meaning. An intermediary might coalesce and/or split frames, if no
extensions were negotiated by the client and the server, or if some extensions were negotiated by the client and the server or if some
extensions were negotiated, but the intermediary understood all the extensions were negotiated, but the intermediary understood all the
extensions negotiated and knows how to coalesce and/or split frames extensions negotiated and knows how to coalesce and/or split frames
in presence of these extensions. One implication of this is that in in the presence of these extensions. One implication of this is that
absence of extensions senders and receivers must not depend on in absence of extensions, senders and receivers must not depend on
presence of specific frame boundaries. the presence of specific frame boundaries.
The following rules apply to fragmentation: The following rules apply to fragmentation:
o An unfragmented message consists of a single frame with the FIN o An unfragmented message consists of a single frame with the FIN
bit set (Section 5.2) and an opcode other than 0. bit set (Section 5.2) and an opcode other than 0.
o A fragmented message consists of a single frame with the FIN bit 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 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 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. A a single frame with the FIN bit set and an opcode of 0. A
fragmented message is conceptually equivalent to a single larger fragmented message is conceptually equivalent to a single larger
message whose payload is equal to the concatenation of the message whose payload is equal to the concatenation of the
payloads of the fragments in order, however in the presence of payloads of the fragments in order; however, in the presence of
extensions this may not hold true as the extension defines the extensions, this may not hold true as the extension defines the
interpretation of the extension data present. For instance, interpretation of the "Extension data" present. For instance,
extension data may only be present at the beginning of the first "Extension data" may only be present at the beginning of the first
fragment and apply to subsequent fragments, or there may be fragment and apply to subsequent fragments, or there may be
extension data present in each of the fragments that applies only "Extension data" present in each of the fragments that applies
to that particular fragment. In absence of extension data, the only to that particular fragment. In the absence of "Extension
following example demonstrates how fragmentation works. data", the following example demonstrates how fragmentation works.
EXAMPLE: For a text message sent as three fragments, the first EXAMPLE: For a text message sent as three fragments, the first
fragment would have an opcode of 0x1 and a FIN bit clear, the fragment would have an opcode of 0x1 and a FIN bit clear, the
second fragment would have an opcode of 0x0 and a FIN bit clear, second fragment would have an opcode of 0x0 and a FIN bit clear,
and the third fragment would have an opcode of 0x0 and a FIN bit and the third fragment would have an opcode of 0x0 and a FIN bit
that is set. that is set.
o Control frames (see Section 5.5) MAY be injected in the middle of o Control frames (see Section 5.5) MAY be injected in the middle of
a fragmented message. Control frames themselves MUST NOT be a fragmented message. Control frames themselves MUST NOT be
fragmented. fragmented.
skipping to change at page 37, line 48 skipping to change at page 35, line 35
o An intermediary MUST NOT change the fragmentation of any message o An intermediary MUST NOT change the fragmentation of any message
in the context of a connection where extensions have been in the context of a connection where extensions have been
negotiated and the intermediary is not aware of the semantics of negotiated and the intermediary is not aware of the semantics of
the negotiated extensions. Similarly, an intermediary that didn't the negotiated extensions. Similarly, an intermediary that didn't
see the WebSocket handshake (and wasn't notified about its see the WebSocket handshake (and wasn't notified about its
content) that resulted in a WebSocket connection MUST NOT change content) that resulted in a WebSocket connection MUST NOT change
the fragmentation of any message of such connection. the fragmentation of any message of such connection.
o As a consequence of these rules, all fragments of a message are of o As a consequence of these rules, all fragments of a message are of
the same type, as set by the first fragment's opcode. Since the same type, as set by the first fragment's opcode. Since
Control frames cannot be fragmented, the type for all fragments in control frames cannot be fragmented, the type for all fragments in
a message MUST be either text or binary, or one of the reserved a message MUST be either text, binary, or one of the reserved
opcodes. opcodes.
_Note: if control frames could not be interjected, the latency of a NOTE: If control frames could not be interjected, the latency of a
ping, for example, would be very long if behind a large message. ping, for example, would be very long if behind a large message.
Hence, the requirement of handling control frames in the middle of a Hence, the requirement of handling control frames in the middle of a
fragmented message._ fragmented message.
_Implementation Note: in absence of any extension a receiver doesn't IMPLEMENTATION NOTE: In the absence of any extension, a receiver
have to buffer the whole frame in order to process it. For example doesn't have to buffer the whole frame in order to process it. For
if a streaming API is used, a part of a frame can be delivered to the example, if a streaming API is used, a part of a frame can be
application. But note that that assumption might not hold true for delivered to the application. However, note that this assumption
all future WebSocket extensions._ might not hold true for all future WebSocket extensions.
5.5. Control Frames 5.5. Control Frames
Control frames are identified by opcodes where the most significant Control frames are identified by opcodes where the most significant
bit of the opcode is 1. Currently defined opcodes for control frames bit of the opcode is 1. Currently defined opcodes for control frames
include 0x8 (Close), 0x9 (Ping), and 0xA (Pong). Opcodes 0xB-0xF are include 0x8 (Close), 0x9 (Ping), and 0xA (Pong). Opcodes 0xB-0xF are
reserved for further control frames yet to be defined. reserved for further control frames yet to be defined.
Control frames are used to communicate state about the WebSocket. Control frames are used to communicate state about the WebSocket.
Control frames can be interjected in the middle of a fragmented Control frames can be interjected in the middle of a fragmented
message. message.
All control frames MUST have a payload length of 125 bytes or less All control frames MUST have a payload length of 125 bytes or less
and MUST NOT be fragmented. and MUST NOT be fragmented.
5.5.1. Close 5.5.1. Close
The Close frame contains an opcode of 0x8. The Close frame contains an opcode of 0x8.
The Close frame MAY contain a body (the "application data" portion of The Close frame MAY contain a body (the "Application data" portion of
the frame) that indicates a reason for closing, such as an endpoint the frame) that indicates a reason for closing, such as an endpoint
shutting down, an endpoint having received a frame too large, or an shutting down, an endpoint having received a frame too large, or an
endpoint having received a frame that does not conform to the format endpoint having received a frame that does not conform to the format
expected by the other endpoint. If there is a body, the first two expected by the endpoint. If there is a body, the first two bytes of
bytes of the body MUST be a 2-byte unsigned integer (in network byte the body MUST be a 2-byte unsigned integer (in network byte order)
order) representing a status code with value /code/ defined in representing a status code with value /code/ defined in Section 7.4.
Section 7.4. Following the 2-byte integer the body MAY contain UTF-8 Following the 2-byte integer, the body MAY contain UTF-8-encoded data
encoded data with value /reason/, the interpretation of which is not with value /reason/, the interpretation of which is not defined by
defined by this specification. This data is not necessarily human this specification. This data is not necessarily human readable but
readable, but may be useful for debugging or passing information may be useful for debugging or passing information relevant to the
relevant to the script that opened the connection. As the data is script that opened the connection. As the data is not guaranteed to
not guaranteed to be human readable, clients MUST NOT show it to end be human readable, clients MUST NOT show it to end users.
users.
Close frames sent from client to server must be masked as per Close frames sent from client to server must be masked as per
Section 5.3. Section 5.3.
The application MUST NOT send any more data frames after sending a The application MUST NOT send any more data frames after sending a
close frame. Close frame.
If an endpoint receives a Close frame and that endpoint did not If an endpoint receives a Close frame and did not previously send a
previously send a Close frame, the endpoint MUST send a Close frame Close frame, the endpoint MUST send a Close frame in response. (When
in response. (When sending a Close frame in response the endpoint sending a Close frame in response, the endpoint typically echos the
typically echos the status code it received.) It SHOULD do so as status code it received.) It SHOULD do so as soon as practical. An
soon as practical. An endpoint MAY delay sending a close frame until endpoint MAY delay sending a Close frame until its current message is
its current message is sent (for instance, if the majority of a sent (for instance, if the majority of a fragmented message is
fragmented message is already sent, an endpoint MAY send the already sent, an endpoint MAY send the remaining fragments before
remaining fragments before sending a Close frame). However, there is sending a Close frame). However, there is no guarantee that the
no guarantee that the endpoint which has already sent a Close frame endpoint that has already sent a Close frame will continue to process
will continue to process data. data.
After both sending and receiving a close message, an endpoint After both sending and receiving a Close message, an endpoint
considers the WebSocket connection closed, and MUST close the considers the WebSocket connection closed and MUST close the
underlying TCP connection. The server MUST close the underlying TCP underlying TCP connection. The server MUST close the underlying TCP
connection immediately; the client SHOULD wait for the server to connection immediately; the client SHOULD wait for the server to
close the connection but MAY close the connection at any time after close the connection but MAY close the connection at any time after
sending and receiving a close message, e.g. if it has not received a sending and receiving a Close message, e.g., if it has not received a
TCP close from the server in a reasonable time period. TCP Close from the server in a reasonable time period.
If a client and server both send a Close message at the same time, If a client and server both send a Close message at the same time,
both endpoints will have sent and received a Close message and should both endpoints will have sent and received a Close message and should
consider the WebSocket connection closed and close the underlying TCP consider the WebSocket connection closed and close the underlying TCP
connection. connection.
5.5.2. Ping 5.5.2. Ping
The Ping frame contains an opcode of 0x9. The Ping frame contains an opcode of 0x9.
A Ping frame MAY include Application Data. A Ping frame MAY include "Application data".
Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in Upon receipt of a Ping frame, an endpoint MUST send a Pong frame in
response, unless it already received a Close frame. It SHOULD response, unless it already received a Close frame. It SHOULD
respond with Pong frame as soon as is practical. Pong frames are respond with Pong frame as soon as is practical. Pong frames are
discussed in Section 5.5.3. discussed in Section 5.5.3.
An endpoint MAY send a Ping frame any time after the connection is An endpoint MAY send a Ping frame any time after the connection is
established and before the connection is closed. NOTE: A ping frame established and before the connection is closed.
may serve either as a keepalive, or to verify that the remote
endpoint is still responsive. NOTE: A Ping frame may serve either as a keepalive or as a means to
verify that the remote endpoint is still responsive.
5.5.3. Pong 5.5.3. Pong
The Pong frame contains an opcode of 0xA. The Pong frame contains an opcode of 0xA.
Section 5.5.2 details requirements that apply to both Ping and Pong Section 5.5.2 details requirements that apply to both Ping and Pong
frames. frames.
A Pong frame sent in response to a Ping frame must have identical A Pong frame sent in response to a Ping frame must have identical
Application Data as found in the message body of the Ping frame being "Application data" as found in the message body of the Ping frame
replied to. being replied to.
If an endpoint receives a Ping frame and has not yet sent Pong If an endpoint receives a Ping frame and has not yet sent Pong
frame(s) in response to previous Ping frame(s), the endpoint MAY frame(s) in response to previous Ping frame(s), the endpoint MAY
elect to send a Pong frame for only the most recently processed Ping elect to send a Pong frame for only the most recently processed Ping
frame. frame.
A Pong frame MAY be sent unsolicited. This serves as a A Pong frame MAY be sent unsolicited. This serves as a
unidirectional heartbeat. A response to an unsolicited pong is not unidirectional heartbeat. A response to an unsolicited Pong frame is
expected. not expected.
5.6. Data Frames 5.6. Data Frames
Data frames (e.g. non-control frames) are identified by opcodes where Data frames (e.g., non-control frames) are identified by opcodes
the most significant bit of the opcode is 0. Currently defined where the most significant bit of the opcode is 0. Currently defined
opcodes for data frames include 0x1 (Text), 0x2 (Binary). Opcodes opcodes for data frames include 0x1 (Text), 0x2 (Binary). Opcodes
0x3-0x7 are reserved for further non-control frames yet to be 0x3-0x7 are reserved for further non-control frames yet to be
defined. defined.
Data frames carry application-layer and/or extension-layer data. The Data frames carry application-layer and/or extension-layer data. The
opcode determines the interpretation of the data: opcode determines the interpretation of the data:
Text Text
The payload data is text data encoded as UTF-8. Note that a The "Payload data" is text data encoded as UTF-8. Note that a
particular text frame might include a partial UTF-8 sequence, particular text frame might include a partial UTF-8 sequence;
however the whole message MUST contain valid UTF-8. Invalid UTF-8 however, the whole message MUST contain valid UTF-8. Invalid
in reassembled messages is handled as described in Section 8.1. UTF-8 in reassembled messages is handled as described in
Section 8.1.
Binary Binary
The payload data is arbitrary binary data whose interpretation is The "Payload data" is arbitrary binary data whose interpretation
solely up to the application layer. is solely up to the application layer.
5.7. Examples 5.7. Examples
o A single-frame unmasked text message o A single-frame unmasked text message
* 0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello") * 0x81 0x05 0x48 0x65 0x6c 0x6c 0x6f (contains "Hello")
o A single-frame masked text message o A single-frame masked text message
* 0x81 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58 * 0x81 0x85 0x37 0xfa 0x21 0x3d 0x7f 0x9f 0x4d 0x51 0x58
skipping to change at page 41, line 33 skipping to change at page 39, line 27
o 64KiB binary message in a single unmasked frame o 64KiB binary message in a single unmasked frame
* 0x82 0x7F 0x0000000000010000 [65536 bytes of binary data] * 0x82 0x7F 0x0000000000010000 [65536 bytes of binary data]
5.8. Extensibility 5.8. Extensibility
The protocol is designed to allow for extensions, which will add The protocol is designed to allow for extensions, which will add
capabilities to the base protocol. The endpoints of a connection capabilities to the base protocol. The endpoints of a connection
MUST negotiate the use of any extensions during the opening MUST negotiate the use of any extensions during the opening
handshake. This specification provides opcodes 0x3 through 0x7 and handshake. This specification provides opcodes 0x3 through 0x7 and
0xB through 0xF, the extension data field, and the frame-rsv1, frame- 0xB through 0xF, the "Extension data" field, and the frame-rsv1,
rsv2, and frame-rsv3 bits of the frame header for use by extensions. frame-rsv2, and frame-rsv3 bits of the frame header for use by
The negotiation of extensions is discussed in further detail in extensions. The negotiation of extensions is discussed in further
Section 9.1. Below are some anticipated uses of extensions. This detail in Section 9.1. Below are some anticipated uses of
list is neither complete nor prescriptive. extensions. This list is neither complete nor prescriptive.
o Extension data may be placed in the payload data before the o "Extension data" may be placed in the "Payload data" before the
application data. "Application data".
o Reserved bits can be allocated for per-frame needs. o Reserved bits can be allocated for per-frame needs.
o Reserved opcode values can be defined. o Reserved opcode values can be defined.
o Reserved bits can be allocated to the opcode field if more opcode o Reserved bits can be allocated to the opcode field if more opcode
values are needed. values are needed.
o A reserved bit or an "extension" opcode can be defined which o A reserved bit or an "extension" opcode can be defined that
allocates additional bits out of the payload data to define larger allocates additional bits out of the "Payload data" to define
opcodes or more per-frame bits. larger opcodes or more per-frame bits.
6. Sending and Receiving Data 6. Sending and Receiving Data
6.1. Sending Data 6.1. Sending Data
To _Send a WebSocket Message_ comprising of /data/ over a WebSocket To _Send a WebSocket Message_ comprising of /data/ over a WebSocket
connection, an endpoint MUST perform the following steps. connection, an endpoint MUST perform the following steps.
1. The endpoint MUST ensure the WebSocket connection is in the OPEN 1. The endpoint MUST ensure the WebSocket connection is in the OPEN
state (cf. Section 4.1 and Section 4.2.2.) If at any point the state (cf. Sections 4.1 and 4.2.2.) If at any point the state of
state of the WebSocket connection changes, the endpoint MUST the WebSocket connection changes, the endpoint MUST abort the
abort the following steps. following steps.
2. An endpoint MUST encapsulate the /data/ in a WebSocket frame as 2. An endpoint MUST encapsulate the /data/ in a WebSocket frame as
defined in Section 5.2. If the data to be sent is large, or if defined in Section 5.2. If the data to be sent is large or if
the data is not available in its entirety at the point the the data is not available in its entirety at the point the
endpoint wishes to begin sending the data, the endpoint MAY endpoint wishes to begin sending the data, the endpoint MAY
alternately encapsulate the data in a series of frames as defined alternately encapsulate the data in a series of frames as defined
in Section 5.4. in Section 5.4.
3. The opcode (frame-opcode) of the first frame containing the data 3. The opcode (frame-opcode) of the first frame containing the data
MUST be set to the appropriate value from Section 5.2 for data MUST be set to the appropriate value from Section 5.2 for data
that is to be interpreted by the recipient as text or binary that is to be interpreted by the recipient as text or binary
data. data.
skipping to change at page 42, line 49 skipping to change at page 40, line 42
7. The frame(s) that have been formed MUST be transmitted over the 7. The frame(s) that have been formed MUST be transmitted over the
underlying network connection. underlying network connection.
6.2. Receiving Data 6.2. Receiving Data
To receive WebSocket data, an endpoint listens on the underlying To receive WebSocket data, an endpoint listens on the underlying
network connection. Incoming data MUST be parsed as WebSocket frames network connection. Incoming data MUST be parsed as WebSocket frames
as defined in Section 5.2. If a control frame (Section 5.5) is as defined in Section 5.2. If a control frame (Section 5.5) is
received, the frame MUST be handled as defined by Section 5.5. Upon received, the frame MUST be handled as defined by Section 5.5. Upon
receiving a data frame (Section 5.6), the endpoint MUST note the receiving a data frame (Section 5.6), the endpoint MUST note the
/type/ of the data as defined by the Opcode (frame-opcode) from /type/ of the data as defined by the opcode (frame-opcode) from
Section 5.2. The _Application Data_ from this frame is defined as Section 5.2. The "Application data" from this frame is defined as
the /data/ of the message. If the frame comprises an unfragmented the /data/ of the message. If the frame comprises an unfragmented
message (Section 5.4), it is said that _A WebSocket Message Has Been message (Section 5.4), it is said that _A WebSocket Message Has Been
Received_ with type /type/ and data /data/. If the frame is part of Received_ with type /type/ and data /data/. If the frame is part of
a fragmented message, the _Application Data_ of the subsequent data a fragmented message, the "Application data" of the subsequent data
frames is concatenated to form the /data/. When the last fragment is frames is concatenated to form the /data/. When the last fragment is
received as indicated by the FIN bit (frame-fin), it is said that _A received as indicated by the FIN bit (frame-fin), it is said that _A
WebSocket Message Has Been Received_ with data /data/ (comprised of WebSocket Message Has Been Received_ with data /data/ (comprised of
the concatenation of the _Application Data_ of the fragments) and the concatenation of the "Application data" of the fragments) and
type /type/ (noted from the first frame of the fragmented message). type /type/ (noted from the first frame of the fragmented message).
Subsequent data frames MUST be interpreted as belonging to a new Subsequent data frames MUST be interpreted as belonging to a new
WebSocket Message. WebSocket message.
Extensions (Section 9) MAY change the semantics of how data is read, Extensions (Section 9) MAY change the semantics of how data is read,
specifically including what comprises a message boundary. specifically including what comprises a message boundary.
Extensions, in addition to adding "Extension data" before the Extensions, in addition to adding "Extension data" before the
"Application data" in a payload, MAY also modify the "Application "Application data" in a payload, MAY also modify the "Application
data" (such as by compressing it). data" (such as by compressing it).
A server MUST remove masking for data frames received from a client A server MUST remove masking for data frames received from a client
as described in Section 5.3. as described in Section 5.3.
7. Closing the connection 7. Closing the Connection
7.1. Definitions 7.1. Definitions
7.1.1. Close the WebSocket Connection 7.1.1. Close the WebSocket Connection
To _Close the WebSocket Connection_, an endpoint closes the To _Close the WebSocket Connection_, an endpoint closes the
underlying TCP connection. An endpoint SHOULD use a method that underlying TCP connection. An endpoint SHOULD use a method that
cleanly closes the TCP connection, as well as the TLS session, if cleanly closes the TCP connection, as well as the TLS session, if
applicable, discarding any trailing bytes that may be received. An applicable, discarding any trailing bytes that may have been
endpoint MAY close the connection via any means available when received. An endpoint MAY close the connection via any means
necessary, such as when under attack. available when necessary, such as when under attack.
The underlying TCP connection, in most normal cases, SHOULD be closed The underlying TCP connection, in most normal cases, SHOULD be closed
first by the server, so that it holds the TIME_WAIT state and not the first by the server, so that it holds the TIME_WAIT state and not the
client (as this would prevent it from re-opening the connection for 2 client (as this would prevent it from re-opening the connection for 2
MSL, while there is no corresponding server impact as a TIME_WAIT maximum segment lifetimes (2MSL), while there is no corresponding
connection is immediately reopened upon a new SYN with a higher seq server impact as a TIME_WAIT connection is immediately reopened upon
number). In abnormal cases (such as not having received a TCP Close a new SYN with a higher seq number). In abnormal cases (such as not
from the server after a reasonable amount of time) a client MAY having received a TCP Close from the server after a reasonable amount
initiate the TCP Close. As such, when a server is instructed to of time) a client MAY initiate the TCP Close. As such, when a server
_Close the WebSocket Connection_ it SHOULD initiate a TCP Close is instructed to _Close the WebSocket Connection_ it SHOULD initiate
immediately, and when a client is instructed to do the same, it a TCP Close immediately, and when a client is instructed to do the
SHOULD wait for a TCP Close from the server. same, it SHOULD wait for a TCP Close from the server.
As an example of how to obtain a clean closure in C using Berkeley As an example of how to obtain a clean closure in C using Berkeley
sockets, one would call shutdown() with SHUT_WR on the socket, call sockets, one would call shutdown() with SHUT_WR on the socket, call
recv() until obtaining a return value of 0 indicating that the peer recv() until obtaining a return value of 0 indicating that the peer
has also performed an orderly shutdown, and finally calling close() has also performed an orderly shutdown, and finally call close() on
on the socket. the socket.
7.1.2. Start the WebSocket Closing Handshake 7.1.2. Start the WebSocket Closing Handshake
To _Start the WebSocket Closing Handshake_ with a status code To _Start the WebSocket Closing Handshake_ with a status code
(Section 7.4) /code/ and an optional close reason (Section 7.1.6) (Section 7.4) /code/ and an optional close reason (Section 7.1.6)
/reason/, an endpoint MUST send a Close control frame, as described /reason/, an endpoint MUST send a Close control frame, as described
in Section 5.5.1 whose status code is set to /code/ and whose close in Section 5.5.1, whose status code is set to /code/ and whose close
reason is set to /reason/. Once an endpoint has both sent and reason is set to /reason/. Once an endpoint has both sent and
received a Close control frame, that endpoint SHOULD _Close the received a Close control frame, that endpoint SHOULD _Close the
WebSocket Connection_ as defined in Section 7.1.1. WebSocket Connection_ as defined in Section 7.1.1.
7.1.3. The WebSocket Closing Handshake is Started 7.1.3. The WebSocket Closing Handshake is Started
Upon either sending or receiving a Close control frame, it is said Upon either sending or receiving a Close control frame, it is said
that _The WebSocket Closing Handshake is Started_ and that the that _The WebSocket Closing Handshake is Started_ and that the
WebSocket connection is in the CLOSING state. WebSocket connection is in the CLOSING state.
7.1.4. The WebSocket Connection is Closed 7.1.4. The WebSocket Connection is Closed
When the underlying TCP connection is closed, it is said that _The When the underlying TCP connection is closed, it is said that _The
WebSocket Connection is Closed_ and that the WebSocket connection is WebSocket Connection is Closed_ and that the WebSocket connection is
in the CLOSED state. If the tcp connection was closed after the in the CLOSED state. If the TCP connection was closed after the
WebSocket closing handshake was completed, the WebSocket connection WebSocket closing handshake was completed, the WebSocket connection
is said to have been closed _cleanly_. is said to have been closed _cleanly_.
If the WebSocket connection could not be established, it is also said If the WebSocket connection could not be established, it is also said
that _The WebSocket Connection is Closed_, but not cleanly. that _The WebSocket Connection is Closed_, but not _cleanly_.
7.1.5. The WebSocket Connection Close Code 7.1.5. The WebSocket Connection Close Code
As defined in Section 5.5.1 and Section 7.4, a Close control frame As defined in Sections 5.5.1 and 7.4, a Close control frame may
may contain a status code indicating a reason for closure. A closing contain a status code indicating a reason for closure. A closing of
of the WebSocket connection may be initiated by either endpoint, the WebSocket connection may be initiated by either endpoint,
potentially simultaneously. _The WebSocket Connection Close Code_ is potentially simultaneously. _The WebSocket Connection Close Code_ is
defined as the status code (Section 7.4) contained in the first Close defined as the status code (Section 7.4) contained in the first Close
control frame received by the application implementing this protocol. control frame received by the application implementing this protocol.
If this Close control frame contains no status code, _The WebSocket If this Close control frame contains no status code, _The WebSocket
Connection Close Code_ is considered to be 1005. If _The WebSocket Connection Close Code_ is considered to be 1005. If _The WebSocket
Connection is Closed_ and no Close control frame was received by the Connection is Closed_ and no Close control frame was received by the
endpoint (such as could occur if the underlying transport connection endpoint (such as could occur if the underlying transport connection
is lost), _The WebSocket Connection Close Code_ is considered to be is lost), _The WebSocket Connection Close Code_ is considered to be
1006. 1006.
NOTE: Two endpoints may not agree on the value of _The WebSocket NOTE: Two endpoints may not agree on the value of _The WebSocket
Connection Close Code_. As an example, if the remote endpoint sent a Connection Close Code_. As an example, if the remote endpoint sent a
Close frame but the local application has not yet read the data Close frame but the local application has not yet read the data
containing the Close frame from its socket's receive buffer, and the containing the Close frame from its socket's receive buffer, and the
local application independently decided to close the connection and local application independently decided to close the connection and
send a Close frame, both endpoints will have sent and received a send a Close frame, both endpoints will have sent and received a
Close frame, and will not send further Close frames. Each endpoint Close frame and will not send further Close frames. Each endpoint
will see the Connection Close Code sent by the other end as the will see the status code sent by the other end as _The WebSocket
_WebSocket Connection Close Code_. As such, it is possible that the Connection Close Code_. As such, it is possible that the two
two endpoints may not agree on the value of _The WebSocket Connection endpoints may not agree on the value of _The WebSocket Connection
Close Code_ in the case that both endpoints _Start the WebSocket Close Code_ in the case that both endpoints _Start the WebSocket
Closing Handshake_ independently and at roughly the same time. Closing Handshake_ independently and at roughly the same time.
7.1.6. The WebSocket Connection Close Reason 7.1.6. The WebSocket Connection Close Reason
As defined in Section 5.5.1 and Section 7.4, a Close control frame As defined in Sections 5.5.1 and 7.4, a Close control frame may
may contain a status code indicating a reason for closure, followed contain a status code indicating a reason for closure, followed by
by UTF-8 encoded data, the interpretation of said data being left to UTF-8-encoded data, the interpretation of said data being left to the
the endpoints and not defined by this protocol. A closing of the endpoints and not defined by this protocol. A closing of the
WebSocket connection may be initiated by either endpoint, potentially WebSocket connection may be initiated by either endpoint, potentially
simultaneously. _The WebSocket Connection Close Reason_ is defined as simultaneously. _The WebSocket Connection Close Reason_ is defined as
the UTF-8 encoded data following the status code (Section 7.4) the UTF-8-encoded data following the status code (Section 7.4)
contained in the first Close control frame received by the contained in the first Close control frame received by the
application implementing this protocol. If there is no such data in application implementing this protocol. If there is no such data in
the Close control frame, _The WebSocket Connection Close Reason_ is the Close control frame, _The WebSocket Connection Close Reason_ is
the empty string. the empty string.
NOTE: Following the same logic as noted in Section 7.1.5, two NOTE: Following the same logic as noted in Section 7.1.5, two
endpoints may not agree on _The WebSocket Connection Close Reason_. endpoints may not agree on _The WebSocket Connection Close Reason_.
7.1.7. Fail the WebSocket Connection 7.1.7. Fail the WebSocket Connection
Certain algorithms and specifications require an endpoint to _Fail Certain algorithms and specifications require an endpoint to _Fail
the WebSocket Connection_. To do so, the client MUST _Close the the WebSocket Connection_. To do so, the client MUST _Close the
WebSocket Connection_, and MAY report the problem to the user (which WebSocket Connection_, and MAY report the problem to the user (which
would be especially useful for developers) in an appropriate manner. would be especially useful for developers) in an appropriate manner.
Similarly, to do so, the server MUST _Close the WebSocket Similarly, to do so, the server MUST _Close the WebSocket
Connection_, and SHOULD log the problem. Connection_, and SHOULD log the problem.
If _The WebSocket Connection is Established_ prior to the point where If _The WebSocket Connection is Established_ prior to the point where
the endpoint is required to _Fail the WebSocket Connection_, the the endpoint is required to _Fail the WebSocket Connection_, the
endpoint SHOULD send a Close frame with an appropriate status code endpoint SHOULD send a Close frame with an appropriate status code
Section 7.4 before proceeding to _Close the WebSocket Connection_. (Section 7.4) before proceeding to _Close the WebSocket Connection_.
An endpoint MAY omit sending a Close frame if it believes the other An endpoint MAY omit sending a Close frame if it believes the other
side is unlikely to be able to receive and process the close frame, side is unlikely to be able to receive and process the Close frame,
due to the nature of the error that led to the WebSocket connection due to the nature of the error that led the WebSocket connection to
being failed in the first place. An endpoint MUST NOT continue to fail in the first place. An endpoint MUST NOT continue to attempt to
attempt to process data (including a responding Close frame) from the process data (including a responding Close frame) from the remote
remote endpoint after being instructed to _Fail the WebSocket endpoint after being instructed to _Fail the WebSocket Connection_.
Connection_.
Except as indicated above or as specified by the application layer Except as indicated above or as specified by the application layer
(e.g. a script using the WebSocket API), clients SHOULD NOT close the (e.g., a script using the WebSocket API), clients SHOULD NOT close
connection. the connection.
7.2. Abnormal Closures 7.2. Abnormal Closures
7.2.1. Client-Initiated Closure 7.2.1. Client-Initiated Closure
Certain algorithms, namely during the opening handshake, require the Certain algorithms, in particular during the opening handshake,
client to _Fail the WebSocket Connection_. To do so, the client MUST require the client to _Fail the WebSocket Connection_. To do so, the
_Fail the WebSocket Connection_ as defined in Section 7.1.7. client MUST _Fail the WebSocket Connection_ as defined in
Section 7.1.7.
If at any point the underlying transport layer connection is If at any point the underlying transport layer connection is
unexpectedly lost, the client MUST _Fail the WebSocket Connection_. unexpectedly lost, the client MUST _Fail the WebSocket Connection_.
Except as indicated above or as specified by the application layer Except as indicated above or as specified by the application layer
(e.g. a script using the WebSocket API), clients SHOULD NOT close the (e.g., a script using the WebSocket API), clients SHOULD NOT close
connection. the connection.
7.2.2. Server-Initiated Closure 7.2.2. Server-Initiated Closure
Certain algorithms require or recommend that the server _Abort the Certain algorithms require or recommend that the server _Abort the
WebSocket Connection_ during the opening handshake. To do so, the WebSocket Connection_ during the opening handshake. To do so, the
server MUST simply _Close the WebSocket Connection_ (Section 7.1.1). server MUST simply _Close the WebSocket Connection_ (Section 7.1.1).
7.2.3. Recovering From Abnormal Closure 7.2.3. Recovering from Abnormal Closure
Abnormal closures may be caused by any number of reasons. Such Abnormal closures may be caused by any number of reasons. Such
closures could be the result of a transient error, in which case closures could be the result of a transient error, in which case
reconnecting may lead to a good connection and a resumption of normal reconnecting may lead to a good connection and a resumption of normal
operations. Such closures may also be the result of a nontransient operations. Such closures may also be the result of a nontransient
problem, in which case if each deployed client experiences an problem, in which case if each deployed client experiences an
abnormal closure and immediately and persistently tries to reconnect, abnormal closure and immediately and persistently tries to reconnect,
the server may experience what amounts to a denial of service attack the server may experience what amounts to a denial-of-service attack
by a large number of clients trying to reconnect. The end result of by a large number of clients trying to reconnect. The end result of
such a scenario could be that the service is unable to recover, or such a scenario could be that the service is unable to recover in a
recovery is made much more difficult, in any sort of timely manner. timely manner or recovery is made much more difficult.
To prevent this, clients SHOULD use some form of backoff when trying To prevent this, clients SHOULD use some form of backoff when trying
to reconnect after abnormal closures as described in this section. to reconnect after abnormal closures as described in this section.
The first reconnect attempt SHOULD be delayed by a random amount of The first reconnect attempt SHOULD be delayed by a random amount of
time. The parameters by which this random delay is chosen are left time. The parameters by which this random delay is chosen are left
to the client to decide; a value chosen randomly between 0 and 5 to the client to decide; a value chosen randomly between 0 and 5
seconds is a reasonable initial delay though clients MAY choose a seconds is a reasonable initial delay though clients MAY choose a
different interval from which to select a delay length based on different interval from which to select a delay length based on
implementation experience and particular application. implementation experience and particular application.
skipping to change at page 47, line 47 skipping to change at page 45, line 14
7.3. Normal Closure of Connections 7.3. Normal Closure of Connections
Servers MAY close the WebSocket connection whenever desired. Clients Servers MAY close the WebSocket connection whenever desired. Clients
SHOULD NOT close the WebSocket connection arbitrarily. In either SHOULD NOT close the WebSocket connection arbitrarily. In either
case, an endpoint initiates a closure by following the procedures to case, an endpoint initiates a closure by following the procedures to
_Start the WebSocket Closing Handshake_ (Section 7.1.2). _Start the WebSocket Closing Handshake_ (Section 7.1.2).
7.4. Status Codes 7.4. Status Codes
When closing an established connection (e.g. when sending a Close When closing an established connection (e.g., when sending a Close
frame, after the opening handshake has completed), an endpoint MAY frame, after the opening handshake has completed), an endpoint MAY
indicate a reason for closure. The interpretation of this reason by indicate a reason for closure. The interpretation of this reason by
an endpoint, and the action an endpoint should take given this an endpoint, and the action an endpoint should take given this
reason, are left undefined by this specification. This specification reason, are left undefined by this specification. This specification
defines a set of pre-defined status codes, and specifies which ranges defines a set of pre-defined status codes and specifies which ranges
may be used by extensions, frameworks, and end applications. The may be used by extensions, frameworks, and end applications. The
status code and any associated textual message are optional status code and any associated textual message are optional
components of a Close frame. components of a Close frame.
7.4.1. Defined Status Codes 7.4.1. Defined Status Codes
Endpoints MAY use the following pre-defined status codes when sending Endpoints MAY use the following pre-defined status codes when sending
a Close frame. a Close frame.
1000 1000
1000 indicates a normal closure, meaning whatever purpose the 1000 indicates a normal closure, meaning that the purpose for
connection was established for has been fulfilled. which the connection was established has been fulfilled.
1001 1001
1001 indicates that an endpoint is "going away", such as a server 1001 indicates that an endpoint is "going away", such as a server
going down, or a browser having navigated away from a page. going down or a browser having navigated away from a page.
1002 1002
1002 indicates that an endpoint is terminating the connection due 1002 indicates that an endpoint is terminating the connection due
to a protocol error. to a protocol error.
1003 1003
1003 indicates that an endpoint is terminating the connection 1003 indicates that an endpoint is terminating the connection
because it has received a type of data it cannot accept (e.g. an because it has received a type of data it cannot accept (e.g., an
endpoint that understands only text data MAY send this if it endpoint that understands only text data MAY send this if it
receives a binary message). receives a binary message).
1004 1004
Reserved. The specific meaning might be defined in the future. Reserved. The specific meaning might be defined in the future.
1005 1005
1005 is a reserved value and MUST NOT be set as a status code in a 1005 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that no status applications expecting a status code to indicate that no status
code was actually present. code was actually present.
1006 1006
1006 is a reserved value and MUST NOT be set as a status code in a 1006 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that the applications expecting a status code to indicate that the
connection was closed abnormally, e.g. without sending or connection was closed abnormally, e.g., without sending or
receiving a Close control frame. receiving a Close control frame.
1007 1007
1007 indicates that an endpoint is terminating the connection 1007 indicates that an endpoint is terminating the connection
because it has received data within a message that was not because it has received data within a message that was not
consistent with the type of the message (e.g., non-UTF-8 [RFC3629] consistent with the type of the message (e.g., non-UTF-8 [RFC3629]
data within a text message). data within a text message).
1008 1008
1008 indicates that an endpoint is terminating the connection 1008 indicates that an endpoint is terminating the connection
because it has received a message that violates its policy. This because it has received a message that violates its policy. This
is a generic status code that can be returned when there is no is a generic status code that can be returned when there is no
other more suitable status code (e.g. 1003 or 1009), or if there other more suitable status code (e.g., 1003 or 1009) or if there
is a need to hide specific details about the policy. is a need to hide specific details about the policy.
1009 1009
1009 indicates that an endpoint is terminating the connection 1009 indicates that an endpoint is terminating the connection
because it has received a message which is too big for it to because it has received a message that is too big for it to
process. process.
1010 1010
1010 indicates that an endpoint (client) is terminating the 1010 indicates that an endpoint (client) is terminating the
connection because it has expected the server to negotiate one or connection because it has expected the server to negotiate one or
more extension, but the server didn't return them in the response more extension, but the server didn't return them in the response
message of the WebSocket handshake. The list of extensions which message of the WebSocket handshake. The list of extensions that
are needed SHOULD appear in the /reason/ part of the Close frame. are needed SHOULD appear in the /reason/ part of the Close frame.
Note that this status code is not used by the server, because it Note that this status code is not used by the server, because it
can fail the WebSocket handshake instead. can fail the WebSocket handshake instead.
1011
1011 indicates that a server is terminating the connection because
it encountered an unexpected condition that prevented it from
fulfilling the request.
1015
1015 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that the
connection was closed due to a failure to perform a TLS handshake
(e.g., the server certificate can't be verified).
7.4.2. Reserved Status Code Ranges 7.4.2. Reserved Status Code Ranges
0-999 0-999
Status codes in the range 0-999 are not used. Status codes in the range 0-999 are not used.
1000-2999 1000-2999
Status codes in the range 1000-2999 are reserved for definition by Status codes in the range 1000-2999 are reserved for definition by
this protocol, its future revisions, and extensions specified in a this protocol, its future revisions, and extensions specified in a
permanent and readily available public specification. permanent and readily available public specification.
3000-3999 3000-3999
Status codes in the range 3000-3999 are reserved for use by Status codes in the range 3000-3999 are reserved for use by
libraries, frameworks and application. These status codes are libraries, frameworks, and applications. These status codes are
registered directly with IANA. The interpretation of these codes registered directly with IANA. The interpretation of these codes
is undefined by this protocol. is undefined by this protocol.
4000-4999 4000-4999
Status codes in the range 4000-4999 are reserved for private use Status codes in the range 4000-4999 are reserved for private use
and thus can't be registered. Such codes can be used by prior and thus can't be registered. Such codes can be used by prior
agreements between WebSocket applications. The interpretation of agreements between WebSocket applications. The interpretation of
these codes is undefined by this protocol. these codes is undefined by this protocol.
8. Error Handling 8. Error Handling
8.1. Handling Errors in UTF-8 Encoded Data 8.1. Handling Errors in UTF-8-Encoded Data
When an endpoint is to interpret a byte stream as UTF-8 but finds When an endpoint is to interpret a byte stream as UTF-8 but finds
that the byte stream is not in fact a valid UTF-8 stream, that that the byte stream is not, in fact, a valid UTF-8 stream, that
endpoint MUST _Fail the WebSocket Connection_. This rule applies endpoint MUST _Fail the WebSocket Connection_. This rule applies
both during the opening handshake and during subsequent data both during the opening handshake and during subsequent data
exchange. exchange.
9. Extensions 9. Extensions
WebSocket clients MAY request extensions to this specification, and WebSocket clients MAY request extensions to this specification, and
WebSocket servers MAY accept some or all extensions requested by the WebSocket servers MAY accept some or all extensions requested by the
client. A server MUST NOT respond with any extension not requested client. A server MUST NOT respond with any extension not requested
by the client. If extension parameters are included in negotiations by the client. If extension parameters are included in negotiations
between the client and the server, those parameters MUST be chosen in between the client and the server, those parameters MUST be chosen in
accordance with the specification of the extension to which the accordance with the specification of the extension to which the
parameters apply. parameters apply.
9.1. Negotiating Extensions 9.1. Negotiating Extensions
A client requests extensions by including a "Sec-WebSocket- A client requests extensions by including a |Sec-WebSocket-
Extensions" header field, which follows the normal rules for HTTP Extensions| header field, which follows the normal rules for HTTP
header fields (see [RFC2616] section 4.2) and the value of the header header fields (see [RFC2616], Section 4.2) and the value of the
field is defined by the following ABNF [RFC2616]. Note that this header field is defined by the following ABNF [RFC2616]. Note that
section is using ABNF syntax/rules from [RFC2616], including "implied this section is using ABNF syntax/rules from [RFC2616], including the
*LWS rule". If a value is received by either the client or the "implied *LWS rule". If a value is received by either the client or
server during negotiation that does not conform to the ABNF below, the server during negotiation that does not conform to the ABNF
the recipient of such malformed data MUST immediately _Fail the below, the recipient of such malformed data MUST immediately _Fail
WebSocket Connection_. the WebSocket Connection_.
Sec-WebSocket-Extensions = extension-list Sec-WebSocket-Extensions = extension-list
extension-list = 1#extension extension-list = 1#extension
extension = extension-token *( ";" extension-param ) extension = extension-token *( ";" extension-param )
extension-token = registered-token extension-token = registered-token
registered-token = token registered-token = token
extension-param = token [ "=" (token | quoted-string) ] extension-param = token [ "=" (token | quoted-string) ]
;When using the quoted-string syntax variant, the value ;When using the quoted-string syntax variant, the value
;after quoted-string unescaping MUST conform to the ;after quoted-string unescaping MUST conform to the
;'token' ABNF. ;'token' ABNF.
skipping to change at page 52, line 51 skipping to change at page 49, line 19
Sec-WebSocket-Extensions: foo Sec-WebSocket-Extensions: foo
Sec-WebSocket-Extensions: bar; baz=2 Sec-WebSocket-Extensions: bar; baz=2
is exactly equivalent to is exactly equivalent to
Sec-WebSocket-Extensions: foo, bar; baz=2 Sec-WebSocket-Extensions: foo, bar; baz=2
Any extension-token used MUST be a registered token (see Any extension-token used MUST be a registered token (see
Section 11.4). The parameters supplied with any given extension MUST Section 11.4). The parameters supplied with any given extension MUST
be defined for that extension. Note that the client is only offering be defined for that extension. Note that the client is only offering
to use any advertised extensions, and MUST NOT use them unless the to use any advertised extensions and MUST NOT use them unless the
server indicates that it wishes to use the extension. server indicates that it wishes to use the extension.
Note that the order of extensions is significant. Any interactions Note that the order of extensions is significant. Any interactions
between multiple extensions MAY be defined in the documents defining between multiple extensions MAY be defined in the documents defining
the extensions. In the absence of such definition, the the extensions. In the absence of such definitions, the
interpretation is that the header fields listed by the client in its interpretation is that the header fields listed by the client in its
request represent a preference of the header fields it wishes to use, request represent a preference of the header fields it wishes to use,
with the first options listed being most preferable. The extensions with the first options listed being most preferable. The extensions
listed by the server in response represent the extensions actually in listed by the server in response represent the extensions actually in
use for the connection. Should the extensions modify the data and/or use for the connection. Should the extensions modify the data and/or
framing, the order of operations on the data should be assumed to be framing, the order of operations on the data should be assumed to be
the same as the order in which the extensions are listed in the the same as the order in which the extensions are listed in the
server's response in the opening handshake. server's response in the opening handshake.
For example, if there are two extensions "foo" and "bar", if the For example, if there are two extensions "foo" and "bar" and if the
header field |Sec-WebSocket-Extensions| sent by the server has the header field |Sec-WebSocket-Extensions| sent by the server has the
value "foo, bar" then operations on the data will be made as value "foo, bar", then operations on the data will be made as
bar(foo(data)), be those changes to the data itself (such as bar(foo(data)), be those changes to the data itself (such as
compression) or changes to the framing that may "stack". compression) or changes to the framing that may "stack".
Non-normative examples of acceptable extension header fields (note Non-normative examples of acceptable extension header fields (note
that long lines are folded for readability): that long lines are folded for readability):
Sec-WebSocket-Extensions: deflate-stream Sec-WebSocket-Extensions: deflate-stream
Sec-WebSocket-Extensions: mux; max-channels=4; flow-control, Sec-WebSocket-Extensions: mux; max-channels=4; flow-control,
deflate-stream deflate-stream
Sec-WebSocket-Extensions: private-extension Sec-WebSocket-Extensions: private-extension
A server accepts one or more extensions by including a |Sec- A server accepts one or more extensions by including a
WebSocket-Extensions| header field containing one or more extensions |Sec-WebSocket-Extensions| header field containing one or more
which were requested by the client. The interpretation of any extensions that were requested by the client. The interpretation of
extension parameters, and what constitutes a valid response by a any extension parameters, and what constitutes a valid response by a
server to a requested set of parameters by a client, will be defined server to a requested set of parameters by a client, will be defined
by each such extension. by each such extension.
9.2. Known Extensions 9.2. Known Extensions
Extensions provide a mechanism for implementations to opt-in to Extensions provide a mechanism for implementations to opt-in to
additional protocol features. This document doesn't define any additional protocol features. This document doesn't define any
extension but implementations MAY use extensions defined separately. extension, but implementations MAY use extensions defined separately.
10. Security Considerations 10. Security Considerations
This section describes some security considerations applicable to the This section describes some security considerations applicable to the
WebSocket protocol. Specific security considerations are described WebSocket Protocol. Specific security considerations are described
in subsections of this section. in subsections of this section.
10.1. Non-Browser Clients 10.1. Non-Browser Clients
Many threats anticipated by the WebSocket protocol protect from The WebSocket Protocol protects against malicious JavaScript running
malicious JavaScript running inside a trusted application such as a inside a trusted application such as a web browser, for example, by
web browser, for example checking of the "Origin" header field (see checking of the |Origin| header field (see below). See Section 1.6
below). See Section 1.6 for additional details. Such assumptions for additional details. Such assumptions don't hold true in the case
don't hold true in the case of a more capable client. of a more-capable client.
While this protocol is intended to be used by scripts in Web pages, While this protocol is intended to be used by scripts in web pages,
it can also be used directly by hosts. Such hosts are acting on it can also be used directly by hosts. Such hosts are acting on
their own behalf, and can therefore send fake "Origin" header fields, their own behalf and can therefore send fake |Origin| header fields,
misleading the server. Servers should therefore be careful about misleading the server. Servers should therefore be careful about
assuming that they are talking directly to scripts from known assuming that they are talking directly to scripts from known origins
origins, and must consider that they might be accessed in unexpected and must consider that they might be accessed in unexpected ways. In
ways. In particular, a server should not trust that any input is particular, a server should not trust that any input is valid.
valid.
EXAMPLE: For example, if the server uses input as part of SQL EXAMPLE: If the server uses input as part of SQL queries, all input
queries, all input text should be escaped before being passed to the text should be escaped before being passed to the SQL server, lest
SQL server, lest the server be susceptible to SQL injection. the server be susceptible to SQL injection.
10.2. Origin Considerations 10.2. Origin Considerations
Servers that are not intended to process input from any Web page but Servers that are not intended to process input from any web page but
only for certain sites SHOULD verify the "Origin" field is an origin only for certain sites SHOULD verify the |Origin| field is an origin
they expect. If the origin indicated is unacceptable to the server, they expect. If the origin indicated is unacceptable to the server,
then it SHOULD respond to the WebSocket handshake with a reply then it SHOULD respond to the WebSocket handshake with a reply
containing HTTP 403 Forbidden status code. containing HTTP 403 Forbidden status code.
The "Origin" header field protects from the attack cases when the The |Origin| header field protects from the attack cases when the
untrusted party is typically the author of a JavaScript application untrusted party is typically the author of a JavaScript application
that is executing in the context of the trusted client. The client that is executing in the context of the trusted client. The client
itself can contact the server and via the mechanism of the "Origin" itself can contact the server and, via the mechanism of the |Origin|
header field, determine whether to extend those communication header field, determine whether to extend those communication
privileges to the JavaScript application. The intent is not to privileges to the JavaScript application. The intent is not to
prevent non-browsers from establishing connections, but rather to prevent non-browsers from establishing connections but rather to
ensure that trusted browsers under the control of potentially ensure that trusted browsers under the control of potentially
malicious JavaScript cannot fake a WebSocket handshake. malicious JavaScript cannot fake a WebSocket handshake.
10.3. Attacks On Infrastructure (Masking) 10.3. Attacks On Infrastructure (Masking)
In addition to endpoints being the target of attacks via WebSockets, In addition to endpoints being the target of attacks via WebSockets,
other parts of web infrastructure, such as proxies, may be the other parts of web infrastructure, such as proxies, may be the
subject of an attack. subject of an attack.
As this protocol was being developed, an experiment was conducted to As this protocol was being developed, an experiment was conducted to
demonstrate a class of attacks on proxies that led to the poisoning demonstrate a class of attacks on proxies that led to the poisoning
of caching proxies deployed in the wild [TALKING]. The general form of caching proxies deployed in the wild [TALKING]. The general form
of the attack was to establish a connection to a server under the of the attack was to establish a connection to a server under the
"attacker's" control, perform an UPGRADE on the HTTP connection "attacker's" control, perform an UPGRADE on the HTTP connection
similar to what the WebSocket protocol does to establish a similar to what the WebSocket Protocol does to establish a
connection, and to subsequently send data over that UPGRADEd connection, and subsequently send data over that UPGRADEd connection
connection that looked like a GET request for a specific known that looked like a GET request for a specific known resource (which
resource (which in an attack would likely be something like a widely in an attack would likely be something like a widely deployed script
deployed script for tracking hits, or a resource on an ad-serving for tracking hits or a resource on an ad-serving network). The
network). The remote server would respond with something that looked remote server would respond with something that looked like a
like a response to the fake GET request, and this response would be response to the fake GET request, and this response would be cached
cached by a nonzero percentage of deployed intermediaries, thus by a nonzero percentage of deployed intermediaries, thus poisoning
poisioning the cache. The net effect of this attack would be that if the cache. The net effect of this attack would be that if a user
a user could be convinced to visit a website the attacker controlled, could be convinced to visit a website the attacker controlled, the
the attacker could potentially poison the cache for that user and attacker could potentially poison the cache for that user and other
other users behind the same cache and run malicious script on other users behind the same cache and run malicious script on other
origins, compromising the web security model. origins, compromising the web security model.
To avoid such attacks on deployed intermediaries, it is not To avoid such attacks on deployed intermediaries, it is not
sufficient to prefix application supplied data with framing that is sufficient to prefix application-supplied data with framing that is
not compliant HTTP, as it is not possible to exhaustively discover not compliant with HTTP, as it is not possible to exhaustively
and test that each nonconformant intermediary does not skip such non discover and test that each nonconformant intermediary does not skip
HTTP framing and act incorrectly on the frame payload. Thus the such non-HTTP framing and act incorrectly on the frame payload.
defence adopted is to mask all data from the client to the server, so Thus, the defense adopted is to mask all data from the client to the
that the remote script (attacker) does not have control over how the server, so that the remote script (attacker) does not have control
data being sent appears on the wire, and thus cannot construct a over how the data being sent appears on the wire and thus cannot
message that could be misinterpreted by an intermediary as an HTTP construct a message that could be misinterpreted by an intermediary
request. as an HTTP request.
Clients MUST choose a new masking key for each frame, using an Clients MUST choose a new masking key for each frame, using an
algorithm that cannot be predicted by end applications that provide algorithm that cannot be predicted by end applications that provide
data. For example, each masking could be drawn from a data. For example, each masking could be drawn from a
cryptographically strong random number generator. If the same key is cryptographically strong random number generator. If the same key is
used, or a decipherable pattern exists for how the next key is used or a decipherable pattern exists for how the next key is chosen,
chosen, the attacker can send a message that, when masked, could the attacker can send a message that, when masked, could appear to be
appear to be an HTTP request (by taking the message the attacker an HTTP request (by taking the message the attacker wishes to see on
wishes to see on the wire, and masking it with the next masking key the wire and masking it with the next masking key to be used, the
to be used, when the client applies the masking key it will masking key will effectively unmask the data when the client applies
effectively unmask the data.) it).
It is also necessary that once the transmission of a frame from a It is also necessary that once the transmission of a frame from a
client has begun, the payload (application supplied data) of that client has begun, the payload (application-supplied data) of that
frame must not be capable of being modified by the application. frame must not be capable of being modified by the application.
Otherwise, an attacker could send a long frame where the initial data Otherwise, an attacker could send a long frame where the initial data
was a known value (such as all zeros), compute the masking key being was a known value (such as all zeros), compute the masking key being
used upon receipt of the first part of the data, and then modify the used upon receipt of the first part of the data, and then modify the
data that is yet to be sent in the frame to appear as an HTTP request data that is yet to be sent in the frame to appear as an HTTP request
when masked. (This is essentially the same problem described in the when masked. (This is essentially the same problem described in the
previous paragraph with using a known or predictable masking key.) previous paragraph with using a known or predictable masking key.)
If additional data is to be sent or data to be sent is somehow If additional data is to be sent or data to be sent is somehow
changed, that new or changed data must be sent in a new frame and changed, that new or changed data must be sent in a new frame and
thus with a new masking key. In short, once transmission of a frame thus with a new masking key. In short, once transmission of a frame
begins, the contents must not be modifiable by the remote script begins, the contents must not be modifiable by the remote script
(application). (application).
The threat model being protected against is one in which the client The threat model being protected against is one in which the client
sends data that appears to be a HTTP request. As such, the channel sends data that appears to be an HTTP request. As such, the channel
that needs to be masked is the data from the client to the server. that needs to be masked is the data from the client to the server.
The data from the server to the client can be made to look like a The data from the server to the client can be made to look like a
response, but to accomplish this request the client must also be able response, but to accomplish this request, the client must also be
to forge a request. As such, it was not deemed necessary to mask able to forge a request. As such, it was not deemed necessary to
data in both directions (the data from the server to the client is mask data in both directions (the data from the server to the client
not masked). is not masked).
Despite the protection provided by masking, non-compliant HTTP Despite the protection provided by masking, non-compliant HTTP
proxies will still be vulnerable to poisoning attacks of this type by proxies will still be vulnerable to poisoning attacks of this type by
clients and servers that do not apply masking. clients and servers that do not apply masking.
10.4. Implementation-Specific Limits 10.4. Implementation-Specific Limits
Implementations which have implementation- and/or platform-specific Implementations that have implementation- and/or platform-specific
limitations regarding the frame size or total message size after limitations regarding the frame size or total message size after
reassembly from multiple frames MUST protect themselves against reassembly from multiple frames MUST protect themselves against
exceeding those limits. (For example, a malicious endpoint can try exceeding those limits. (For example, a malicious endpoint can try
to exhaust its peer's memory or mount a denial of service attack by to exhaust its peer's memory or mount a denial-of-service attack by
sending either a single big frame (e.g. of size 2**60), or by sending sending either a single big frame (e.g., of size 2**60) or by sending
a long stream of small frames which are a part of a fragmented a long stream of small frames that are a part of a fragmented
message.) Such an implementation SHOULD impose limit on frame sizes message.) Such an implementation SHOULD impose a limit on frame
and the total message size after reassembly from multiple frames. sizes and the total message size after reassembly from multiple
frames.
10.5. WebSocket client authentication 10.5. WebSocket Client Authentication
This protocol doesn't prescribe any particular way that servers can This protocol doesn't prescribe any particular way that servers can
authenticate clients during the WebSocket handshake. The WebSocket authenticate clients during the WebSocket handshake. The WebSocket
server can use any client authentication mechanism available to a server can use any client authentication mechanism available to a
generic HTTP server, such as Cookies, HTTP Authentication, or TLS generic HTTP server, such as cookies, HTTP authentication, or TLS
authentication. authentication.
10.6. Connection confidentiality and integrity 10.6. Connection Confidentiality and Integrity
Communications confidentiality and integrity is provided by running Connection confidentiality and integrity is provided by running the
the WebSocket protocol over TLS (wss URIs). WebSocket WebSocket Protocol over TLS (wss URIs). WebSocket implementations
implementations MUST support TLS, and SHOULD employ it when MUST support TLS and SHOULD employ it when communicating with their
communicating with their peers. peers.
For connections using TLS, the amount of benefit provided by TLS For connections using TLS, the amount of benefit provided by TLS
depends greatly on the strength of the algorithms negotiated during depends greatly on the strength of the algorithms negotiated during
the TLS handshake. For example some TLS cipher mechanisms don't the TLS handshake. For example, some TLS cipher mechanisms don't
provide connection confidentiality. To achieve reasonable levels of provide connection confidentiality. To achieve reasonable levels of
protections, clients should use only Strong TLS algorithms. "Web protection, clients should use only Strong TLS algorithms. "Web
Security Context: User Interface Guidelines" Security Context: User Interface Guidelines"
[W3C.REC-wsc-ui-20100812] discusses what constitutes Strong TLS [W3C.REC-wsc-ui-20100812] discusses what constitutes Strong TLS
algorithms. [RFC5246] provides additional guidance in Appendix A.5 algorithms. [RFC5246] provides additional guidance in Appendix A.5
and Appendix D.3. and Appendix D.3.
10.7. Handling of invalid data 10.7. Handling of Invalid Data
Incoming data MUST always be validated by both clients and servers. Incoming data MUST always be validated by both clients and servers.
If at any time an endpoint is faced with data that it does not If, at any time, an endpoint is faced with data that it does not
understand, or that violates some criteria by which the endpoint understand or that violates some criteria by which the endpoint
determines safety of input, or when the endpoint sees an opening determines safety of input, or when the endpoint sees an opening
handshake that does not correspond to the values it is expecting handshake that does not correspond to the values it is expecting
(e.g. incorrect path or origin in the client request), the endpoint (e.g., incorrect path or origin in the client request), the endpoint
MAY drop the TCP connection. If the invalid data received after a MAY drop the TCP connection. If the invalid data was received after
successful WebSocket handshake, the endpoint SHOULD send a Close a successful WebSocket handshake, the endpoint SHOULD send a Close
frame with an appropriate status code Section 7.4 before proceeding frame with an appropriate status code (Section 7.4) before proceeding
to _Close the WebSocket Connection_. Use of a Close frame with an to _Close the WebSocket Connection_. Use of a Close frame with an
appropriate status code can help in diagnosing the problem. If the appropriate status code can help in diagnosing the problem. If the
invalid data is sent during the WebSocket handshake the server SHOULD invalid data is sent during the WebSocket handshake, the server
return an appropriate HTTP [RFC2616] status code. SHOULD return an appropriate HTTP [RFC2616] status code.
A common class of security problems arise when sending text data A common class of security problems arises when sending text data
using using the wrong encoding. This protocol specifies that using the wrong encoding. This protocol specifies that messages with
messages with a Text data type (as opposed to Binary or other types) a Text data type (as opposed to Binary or other types) contain UTF-8-
contain UTF-8 encoded data. Although the length is still indicated encoded data. Although the length is still indicated and
and applications implementing this protocol should use the length to applications implementing this protocol should use the length to
determine where the frame actually ends, sending data in an improper determine where the frame actually ends, sending data in an improper
encoding may still break assumptions applications built on top of encoding may still break assumptions that applications built on top
this protocol may make, leading from anything to misinterpretation of of this protocol may make, leading to anything from misinterpretation
data to loss of data to potential security bugs. of data to loss of data or potential security bugs.
10.8. Use of SHA-1 by the WebSocket handshake 10.8. Use of SHA-1 by the WebSocket Handshake
The WebSocket handshake described in this document doesn't depend on The WebSocket handshake described in this document doesn't depend on
any security properties of SHA-1, such as collision resistance or any security properties of SHA-1, such as collision resistance or
resistance to the second pre-image attack (as described in resistance to the second pre-image attack (as described in
[RFC4270]). [RFC4270]).
11. IANA Considerations 11. IANA Considerations
11.1. Registration of new URI Schemes 11.1. Registration of New URI Schemes
11.1.1. Registration of "ws" Scheme 11.1.1. Registration of "ws" Scheme
A |ws| URI identifies a WebSocket server and resource name. A |ws| URI identifies a WebSocket server and resource name.
URI scheme name. URI scheme name
ws ws
Status. Status
Permanent. Permanent
URI scheme syntax. URI scheme syntax
In ABNF [RFC5234] terms using the terminals from the URI Using the ABNF [RFC5234] syntax and ABNF terminals from the URI
specifications: [RFC5234] [RFC3986] specification [RFC3986]:
"ws:" "//" authority path-abempty [ "?" query ] "ws:" "//" authority path-abempty [ "?" query ]
The <path-abempty> and <query> [RFC3986] components form the The <path-abempty> and <query> [RFC3986] components form the resource
resource name sent to the server to identify the kind of service name sent to the server to identify the kind of service desired.
desired. Other components have the meanings described in RFC3986. Other components have the meanings described in [RFC3986].
URI scheme semantics. URI scheme semantics
The only operation for this scheme is to open a connection using The only operation for this scheme is to open a connection using
the WebSocket protocol. the WebSocket Protocol.
Encoding considerations. Encoding considerations
Characters in the host component that are excluded by the syntax Characters in the host component that are excluded by the syntax
defined above MUST be converted from Unicode to ASCII as specified defined above MUST be converted from Unicode to ASCII as specified
in [RFC3987] or its replacement. For the purposes of scheme-based in [RFC3987] or its replacement. For the purposes of scheme-based
normalization IDN forms of the host component and their normalization, Internationalized Domain Name (IDN) forms of the
conversions to punycode are considered equivalent (see Section host component and their conversions to punycode are considered
5.3.3 of [RFC3987]). equivalent (see Section 5.3.3 of [RFC3987]).
Characters in other components that are excluded by the syntax Characters in other components that are excluded by the syntax
defined above MUST be converted from Unicode to ASCII by first defined above MUST be converted from Unicode to ASCII by first
encoding the characters as UTF-8 and then replacing the encoding the characters as UTF-8 and then replacing the
corresponding bytes using their percent-encoded form as defined in corresponding bytes using their percent-encoded form as defined in
the URI and IRI specifications. [RFC3986] [RFC3987] the URI [RFC3986] and Internationalized Resource Identifier (IRI)
[RFC3987] specifications.
Applications/protocols that use this URI scheme name. Applications/protocols that use this URI scheme name
WebSocket protocol. WebSocket Protocol
Interoperability considerations. Interoperability considerations
Use of WebSocket requires use of HTTP version 1.1 or higher. Use of WebSocket requires use of HTTP version 1.1 or higher.
Security considerations. Security considerations
See "Security considerations" section above. See "Security Considerations" section.
Contact. Contact
HYBI WG <hybi@ietf.org> HYBI WG <hybi@ietf.org>
Author/Change controller. Author/Change controller
IETF <iesg@ietf.org> IETF <iesg@ietf.org>
References. References
RFC XXXX RFC 6455
11.1.2. Registration of "wss" Scheme 11.1.2. Registration of "wss" Scheme
A |wss| URI identifies a WebSocket server and resource name, and A |wss| URI identifies a WebSocket server and resource name and
indicates that traffic over that connection is to be protected via indicates that traffic over that connection is to be protected via
TLS (including standard benefits of TLS such as data confidentiality TLS (including standard benefits of TLS such as data confidentiality
and integrity, and endpoint authentication). and integrity and endpoint authentication).
URI scheme name. URI scheme name
wss wss
Status. Status
Permanent. Permanent
URI scheme syntax. URI scheme syntax
In ABNF [RFC5234] terms using the terminals from the URI Using the ABNF [RFC5234] syntax and ABNF terminals from the URI
specifications: [RFC5234] [RFC3986] specification [RFC3986]:
"wss:" "//" authority path-abempty [ "?" query ] "wss:" "//" authority path-abempty [ "?" query ]
The <path-abempty> and <query> components form the resource name The <path-abempty> and <query> components form the resource name sent
sent to the server to identify the kind of service desired. Other to the server to identify the kind of service desired. Other
components have the meanings described in RFC3986. components have the meanings described in [RFC3986].
URI scheme semantics. URI scheme semantics
The only operation for this scheme is to open a connection using The only operation for this scheme is to open a connection using
the WebSocket protocol, encrypted using TLS. the WebSocket Protocol, encrypted using TLS.
Encoding considerations. Encoding considerations
Characters in the host component that are excluded by the syntax Characters in the host component that are excluded by the syntax
defined above MUST be converted from Unicode to ASCII as specified defined above MUST be converted from Unicode to ASCII as specified
in [RFC3987] or its replacement. For the purposes of scheme-based in [RFC3987] or its replacement. For the purposes of scheme-based
normalization IDN forms of the host component and their normalization IDN forms of the host component and their
conversions to punycode are considered equivalent (see Section conversions to punycode are considered equivalent (see Section
5.3.3 of [RFC3987]). 5.3.3 of [RFC3987]).
Characters in other components that are excluded by the syntax Characters in other components that are excluded by the syntax
defined above MUST be converted from Unicode to ASCII by first defined above MUST be converted from Unicode to ASCII by first
encoding the characters as UTF-8 and then replacing the encoding the characters as UTF-8 and then replacing the
corresponding bytes using their percent-encoded form as defined in corresponding bytes using their percent-encoded form as defined in
the URI and IRI specification. [RFC3986] [RFC3987] the URI [RFC3986] and IRI [RFC3987] specifications.
Applications/protocols that use this URI scheme name. Applications/protocols that use this URI scheme name
WebSocket protocol over TLS. WebSocket Protocol over TLS
Interoperability considerations. Interoperability considerations
Use of WebSocket requires use of HTTP version 1.1 or higher. Use of WebSocket requires use of HTTP version 1.1 or higher.
Security considerations. Security considerations
See "Security considerations" section above. See "Security Considerations" section.
Contact. Contact
HYBI WG <hybi@ietf.org> HYBI WG <hybi@ietf.org>
Author/Change controller. Author/Change controller
IETF <iesg@ietf.org> IETF <iesg@ietf.org>
References. References
RFC XXXX RFC 6455
11.2. Registration of the "WebSocket" HTTP Upgrade Keyword 11.2. Registration of the "WebSocket" HTTP Upgrade Keyword
This section defines a keyword for registration in the "HTTP Upgrade This section defines a keyword registered in the HTTP Upgrade Tokens
Tokens" registry as per RFC 2817 [RFC2817]. Registry as per RFC 2817 [RFC2817].
Name of token. Name of token
WebSocket WebSocket
Author/Change controller. Author/Change controller
IETF <iesg@ietf.org> IETF <iesg@ietf.org>
Contact. Contact
HYBI <hybi@ietf.org> HYBI <hybi@ietf.org>
References. References
RFC XXXX RFC 6455
11.3. Registration of New HTTP Header Fields
11.3. Registration of new HTTP Header Fields
11.3.1. Sec-WebSocket-Key 11.3.1. Sec-WebSocket-Key
This section describes a header field for registration in the This section describes a header field registered in the Permanent
Permanent Message Header Field Registry. [RFC3864] Message Header Field Names registry [RFC3864].
Header field name Header field name
Sec-WebSocket-Key Sec-WebSocket-Key
Applicable protocol Applicable protocol
http http
Status Status
standard standard
Author/Change controller Author/Change controller
IETF IETF
Specification document(s) Specification document(s)
RFC XXXX RFC 6455
Related information Related information
This header field is only used for WebSocket opening handshake. This header field is only used for WebSocket opening handshake.
The |Sec-WebSocket-Key| header field is used in the WebSocket opening The |Sec-WebSocket-Key| header field is used in the WebSocket opening
handshake. It is sent from the client to the server to provide part handshake. It is sent from the client to the server to provide part
of the information used by the server to prove that it received a of the information used by the server to prove that it received a
valid WebSocket opening handshake. This helps ensure that the server valid WebSocket opening handshake. This helps ensure that the server
does not accept connections from non-WebSocket clients (e.g. HTTP does not accept connections from non-WebSocket clients (e.g., HTTP
clients) that are being abused to send data to unsuspecting WebSocket clients) that are being abused to send data to unsuspecting WebSocket
servers. servers.
The |Sec-WebSocket-Key| header field MUST NOT appear more than once The |Sec-WebSocket-Key| header field MUST NOT appear more than once
in an HTTP request. in an HTTP request.
11.3.2. Sec-WebSocket-Extensions 11.3.2. Sec-WebSocket-Extensions
This section describes a header field for registration in the This section describes a header field for registration in the
Permanent Message Header Field Registry. [RFC3864] Permanent Message Header Field Names registry [RFC3864].
Header field name Header field name
Sec-WebSocket-Extensions Sec-WebSocket-Extensions
Applicable protocol Applicable protocol
http http
Status Status
standard standard
Author/Change controller Author/Change controller
IETF IETF
Specification document(s) Specification document(s)
RFC XXXX RFC 6455
Related information Related information
This header field is only used for WebSocket opening handshake. This header field is only used for WebSocket opening handshake.
The |Sec-WebSocket-Extensions| header field is used in the WebSocket The |Sec-WebSocket-Extensions| header field is used in the WebSocket
opening handshake. It is initially sent from the client to the opening handshake. It is initially sent from the client to the
server, and then subsequently sent from the server to the client, to server, and then subsequently sent from the server to the client, to
agree on a set of protocol-level extensions to use for the duration agree on a set of protocol-level extensions to use for the duration
of the connection. of the connection.
The |Sec-WebSocket-Extensions| header field MAY appear multiple times The |Sec-WebSocket-Extensions| header field MAY appear multiple times
in an HTTP request (which is logically the same as a single |Sec- in an HTTP request (which is logically the same as a single
WebSocket-Extensions| header field that contains all values. However |Sec-WebSocket-Extensions| header field that contains all values.
the |Sec-WebSocket-Extensions| header field MUST NOT appear more than However, the |Sec-WebSocket-Extensions| header field MUST NOT appear
once in an HTTP response. more than once in an HTTP response.
11.3.3. Sec-WebSocket-Accept 11.3.3. Sec-WebSocket-Accept
This section describes a header field for registration in the This section describes a header field registered in the Permanent
Permanent Message Header Field Registry. [RFC3864] Message Header Field Names registry [RFC3864].
Header field name Header field name
Sec-WebSocket-Accept Sec-WebSocket-Accept
Applicable protocol Applicable protocol
http http
Status Status
standard standard
Author/Change controller Author/Change controller
IETF IETF
Specification document(s) Specification document(s)
RFC XXXX RFC 6455
Related information Related information
This header field is only used for WebSocket opening handshake. This header field is only used for the WebSocket opening
handshake.
The |Sec-WebSocket-Accept| header field is used in the WebSocket The |Sec-WebSocket-Accept| header field is used in the WebSocket
opening handshake. It is sent from the server to the client to opening handshake. It is sent from the server to the client to
confirm that the server is willing to initiate the WebSocket confirm that the server is willing to initiate the WebSocket
connection. connection.
The |Sec-WebSocket-Accept| header MUST NOT appear more than once in The |Sec-WebSocket-Accept| header MUST NOT appear more than once in
an HTTP response. an HTTP response.
11.3.4. Sec-WebSocket-Protocol 11.3.4. Sec-WebSocket-Protocol
This section describes a header field for registration in the This section describes a header field registered in the Permanent
Permanent Message Header Field Registry. [RFC3864] Message Header Field Names registry [RFC3864].
Header field name Header field name
Sec-WebSocket-Protocol Sec-WebSocket-Protocol
Applicable protocol Applicable protocol
http http
Status Status
standard standard
Author/Change controller Author/Change controller
IETF IETF
Specification document(s) Specification document(s)
RFC XXXX RFC 6455
Related information Related information
This header field is only used for WebSocket opening handshake. This header field is only used for the WebSocket opening
handshake.
The |Sec-WebSocket-Protocol| header field is used in the WebSocket The |Sec-WebSocket-Protocol| header field is used in the WebSocket
opening handshake. It is sent from the client to the server and back opening handshake. It is sent from the client to the server and back
from the server to the client to confirm the subprotocol of the from the server to the client to confirm the subprotocol of the
connection. This enables scripts to both select a subprotocol and be connection. This enables scripts to both select a subprotocol and be
sure that the server agreed to serve that subprotocol. sure that the server agreed to serve that subprotocol.
The |Sec-WebSocket-Protocol| header field MAY appear multiple times The |Sec-WebSocket-Protocol| header field MAY appear multiple times
in an HTTP request (which is logically the same as a single |Sec- in an HTTP request (which is logically the same as a single
WebSocket-Protocol| header field that contains all values. However |Sec-WebSocket-Protocol| header field that contains all values).
the |Sec-WebSocket-Protocol| header field MUST NOT appear more than However, the |Sec-WebSocket-Protocol| header field MUST NOT appear
once in an HTTP response. more than once in an HTTP response.
11.3.5. Sec-WebSocket-Version 11.3.5. Sec-WebSocket-Version
This section describes a header field for registration in the This section describes a header field registered in the Permanent
Permanent Message Header Field Registry [RFC3864]. Message Header Field Names registry [RFC3864].
Header field name Header field name
Sec-WebSocket-Version Sec-WebSocket-Version
Applicable protocol Applicable protocol
http http
Status Status
standard standard
Author/Change controller Author/Change controller
IETF IETF
Specification document(s) Specification document(s)
RFC XXXX RFC 6455
Related information Related information
This header field is only used for WebSocket opening handshake. This header field is only used for the WebSocket opening
handshake.
The |Sec-WebSocket-Version| header field is used in the WebSocket The |Sec-WebSocket-Version| header field is used in the WebSocket
opening handshake. It is sent from the client to the server to opening handshake. It is sent from the client to the server to
indicate the protocol version of the connection. This enables indicate the protocol version of the connection. This enables
servers to correctly interpret the opening handshake and subsequent servers to correctly interpret the opening handshake and subsequent
data being sent from the data, and close the connection if the server data being sent from the data, and close the connection if the server
cannot interpret that data in a safe manner. The |Sec-WebSocket- cannot interpret that data in a safe manner. The |Sec-WebSocket-
Version| header field is also sent from the server to the client on Version| header field is also sent from the server to the client on
WebSocket handshake error, when the version received from the client WebSocket handshake error, when the version received from the client
does not match a version understood by the server. In such a case does not match a version understood by the server. In such a case,
the header field includes the protocol version(s) supported by the the header field includes the protocol version(s) supported by the
server. server.
Note that there is no expectation that higher version numbers are Note that there is no expectation that higher version numbers are
necessarily backward compatible with lower version numbers. necessarily backward compatible with lower version numbers.
The |Sec-WebSocket-Version| header field MAY appear multiple times in The |Sec-WebSocket-Version| header field MAY appear multiple times in
an HTTP response (which is logically the same as a single |Sec- an HTTP response (which is logically the same as a single
WebSocket-Version| header field that contains all values. However |Sec-WebSocket-Version| header field that contains all values).
the |Sec-WebSocket-Version| header field MUST NOT appear more than However, the |Sec-WebSocket-Version| header field MUST NOT appear
once in an HTTP request. more than once in an HTTP request.
11.4. WebSocket Extension Name Registry 11.4. WebSocket Extension Name Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket
WebSocket Extension names to be used with the WebSocket protocol in Extension names to be used with the WebSocket Protocol in accordance
accordance with the principles set out in RFC 5226 [RFC5226]. with the principles set out in RFC 5226 [RFC5226].
As part of this registry IANA will maintain the following As part of this registry, IANA maintains the following information:
information:
Extension Identifier Extension Identifier
The identifier of the extension, as will be used in the Sec- The identifier of the extension, as will be used in the
WebSocket-Extension header field registered in Section 11.3.2 of |Sec-WebSocket-Extensions| header field registered in
this specification. The value must conform to the requirements Section 11.3.2 of this specification. The value must conform to
for an extension-token as defined in Section 9.1 of this the requirements for an extension-token as defined in Section 9.1
specification. of this specification.
Extension Common Name Extension Common Name
The name of the extension, as the extension is generally referred The name of the extension, as the extension is generally referred
to. to.
Extension Definition Extension Definition
A reference to the document in which the extension being used with A reference to the document in which the extension being used with
the WebSocket protocol is defined. the WebSocket Protocol is defined.
Known Incompatible Extensions Known Incompatible Extensions
A list of extension identifiers with which this extension is known A list of extension identifiers with which this extension is known
to be incompatible. to be incompatible.
WebSocket Extension names are to be subject to "First Come First WebSocket Extension names are to be subject to the "First Come First
Served" IANA registration policy [RFC5226]. Served" IANA registration policy [RFC5226].
There are no initial values in this registry. There are no initial values in this registry.
11.5. WebSocket Subprotocol Name Registry 11.5. WebSocket Subprotocol Name Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket
WebSocket Subprotocol names to be used with the WebSocket protocol in Subprotocol names to be used with the WebSocket Protocol in
accordance with the principles set out in RFC 5226 [RFC5226]. accordance with the principles set out in RFC 5226 [RFC5226].
As part of this registry IANA will maintain the following As part of this registry, IANA maintains the following information:
information:
Subprotocol Identifier Subprotocol Identifier
The identifier of the subprotocol, as will be used in the Sec- The identifier of the subprotocol, as will be used in the
WebSocket-Protocol header field registered in Section 11.3.4 of |Sec-WebSocket-Protocol| header field registered in Section 11.3.4
this specification. The value must conform to the requirements of this specification. The value must conform to the requirements
given in Paragraph 10 of Section 4.1 of this specification, namely given in item 10 of Section 4.1 of this specification -- namely,
the value must be a token as defined by RFC 2616 [RFC2616]. the value must be a token as defined by RFC 2616 [RFC2616].
Subprotocol Common Name Subprotocol Common Name
The name of the subprotocol, as the subprotocol is generally The name of the subprotocol, as the subprotocol is generally
referred to. referred to.
Subprotocol Definition Subprotocol Definition
A reference to the document in which the subprotocol being used A reference to the document in which the subprotocol being used
with the WebSocket protocol is defined. with the WebSocket Protocol is defined.
WebSocket Subprotocol names are to be subject to "First Come First WebSocket Subprotocol names are to be subject to the "First Come
Served" IANA registration policy [RFC5226]. First Served" IANA registration policy [RFC5226].
11.6. WebSocket Version Number Registry 11.6. WebSocket Version Number Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket Version
WebSocket Version Numbers to be used with the WebSocket protocol in Numbers to be used with the WebSocket Protocol in accordance with the
accordance with the principles set out in RFC 5226 [RFC5226]. principles set out in RFC 5226 [RFC5226].
As part of this registry IANA will maintain the following As part of this registry, IANA maintains the following information:
information:
Version Number Version Number
The version number to be used in the Sec-WebSocket-Version as The version number to be used in the |Sec-WebSocket-Version| is
specified in Section 4.1 of this specification. The value must be specified in Section 4.1 of this specification. The value must be
a non negative integer in the range between 0 and 255 (inclusive). a non-negative integer in the range between 0 and 255 (inclusive).
Reference Reference
The RFC requesting a new version number. The RFC requesting a new version number or a draft name with
version number (see below).
WebSocket Version Numbers are to be subject to "IETF Review" IANA Status
registration policy [RFC5226]. In order to improve interoperability Either "Interim" or "Standard". See below for description.
with intermediate versions published in Internet Drafts, version
numbers associated with such drafts might be registered in this
registry. Note that "IETF Review" applies to registrations
corresponding to Internet Drafts.
IANA is asked to add initial values to the registry, with suggested A version number is designated as either "Interim" or "Standard".
numerical values as these have been used in past versions of this
protocol.
Version Number | Reference A "Standard" version number is documented in an RFC and used to
-+----------------+-----------------------------------------+- identify a major, stable version of the WebSocket protocol, such as
| 0 + draft-ietf-hybi-thewebsocketprotocol-00 | the version defined by this RFC. "Standard" version numbers are
-+----------------+-----------------------------------------+- subject to the "IETF Review" IANA registration policy [RFC5226].
| 1 + draft-ietf-hybi-thewebsocketprotocol-01 |
-+----------------+-----------------------------------------+- An "Interim" version number is documented in an Internet-Draft and
| 2 + draft-ietf-hybi-thewebsocketprotocol-02 | used to help implementors identify and interoperate with deployed
-+----------------+-----------------------------------------+- versions of the WebSocket protocol, such as versions developed before
| 3 + draft-ietf-hybi-thewebsocketprotocol-03 | the publication of this RFC. "Interim" version numbers are subject
-+----------------+-----------------------------------------+- to the "Expert Review" IANA registration policy [RFC5226], with the
| 4 + draft-ietf-hybi-thewebsocketprotocol-04 | chairs of the HYBI Working Group (or, if the working group closes,
-+----------------+-----------------------------------------+- the Area Directors for the IETF Applications Area) being the initial
| 5 + draft-ietf-hybi-thewebsocketprotocol-05 | Designated Experts.
-+----------------+-----------------------------------------+-
| 6 + draft-ietf-hybi-thewebsocketprotocol-06 | IANA has added initial values to the registry as follows.
-+----------------+-----------------------------------------+-
| 7 + draft-ietf-hybi-thewebsocketprotocol-07 | +--------+-----------------------------------------+----------+
-+----------------+-----------------------------------------+- |Version | Reference | Status |
| 8 + draft-ietf-hybi-thewebsocketprotocol-08 | | Number | | |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 9 + Reserved | | 0 + draft-ietf-hybi-thewebsocketprotocol-00 | Interim |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 10 + Reserved | | 1 + draft-ietf-hybi-thewebsocketprotocol-01 | Interim |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 11 + Reserved | | 2 + draft-ietf-hybi-thewebsocketprotocol-02 | Interim |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 12 + Reserved | | 3 + draft-ietf-hybi-thewebsocketprotocol-03 | Interim |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 13 + RFCXXXX (RFC Editor: please update) | | 4 + draft-ietf-hybi-thewebsocketprotocol-04 | Interim |
-+----------------+-----------------------------------------+- +--------+-----------------------------------------+----------+
| 5 + draft-ietf-hybi-thewebsocketprotocol-05 | Interim |
+--------+-----------------------------------------+----------+
| 6 + draft-ietf-hybi-thewebsocketprotocol-06 | Interim |
+--------+-----------------------------------------+----------+
| 7 + draft-ietf-hybi-thewebsocketprotocol-07 | Interim |
+--------+-----------------------------------------+----------+
| 8 + draft-ietf-hybi-thewebsocketprotocol-08 | Interim |
+--------+-----------------------------------------+----------+
| 9 + Reserved | |
+--------+-----------------------------------------+----------+
| 10 + Reserved | |
+--------+-----------------------------------------+----------+
| 11 + Reserved | |
+--------+-----------------------------------------+----------+
| 12 + Reserved | |
+--------+-----------------------------------------+----------+
| 13 + RFC 6455 | Standard |
+--------+-----------------------------------------+----------+
11.7. WebSocket Close Code Number Registry 11.7. WebSocket Close Code Number Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket
WebSocket Connection Close Code Numbers in accordance with the Connection Close Code Numbers in accordance with the principles set
principles set out in RFC 5226 [RFC5226]. out in RFC 5226 [RFC5226].
As part of this registry IANA will maintain the following As part of this registry, IANA maintains the following information:
information:
Status Code Status Code
The Status Code which denotes a reason for a WebSocket connection The Status Code denotes a reason for a WebSocket connection
closure as per Section 7.4 of this document. The status code is closure as per Section 7.4 of this document. The status code is
an integer number between 1000 and 4999 (inclusive). an integer number between 1000 and 4999 (inclusive).
Meaning Meaning
The meaning of the status code. Each status code has to have a The meaning of the status code. Each status code has to have a
unique meaning. unique meaning.
Contact Contact
A contact for the entity reserving the status code. A contact for the entity reserving the status code.
Reference Reference
The stable document requesting the status codes and defining their The stable document requesting the status codes and defining their
meaning. This is required for status codes in the range 1000- meaning. This is required for status codes in the range 1000-2999
2999, and recommended for status codes in the range 3000-3999. and recommended for status codes in the range 3000-3999.
WebSocket Close Code Numbers are to be subject to different WebSocket Close Code Numbers are subject to different registration
registration requirements depending on their range. Unless otherwise requirements depending on their range. Requests for status codes for
specified, requests are subject to "Standards Action" IANA use by this protocol and its subsequent versions or extensions are
registration policy [RFC5226]. Requests for status codes for use by subject to any one of the "Standards Action", "Specification
this protocol, its subsequent versions or extensions are subject to Required" (which implies "Designated Expert"), or "IESG Review" IANA
any one of "Standards Action", "Specification Required" (which registration policies and should be granted in the range 1000-2999.
implies "Designated Expert") or "IESG Review" IANA registration Requests for status codes for use by libraries, frameworks, and
policies and should be granted status codes in the range 1000-2999. applications are subject to the "First Come First Served" IANA
Requests for status codes for use by libraries, frameworks and
applications are subject to "First Come First Served" IANA
registration policy and should be granted in the range 3000-3999. registration policy and should be granted in the range 3000-3999.
The range of status codes from 4000-4999 is designated for Private The range of status codes from 4000-4999 is designated for Private
Use. Requests should indicate whether they are requesting status Use. Requests should indicate whether they are requesting status
codes for use by the WebSocket protocol (or a future version of the codes for use by the WebSocket Protocol (or a future version of the
protocol) or by extensions, or by libraries/frameworks/applications. protocol), by extensions, or by libraries/frameworks/applications.
IANA is asked to add initial values to the registry, with suggested IANA has added initial values to the registry as follows.
numerical values as these have been used in past versions of this
protocol.
|Status Code | Meaning | Contact | Reference | |Status Code | Meaning | Contact | Reference |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1000 | Normal Closure | hybi@ietf.org | RFC XXXX | | 1000 | Normal Closure | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1001 | Going Away | hybi@ietf.org | RFC XXXX | | 1001 | Going Away | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1002 | Protocol error | hybi@ietf.org | RFC XXXX | | 1002 | Protocol error | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1003 | Unsupported Data| hybi@ietf.org | RFC XXXX | | 1003 | Unsupported Data| hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1004 | ---Reserved---- | hybi@ietf.org | RFC XXXX | | 1004 | ---Reserved---- | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1005 | No Status Rcvd | hybi@ietf.org | RFC XXXX | | 1005 | No Status Rcvd | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1006 | Abnormal Closure| hybi@ietf.org | RFC XXXX | | 1006 | Abnormal Closure| hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1007 | Invalid frame | hybi@ietf.org | RFC XXXX | | 1007 | Invalid frame | hybi@ietf.org | RFC 6455 |
| | payload data | | | | | payload data | | |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1008 | Policy Violation| hybi@ietf.org | RFC XXXX | | 1008 | Policy Violation| hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1009 | Message Too Big | hybi@ietf.org | RFC XXXX | | 1009 | Message Too Big | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
| 1010 | Mandatory Ext. | hybi@ietf.org | RFC XXXX | | 1010 | Mandatory Ext. | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------|
| 1011 | Internal Server | hybi@ietf.org | RFC 6455 |
| | Error | | |
-+------------+-----------------+---------------+-----------|
| 1015 | TLS handshake | hybi@ietf.org | RFC 6455 |
-+------------+-----------------+---------------+-----------| -+------------+-----------------+---------------+-----------|
11.8. WebSocket Opcode Registry 11.8. WebSocket Opcode Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket Opcodes
WebSocket Opcodes in accordance with the principles set out in RFC in accordance with the principles set out in RFC 5226 [RFC5226].
5226 [RFC5226].
As part of this registry IANA will maintain the following As part of this registry, IANA maintains the following information:
information:
Opcode Opcode
The opcode denotes the frame type of the WebSocket frame, as The opcode denotes the frame type of the WebSocket frame, as
defined in Section 5.2. The status code is an integer number defined in Section 5.2. The opcode is an integer number between 0
between 0 and 15, inclusive. and 15, inclusive.
Meaning Meaning
The meaning of the opcode code. The meaning of the opcode value.
Reference Reference
The specification requesting the opcode. The specification requesting the opcode.
WebSocket Opcode numbers are subject to "Standards Action" IANA WebSocket Opcode numbers are subject to the "Standards Action" IANA
registration policy [RFC5226]. registration policy [RFC5226].
IANA is asked to add initial values to the registry, with suggested IANA has added initial values to the registry as follows.
numerical values as these have been used in past versions of this
protocol.
|Opcode | Meaning | Reference | |Opcode | Meaning | Reference |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 0 | Continuation Frame | RFC XXXX | | 0 | Continuation Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 1 | Text Frame | RFC XXXX | | 1 | Text Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 2 | Binary Frame | RFC XXXX | | 2 | Binary Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 8 | Connection Close Frame | RFC XXXX | | 8 | Connection Close Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 9 | Ping Frame | RFC XXXX | | 9 | Ping Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
| 10 | Pong Frame | RFC XXXX | | 10 | Pong Frame | RFC 6455 |
-+--------+-------------------------------------+-----------| -+--------+-------------------------------------+-----------|
11.9. WebSocket Framing Header Bits Registry 11.9. WebSocket Framing Header Bits Registry
This specification requests the creation of a new IANA registry for This specification creates a new IANA registry for WebSocket Framing
WebSocket Framing Header Bits in accordance with the principles set Header Bits in accordance with the principles set out in RFC 5226
out in RFC 5226 [RFC5226]. This registry controls assignment of the [RFC5226]. This registry controls assignment of the bits marked
bits marked RSV1, RSV2, and RSV3 in Section 5.2. RSV1, RSV2, and RSV3 in Section 5.2.
These bits are reserved for future versions or extensions of this These bits are reserved for future versions or extensions of this
specification. specification.
WebSocket Framing Header Bits assignments are subject to "Standards WebSocket Framing Header Bits assignments are subject to the
Action" IANA registration policy [RFC5226]. "Standards Action" IANA registration policy [RFC5226].
12. Using the WebSocket protocol from Other Specifications 12. Using the WebSocket Protocol from Other Specifications
The WebSocket protocol is intended to be used by another The WebSocket Protocol is intended to be used by another
specification to provide a generic mechanism for dynamic author- specification to provide a generic mechanism for dynamic author-
defined content, e.g. in a specification defining a scripted API. defined content, e.g., in a specification defining a scripted API.
Such a specification first needs to _Establish a WebSocket Such a specification first needs to _Establish a WebSocket
Connection_, providing that algorithm with: Connection_, providing that algorithm with:
o The destination, consisting of a /host/ and a /port/. o The destination, consisting of a /host/ and a /port/.
o A /resource name/, which allows for multiple services to be o A /resource name/, which allows for multiple services to be
identified at one host and port. identified at one host and port.
o A /secure/ flag, which is true if the connection is to be o A /secure/ flag, which is true if the connection is to be
encrypted, and false otherwise. encrypted and false otherwise.
o An ASCII serialization of an origin that is being made responsible o An ASCII serialization of an origin [RFC6454] that is being made
for the connection. [I-D.ietf-websec-origin] responsible for the connection.
o Optionally a string identifying a protocol that is to be layered o Optionally, a string identifying a protocol that is to be layered
over the WebSocket connection. over the WebSocket connection.
The /host/, /port/, /resource name/, and /secure/ flag are usually The /host/, /port/, /resource name/, and /secure/ flag are usually
obtained from a URI using the steps to parse a WebSocket URI's obtained from a URI using the steps to parse a WebSocket URI's
components. These steps fail if the URI does not specify a components. These steps fail if the URI does not specify a
WebSocket. WebSocket.
If at any time the connection is to be closed, then the specification If at any time the connection is to be closed, then the specification
needs to use the _Close the WebSocket Connection_ algorithm needs to use the _Close the WebSocket Connection_ algorithm
(Section 7.1.1). (Section 7.1.1).
skipping to change at page 73, line 16 skipping to change at page 67, line 45
Special thanks are due to Ian Hickson, who was the original author Special thanks are due to Ian Hickson, who was the original author
and editor of this protocol. The initial design of this and editor of this protocol. The initial design of this
specification benefitted from the participation of many people in the specification benefitted from the participation of many people in the
WHATWG and WHATWG mailing list. Contributions to that specification WHATWG and WHATWG mailing list. Contributions to that specification
are not tracked by section, but a list of all who contributed to that are not tracked by section, but a list of all who contributed to that
specification is given in the WHATWG HTML specification at specification is given in the WHATWG HTML specification at
http://whatwg.org/html5. http://whatwg.org/html5.
Special thanks also to John Tamplin for providing a significant Special thanks also to John Tamplin for providing a significant
amount of text for the Data Framing section of this specification. amount of text for the "Data Framing" section of this specification.
Special thanks also to Adam Barth for providing a significant amount Special thanks also to Adam Barth for providing a significant amount
of text and background research for the Data Masking section of this of text and background research for the "Data Masking" section of
specification. this specification.
Special thanks to Lisa Dusseault for the Apps Area review (and for Special thanks to Lisa Dusseault for the Apps Area review (and for
helping to start this work), Richard Barnes for the Gen-Art review helping to start this work), Richard Barnes for the Gen-Art review,
and Magnus Westerlund for the Transport Area Review. Special thanks and Magnus Westerlund for the Transport Area Review. Special thanks
to HYBI WG past and present WG chairs who tirelessly worked behind to HYBI WG past and present WG chairs who tirelessly worked behind
the scene to move this work toward completion: Joe Hildebrand, the scene to move this work toward completion: Joe Hildebrand,
Salvatore Loreto and Gabriel Montenegro. And last but not least, Salvatore Loreto, and Gabriel Montenegro. And last but not least,
special thank you to the responsible Area Director Peter Saint-Andre. special thank you to the responsible Area Director Peter Saint-Andre.
Thank you to the following people who participated in discussions on Thank you to the following people who participated in discussions on
the HYBI WG mailing list and contributed ideas and/or provided the HYBI WG mailing list and contributed ideas and/or provided
detailed reviews (the list is likely to be incomplete): Greg Wilkins, detailed reviews (the list is likely to be incomplete): Greg Wilkins,
John Tamplin, Willy Tarreau, Maciej Stachowiak, Jamie Lokier, Scott John Tamplin, Willy Tarreau, Maciej Stachowiak, Jamie Lokier, Scott
Ferguson, Bjoern Hoehrmann, Julian Reschke, Dave Cridland, Andy Ferguson, Bjoern Hoehrmann, Julian Reschke, Dave Cridland, Andy
Green, Eric Rescorla, Inaki Baz Castillo, Martin Thomson, Roberto Green, Eric Rescorla, Inaki Baz Castillo, Martin Thomson, Roberto
Peon, Patrick McManus, Zhong Yu, Bruce Atherton, Takeshi Yoshino, Peon, Patrick McManus, Zhong Yu, Bruce Atherton, Takeshi Yoshino,
Martin J. Duerst, James Graham, Simon Pieters, Roy T. Fielding, Martin J. Duerst, James Graham, Simon Pieters, Roy T. Fielding,
Mykyta Yevstifeyev, Len Holgate, Paul Colomiets, Piotr Kulaga, Brian Mykyta Yevstifeyev, Len Holgate, Paul Colomiets, Piotr Kulaga, Brian
Raymor, Jan Koehler, Joonas Lehtolahti, Sylvain Hellegouarch, Stephen Raymor, Jan Koehler, Joonas Lehtolahti, Sylvain Hellegouarch, Stephen
Farrell, Sean Turner, Pete Resnick, Peter Thorson, Joe Mason, John Farrell, Sean Turner, Pete Resnick, Peter Thorson, Joe Mason, John
Fallows, Alexander Philippou. Note that people listed above didn't Fallows, and Alexander Philippou. Note that people listed above
necessarily endorse the end result of this work. didn't necessarily endorse the end result of this work.
14. References 14. References
14.1. Normative References 14.1. Normative References
[ANSI.X3-4.1986] [ANSI.X3-4.1986]
American National Standards Institute, "Coded Character American National Standards Institute, "Coded Character
Set - 7-bit American Standard Code for Information Set - 7-bit American Standard Code for Information
Interchange", ANSI X3.4, 1986. Interchange", ANSI X3.4, 1986.
[FIPS.180-2.2002] [FIPS.180-3]
National Institute of Standards and Technology, "Secure National Institute of Standards and Technology, "Secure
Hash Standard", FIPS PUB 180-2, August 2002, <http:// Hash Standard", FIPS PUB 180-3, October 2008,
csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf>. <http://csrc.nist.gov/publications/fips/fips180-3/
fips180-3_final.pdf>.
[RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and [RFC1928] Leech, M., Ganis, M., Lee, Y., Kuris, R., Koblas, D., and
L. Jones, "SOCKS Protocol Version 5", RFC 1928, L. Jones, "SOCKS Protocol Version 5", RFC 1928,
March 1996. March 1996.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997. Requirement Levels", BCP 14, RFC 2119, March 1997.
[RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H., [RFC2616] Fielding, R., Gettys, J., Mogul, J., Frystyk, H.,
Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext Masinter, L., Leach, P., and T. Berners-Lee, "Hypertext
skipping to change at page 74, line 52 skipping to change at page 69, line 27
[RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform [RFC3986] Berners-Lee, T., Fielding, R., and L. Masinter, "Uniform
Resource Identifier (URI): Generic Syntax", STD 66, Resource Identifier (URI): Generic Syntax", STD 66,
RFC 3986, January 2005. RFC 3986, January 2005.
[RFC3987] Duerst, M. and M. Suignard, "Internationalized Resource [RFC3987] Duerst, M. and M. Suignard, "Internationalized Resource
Identifiers (IRIs)", RFC 3987, January 2005. Identifiers (IRIs)", RFC 3987, January 2005.
[RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness [RFC4086] Eastlake, D., Schiller, J., and S. Crocker, "Randomness
Requirements for Security", BCP 106, RFC 4086, June 2005. Requirements for Security", BCP 106, RFC 4086, June 2005.
[RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security
(TLS) Protocol Version 1.2", RFC 5246, August 2008.
[RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions:
Extension Definitions", RFC 6066, January 2011.
[RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data [RFC4648] Josefsson, S., "The Base16, Base32, and Base64 Data
Encodings", RFC 4648, October 2006. Encodings", RFC 4648, October 2006.
[RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an [RFC5226] Narten, T. and H. Alvestrand, "Guidelines for Writing an
IANA Considerations Section in RFCs", BCP 26, RFC 5226, IANA Considerations Section in RFCs", BCP 26, RFC 5226,
May 2008. May 2008.
[RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax [RFC5234] Crocker, D. and P. Overell, "Augmented BNF for Syntax
Specifications: ABNF", STD 68, RFC 5234, January 2008. Specifications: ABNF", STD 68, RFC 5234, January 2008.
[I-D.ietf-websec-origin] [RFC5246] Dierks, T. and E. Rescorla, "The Transport Layer Security
Barth, A., "The Web Origin Concept", (TLS) Protocol Version 1.2", RFC 5246, August 2008.
draft-ietf-websec-origin-05 (work in progress),
September 2011.
14.2. Informative References [RFC6066] Eastlake, D., "Transport Layer Security (TLS) Extensions:
Extension Definitions", RFC 6066, January 2011.
[WSAPI] Hickson, I., "The Web Sockets API", August 2010, [RFC6454] Barth, A., "The Web Origin Concept", RFC 6454,
<http://dev.w3.org/html5/websockets/>. December 2011.
14.2. Informative References
[RFC4122] Leach, P., Mealling, M., and R. Salz, "A Universally [RFC4122] Leach, P., Mealling, M., and R. Salz, "A Universally
Unique IDentifier (UUID) URN Namespace", RFC 4122, Unique IDentifier (UUID) URN Namespace", RFC 4122,
July 2005. July 2005.
[RFC6265] Barth, A., "HTTP State Management Mechanism", RFC 6265, [RFC4270] Hoffman, P. and B. Schneier, "Attacks on Cryptographic
April 2011. Hashes in Internet Protocols", RFC 4270, November 2005.
[RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321, [RFC5321] Klensin, J., "Simple Mail Transfer Protocol", RFC 5321,
October 2008. October 2008.
[RFC6202] Loreto, S., Saint-Andre, P., Salsano, S., and G. Wilkins, [RFC6202] Loreto, S., Saint-Andre, P., Salsano, S., and G. Wilkins,
"Known Issues and Best Practices for the Use of Long "Known Issues and Best Practices for the Use of Long
Polling and Streaming in Bidirectional HTTP", RFC 6202, Polling and Streaming in Bidirectional HTTP", RFC 6202,
April 2011. April 2011.
[RFC4270] Hoffman, P. and B. Schneier, "Attacks on Cryptographic [RFC6265] Barth, A., "HTTP State Management Mechanism", RFC 6265,
Hashes in Internet Protocols", RFC 4270, November 2005. April 2011.
[TALKING] Huang, L-S., Chen, E., Barth, A., Rescorla, E., and C.
Jackson, "Talking to Yourself for Fun and Profit", 2010,
<http://w2spconf.com/2011/papers/websocket.pdf>.
[W3C.REC-wsc-ui-20100812] [W3C.REC-wsc-ui-20100812]
Roessler, T. and A. Saldhana, "Web Security Context: User Roessler, T. and A. Saldhana, "Web Security Context: User
Interface Guidelines", World Wide Web Consortium Interface Guidelines", World Wide Web Consortium
Recommendation REC-wsc-ui-20100812, August 2010, Recommendation REC-wsc-ui-20100812, August 2010,
<http://www.w3.org/TR/2010/REC-wsc-ui-20100812>. <http://www.w3.org/TR/2010/REC-wsc-ui-20100812/>.
[TALKING] Huang, L-S., Chen, E., Barth, A., and E. Rescorla, Latest version available at
"Talking to Yourself for Fun and Profit", 2010, <http:// <http://www.w3.org/TR/wsc-ui/>.
www.adambarth.com/papers/2011/
huang-chen-barth-rescorla-jackson.pdf>. [WSAPI] Hickson, I., "The WebSocket API", W3C Working Draft WD-
websockets-20110929, September 2011,
<http://www.w3.org/TR/2011/WD-websockets-20110929/>.
Latest version available at
<http://www.w3.org/TR/websockets/>.
[XMLHttpRequest] [XMLHttpRequest]
van Kesteren, A., Ed., "XMLHttpRequest", August 2010, van Kesteren, A., Ed., "XMLHttpRequest", W3C Candidate
Recommendation CR-XMLHttpRequest-20100803, August 2010,
<http://www.w3.org/TR/2010/CR-XMLHttpRequest-20100803/>.
Latest version available at
<http://www.w3.org/TR/XMLHttpRequest/>. <http://www.w3.org/TR/XMLHttpRequest/>.
Authors' Addresses Authors' Addresses
Ian Fette Ian Fette
Google, Inc. Google, Inc.
Email: ifette+ietf@google.com EMail: ifette+ietf@google.com
URI: http://www.ianfette.com/ URI: http://www.ianfette.com/
Alexey Melnikov Alexey Melnikov
Isode Ltd Isode Ltd.
5 Castle Business Village 5 Castle Business Village
36 Station Road 36 Station Road
Hampton, Middlesex TW12 2BX Hampton, Middlesex TW12 2BX
UK UK
Email: Alexey.Melnikov@isode.com EMail: Alexey.Melnikov@isode.com
 End of changes. 431 change blocks. 
1116 lines changed or deleted 1163 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/