Skip to content
Permalink
Browse files

Fix module script MIME check to not include params

Also makes it error when there is no MIME type available.
  • Loading branch information
Manishearth committed Jan 6, 2020
1 parent be917ae commit 508bfbd0da53b0badf76e07c6286d6bd4e29900e
Showing with 11 additions and 2 deletions.
  1. +11 −2 components/script/script_module.rs
@@ -931,9 +931,18 @@ impl FetchResponseListener for ModuleContext {
let meta = self.metadata.take().unwrap();

if let Some(content_type) = meta.content_type.map(Serde::into_inner) {
if !SCRIPT_JS_MIMES.contains(&content_type.to_string().as_str()) {
return Err(NetworkError::Internal("Invalid MIME type".to_owned()));
let c = content_type.to_string();
// The MIME crate includes params (e.g. charset=utf8) in the to_string
// https://github.com/hyperium/mime/issues/120
if let Some(ty) = c.split(';').next() {
if !SCRIPT_JS_MIMES.contains(&ty) {
return Err(NetworkError::Internal(format!("Invalid MIME type: {}", ty)));
}
} else {
return Err(NetworkError::Internal("Empty MIME type".into()));
}
} else {
return Err(NetworkError::Internal("No MIME type".into()));
}

// Step 10.

0 comments on commit 508bfbd

Please sign in to comment.
You can’t perform that action at this time.