diff options
author | Josh Matthews <josh@joshmatthews.net> | 2015-07-21 20:11:57 -0400 |
---|---|---|
committer | Josh Matthews <josh@joshmatthews.net> | 2015-07-22 09:35:07 -0400 |
commit | d385cb701b852684ea3ecfda104ac3711669a651 (patch) | |
tree | 362459b48681375a2bf8f829b591777c039d4284 /components/script | |
parent | cb52cc66581191b6f787a4a6d0d2844e2968b7eb (diff) | |
download | servo-d385cb701b852684ea3ecfda104ac3711669a651.tar.gz servo-d385cb701b852684ea3ecfda104ac3711669a651.zip |
Reject websocket protocol requests that don't match https://tools.ietf.org/html/rfc6455#section-4.1 .
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/webidls/WebSocket.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/websocket.rs | 32 | ||||
-rw-r--r-- | components/script/lib.rs | 1 |
3 files changed, 31 insertions, 4 deletions
diff --git a/components/script/dom/webidls/WebSocket.webidl b/components/script/dom/webidls/WebSocket.webidl index 3fd2fcd403d..b29cf6ba4ed 100644 --- a/components/script/dom/webidls/WebSocket.webidl +++ b/components/script/dom/webidls/WebSocket.webidl @@ -4,7 +4,7 @@ enum BinaryType { "blob", "arraybuffer" }; -[Constructor(DOMString url)] +[Constructor(DOMString url, optional /*(*/DOMString /*or DOMString[])*/ protocols)] interface WebSocket : EventTarget { readonly attribute DOMString url; //ready state diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs index bd90a36680a..6b97352f65b 100644 --- a/components/script/dom/websocket.rs +++ b/components/script/dom/websocket.rs @@ -96,11 +96,34 @@ impl WebSocket { } - pub fn new(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> { + pub fn new(global: GlobalRef, + url: DOMString, + protocols: Option<DOMString>) + -> Fallible<Root<WebSocket>> { // Step 1. let parsed_url = try!(Url::parse(&url).map_err(|_| Error::Syntax)); let url = try!(parse_url(&parsed_url).map_err(|_| Error::Syntax)); + // Step 4. + let protocols = protocols.as_slice(); + + // Step 5. + for (i, protocol) in protocols.iter().enumerate() { + // https://tools.ietf.org/html/rfc6455#section-4.1 + // Handshake requirements, step 10 + if protocol.is_empty() { + return Err(Syntax); + } + + if protocols[i+1..].iter().any(|p| p == protocol) { + return Err(Syntax); + } + + if protocol.chars().any(|c| c < '\u{0021}' || c > '\u{007E}') { + return Err(Syntax); + } + } + /*TODO: This constructor is only a prototype, it does not accomplish the specs defined here: http://html.spec.whatwg.org @@ -150,8 +173,11 @@ impl WebSocket { Ok(ws) } - pub fn Constructor(global: GlobalRef, url: DOMString) -> Fallible<Root<WebSocket>> { - WebSocket::new(global, url) + pub fn Constructor(global: GlobalRef, + url: DOMString, + protocols: Option<DOMString>) + -> Fallible<Root<WebSocket>> { + WebSocket::new(global, url, protocols) } } diff --git a/components/script/lib.rs b/components/script/lib.rs index c57c0de7998..2712aaca88e 100644 --- a/components/script/lib.rs +++ b/components/script/lib.rs @@ -4,6 +4,7 @@ #![feature(append)] #![feature(arc_unique)] +#![feature(as_slice)] #![feature(as_unsafe_cell)] #![feature(borrow_state)] #![feature(box_raw)] |