aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/websocket.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2015-07-21 20:11:57 -0400
committerJosh Matthews <josh@joshmatthews.net>2015-07-22 09:35:07 -0400
commitd385cb701b852684ea3ecfda104ac3711669a651 (patch)
tree362459b48681375a2bf8f829b591777c039d4284 /components/script/dom/websocket.rs
parentcb52cc66581191b6f787a4a6d0d2844e2968b7eb (diff)
downloadservo-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/dom/websocket.rs')
-rw-r--r--components/script/dom/websocket.rs32
1 files changed, 29 insertions, 3 deletions
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)
}
}