Fail fast on bad schemes

This commit is contained in:
Patrick Shaughnessy 2020-02-05 15:22:45 -05:00
parent 5f55cd5d71
commit 7ef644c1f7
3 changed files with 14 additions and 30 deletions

View file

@ -32,7 +32,7 @@ use js::conversions::ToJSValConvertible;
use js::jsval::UndefinedValue;
use mime::{self, Mime};
use net_traits::request::{CacheMode, CorsSettings, Destination, RequestBuilder};
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata};
use net_traits::{CoreResourceMsg, FetchChannels, FetchMetadata, FilteredMetadata};
use net_traits::{FetchResponseListener, FetchResponseMsg, NetworkError};
use net_traits::{ResourceFetchTiming, ResourceTimingType};
use servo_atoms::Atom;
@ -339,7 +339,12 @@ impl FetchResponseListener for EventSourceContext {
Ok(fm) => {
let meta = match fm {
FetchMetadata::Unfiltered(m) => m,
FetchMetadata::Filtered { unsafe_, .. } => unsafe_,
FetchMetadata::Filtered { unsafe_, filtered } => match filtered {
FilteredMetadata::Opaque | FilteredMetadata::OpaqueRedirect => {
return self.fail_the_connection()
},
_ => unsafe_,
},
};
let mime = match meta.content_type {
None => return self.fail_the_connection(),
@ -352,7 +357,13 @@ impl FetchResponseListener for EventSourceContext {
self.announce_the_connection();
},
Err(_) => {
self.reestablish_the_connection();
// The spec advises failing here if reconnecting would be
// "futile", with no more specific advice; WPT tests
// consider a non-http(s) scheme to be futile.
match self.event_source.root().url.scheme() {
"http" | "https" => self.reestablish_the_connection(),
_ => self.fail_the_connection(),
}
},
}
}

View file

@ -5,13 +5,3 @@
[dedicated worker - EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: FAIL
[dedicated worker - EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: FAIL

View file

@ -1,17 +0,0 @@
[eventsource-constructor-non-same-origin.htm]
type: testharness
[EventSource: constructor (act as if there is a network error) (http://example.not/)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (https://example.not/test)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (ftp://example.not/)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (mailto:whatwg@awesome.example)]
expected: FAIL
[EventSource: constructor (act as if there is a network error) (javascript:alert('FAIL'))]
expected: FAIL