Skip to content

Commit

Permalink
disallow restricted XMLHttpRequest header prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chandler Abraham authored and jdm committed Feb 26, 2016
1 parent aaad24c commit c375ad5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
34 changes: 20 additions & 14 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -423,20 +423,26 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
let name_lower = name.to_lower();
let name_str = match name_lower.as_str() {
Some(s) => {
match s {
// Step 5
// Disallowed headers
"accept-charset" | "accept-encoding" |
"access-control-request-headers" |
"access-control-request-method" |
"connection" | "content-length" |
"cookie" | "cookie2" | "date" |"dnt" |
"expect" | "host" | "keep-alive" | "origin" |
"referer" | "te" | "trailer" | "transfer-encoding" |
"upgrade" | "user-agent" | "via" => {
return Ok(());
},
_ => s
// Step 5
// Disallowed headers and header prefixes:
// https://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader-method
let disallowedHeaders =
["accept-charset", "accept-encoding",
"access-control-request-headers",
"access-control-request-method",
"connection", "content-length",
"cookie", "cookie2", "date", "dnt",
"expect", "host", "keep-alive", "origin",
"referer", "te", "trailer", "transfer-encoding",
"upgrade", "user-agent", "via"];

let disallowedHeaderPrefixes = ["sec-", "proxy-"];

if disallowedHeaders.iter().any(|header| *header == s) ||
disallowedHeaderPrefixes.iter().any(|prefix| s.starts_with(prefix)) {
return Ok(())
} else {
s
}
},
None => unreachable!()
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions tests/wpt/metadata/websockets/security/002.html.ini

This file was deleted.

0 comments on commit c375ad5

Please sign in to comment.