From e840698d4ad4eb1bf3cce688aa99b12dd4fde66d Mon Sep 17 00:00:00 2001 From: Alexander Putilin Date: Sun, 24 May 2015 03:53:15 +0300 Subject: [PATCH 1/2] fixes 4184: no-sniff and check-for-apache-bug for mime sniffing --- components/net/resource_task.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/components/net/resource_task.rs b/components/net/resource_task.rs index ac463503a1b..591e146af03 100644 --- a/components/net/resource_task.rs +++ b/components/net/resource_task.rs @@ -99,8 +99,23 @@ pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadat -> Result { if opts::get().sniff_mime_types { // TODO: should be calculated in the resource loader, from pull requeset #4094 - let nosniff = false; - let check_for_apache_bug = false; + let mut nosniff = false; + let mut check_for_apache_bug = false; + + if let Some(ref headers) = metadata.headers { + if let Some(ref raw_content_type) = headers.get_raw("content-type") { + let ref last_raw_content_type = raw_content_type[raw_content_type.len() - 1]; + check_for_apache_bug = last_raw_content_type == b"text/plain" + || last_raw_content_type == b"text/plain; charset=ISO-8859-1" + || last_raw_content_type == b"text/plain; charset=iso-8859-1" + || last_raw_content_type == b"text/plain; charset=UTF-8"; + } + if let Some(ref raw_content_type_options) = headers.get_raw("content-type-options") { + for options in raw_content_type_options.iter() { + nosniff = nosniff || options == b"nosniff"; + } + } + } let supplied_type = metadata.content_type.map(|ContentType(Mime(toplevel, sublevel, _))| { (format!("{}", toplevel), format!("{}", sublevel)) From f5a028583326ca21107e78fd3ab2fa0b3b0667a4 Mon Sep 17 00:00:00 2001 From: Alexander Putilin Date: Tue, 26 May 2015 01:04:05 +0300 Subject: [PATCH 2/2] Fix issues with PR #6171 --- components/net/resource_task.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/net/resource_task.rs b/components/net/resource_task.rs index 591e146af03..14d5e8fbba1 100644 --- a/components/net/resource_task.rs +++ b/components/net/resource_task.rs @@ -104,17 +104,17 @@ pub fn start_sending_sniffed_opt(start_chan: LoadConsumer, mut metadata: Metadat if let Some(ref headers) = metadata.headers { if let Some(ref raw_content_type) = headers.get_raw("content-type") { - let ref last_raw_content_type = raw_content_type[raw_content_type.len() - 1]; - check_for_apache_bug = last_raw_content_type == b"text/plain" - || last_raw_content_type == b"text/plain; charset=ISO-8859-1" - || last_raw_content_type == b"text/plain; charset=iso-8859-1" - || last_raw_content_type == b"text/plain; charset=UTF-8"; - } - if let Some(ref raw_content_type_options) = headers.get_raw("content-type-options") { - for options in raw_content_type_options.iter() { - nosniff = nosniff || options == b"nosniff"; + if raw_content_type.len() > 0 { + let ref last_raw_content_type = raw_content_type[raw_content_type.len() - 1]; + check_for_apache_bug = last_raw_content_type == b"text/plain" + || last_raw_content_type == b"text/plain; charset=ISO-8859-1" + || last_raw_content_type == b"text/plain; charset=iso-8859-1" + || last_raw_content_type == b"text/plain; charset=UTF-8"; } } + if let Some(ref raw_content_type_options) = headers.get_raw("X-content-type-options") { + nosniff = raw_content_type_options.iter().any(|ref opt| *opt == b"nosniff"); + } } let supplied_type = metadata.content_type.map(|ContentType(Mime(toplevel, sublevel, _))| {