Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
file system
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
14 May 2009 at 20:55 UTC
Updated:
11 Oct 2017 at 18:32 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
sreynen commentedSummary of "IE's stupid content sniffing behavior": IE will render some files as different types than the extension suggests (e.g. a .txt file might be rendered as an image or HTML file).
Comment #2
panchoAny progress?
Comment #3
jbrown commentedsubscribing
Comment #4
pwolanin commentedInstead we should perhaps add the "nosniff" header that IE8+ is supposed to respect
http://htaccess.wordpress.com/2009/09/22/x-content-type-options-nosniff-...
http://blogs.msdn.com/b/ie/archive/2008/09/02/ie8-security-part-vi-beta-...
Comment #5
pwolanin commentedComment #6
pwolanin commentedWe would need to change the core .htaccess file to check if mode_headers is enabled and then add the nosniff header when serving static content (or all content?)
http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
Comment #7
panchoI don't think we should really rely on the what browsers like to respect or not. One browser does, the other doesn't.
We should at least make sure validation hooks are available to allow contrib to double-check the data. That might include this reverse-engineered IE-code.
Comment #8
noamdanon commentedwe were facing same problem with a large enterprise customer.
I think the solution should be inherent to Drupal core, and it is rather simple to solve most of it.
The rest 0.01% might need some special care.
Solution:
in upload module when validating uploaded images:
- if the file is 'txt' - make sure it does not contain HTML and if so do not pass validation
- if the file is an image (gif/jpeg) - call getimagesize() function to see if it is a real image. if False returned - do not allow it
This simple patch will solve this. And if I missed some scenario, it is easily added in the right place, where everyone using Drupal will be able to enjoy it without patching the .htaccess file.
Comment #9
gregglesThat doesn't seem like a solution to me. It seems perfectly fine for a text file to contain a mix of different content including HTML.
Comment #10
damien tournoud commentedIf someone wants to implement content verification, let's not reinvent the wheel. Use the IEContentAnalyzer class from MediaWiki.
http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/includes/libs/IEC...
This can be easily implemented as a contrib module, let's bump this as a possible feature request for 8.x.
Comment #11
pwolanin commentedrelated: https://miki.it/blog/2014/7/8/abusing-jsonp-with-rosetta-flash/
This flash vuln would have been block by nosniff
see also: https://www.owasp.org/index.php/List_of_useful_HTTP_headers
Comment #12
pwolanin commentedquick 1st pass
Comment #13
dawehnerIt would be great to link to some resource where this header is explained.
Comment #14
pwolanin commentedhow about this?
Comment #15
pwolanin commentedShould probably add a test that at least verifies the header is set any time PHP serves the response?
Comment #16
gregglesMakes sense to me.
Comment #17
pwolanin commentedHere's a small added test, and fix the htaccess directive
Comment #18
gregglesThis incremental change makes sense to me. Seems like a nice addition.
I filed #2400087: D7 port of 462950 - Mitigate the security risks that come from IE and other browsers trying to sniff the mime type to get this into a d7 environment so we can get broader testing just in case this doesn't get backported (or not quickly).
Comment #19
pwolanin commentedWell, let me see about rolling a Drupal 7 version - it should be easy, but we can use that other issue for now to run the tests.
Comment #20
alexpottThe implementation turned out not to be a feature. Given that facebook and google use this I think it makes sense.
This issue is a major task that will improve security and the disruption it introduces is limited. Per https://www.drupal.org/core/beta-changes, this is a good change to complete during the Drupal 8 beta phase.
Committed 1f380a6 and pushed to 8.0.x. Thanks!
Comment #21
alexpottComment #23
pwolanin commentedcopying the patch over from the other issue. Not sure why it fails. There is something funny about testbot compared to local results for me.
Comment #25
xjmComment #28
pere orgaRerolled patch #23.
Comment #29
pere orgaNow with the right extension
Comment #32
pere orgaThat test is working in my local install. Is that an issue with the test bot?
Comment #33
pwolanin commented@Pere Orga - that's the same question I had in #23 - passed locally but not on the bot
Comment #34
pere orgaok, so this is technically Reviewed and Tested By the Community but not Ready To Be Committed, until we fix the bot.
Should we create a separate issue for the bot somewhere?
Comment #35
pere orgaOtherwise, we can also commit it without the test. Tests can be added later but shouldn't delay a security improvement imho
Comment #36
fabianx commentedAgree, lets do it.
Comment #37
pere orgaDidn't want to hide D8 patch
Comment #38
pwolanin commentedThis is actually critical, since Chrome is affected too in some cases.
Comment #39
David_Rothstein commentedComment #41
David_Rothstein commentedCommitted to 7.x - thanks!
I'm not sure if "Header always set" will break Apache 1.x, but we may have reached the point where we officially stop caring :)
Question, though - we are setting this header on uncached page requests, but not on cached ones - is that an oversight? Leaving the issue open for that, for now.
I also fixed this on commit (not sure why the code comment from Drupal 8 wasn't backported):
Comment #42
David_Rothstein commentedRemoving tag - this doesn't have a change record, and probably doesn't need one actually.
Comment #43
pwolanin commented@David_Rothstein
I think the headers are added to the cache and should be added by drupal_serve_page_from_cache():
Comment #44
kaosagnt commentedThis seems to have been added to Drupal 7.40 as an apache mod_headers directive
Header always set blah
Why was it not a Header merge blah?
Drupal module seckit allowed setting this header and now you wind up with
X-Content-Type-Options: nosniff, nosniff
in the headers. A merge still sets the header if it is not set.
Comment #45
pwolanin commentedThe docs claims it will replace the value:
http://httpd.apache.org/docs/2.2/mod/mod_headers.html
what apache version are you using?
Comment #46
kaosagnt commentedA mixture of
Server version: Apache/2.2.15 (Unix)
Server version: Apache/2.4.12 (Red Hat)
merge works fine for me.
Comment #47
roball commentedI can confirm that as of Drupal 7.40, every page has the following response header included:
X-Content-Type-Options: nosniff, nosniffThe problem that the
nosniffvalue is set twice to theX-Content-Type-Optionsheader originates by the following addition to the.htaccessfile:Header always set X-Content-Type-Options nosniffThe problem in the above Apache directive is the
alwayscondition. That must be removed, so the directive readsHeader set X-Content-Type-Options nosniffI am using Apache 2.2.15 from a stock CentOS 6. No need to change the action from
settomerge.Comment #48
roball commentedHere is the patch that solves the problem mentioned in #47.
Comment #50
pwolanin commentedThis change looks reasonable, but we should make it for Drupal 8 also?
Comment #51
roball commentedThis issue still needs to be RTBC.
Comment #52
pwolanin commentedSo I'm seeing the opposite problem in Drupal 7 and 8, if I take out the "always" I get 2x nosniff header lines like:
Comment #53
roball commentedAnd, keeping the the
alwayscondition results inX-Content-Type-Options: nosniff, nosniff, right?
Comment #54
catchIt's really hard to follow re-opened issues both in terms of history on d.o and also git commits logs.
I've opened #2633204: (followup) Mitigate the security risks that come from IE, Chrome and other browsers trying to sniff the mime type for the follow-up work. Moving this back to 7.x and fixed.
Comment #55
fabianx commentedRestoring priority.
Comment #57
calmforce commentedIt looks like this feature completely broke my installation on openSUSE 11.4: For every js file I am getting now Chrome errors like "Refused to execute script from '<>/misc/drupal.js?o0epsk' because its MIME type ('text/x-js') is not executable, and strict MIME type checking is enabled."
I edited the file /etc/apache2/mime.types - commented out "text/x-js js" entry there and restarted Apache, but that did not help - I am still getting all these errors for js files. What do I have to do?
Comment #58
cilefen commentedThe openSUSE reference suggests editing mod_mime-defaults.conf.
Comment #59
calmforce commentedApparently, clearing Chrome caches was important for my change on the server to be recognized: it kept the old mime types way after I modified them on the server in the file /etc/apache2/mime.types and rebooted the server.
Comment #60
dolphinonmobile commentedThanks for the patch on #48
Comment #61
afschI got similar MIME issue with Chrome trying to load any kind of files. Any patch posted here worked in my case, so I opted to remove this part of code
'X-Content-Type-Options' => 'nosniff',in includes/bootstrap.inc. I'm using Drupal 7.43Comment #62
cilefen commented@alexito By doing so you have reduced the security of Drupal.
Comment #63
David_Rothstein commentedLooks like this is now being addressed at #2819535: x-content-type-options nosniff ignored for anonymous cached pages.
Comment #64
wim leersFollow-up #2633204: (followup) Mitigate the security risks that come from IE, Chrome and other browsers trying to sniff the mime type is superseded by #2854817: Duplicate X-Content-Type-Options headers both with the value nosniff.