Treat certain resources served "text/plain" as if they had no Content-Type header
Categories
(Firefox :: File Handling, defect)
Tracking
()
People
(Reporter: dosergio, Unassigned)
References
(Blocks 1 open bug, )
Details
(Whiteboard: DUPEME)
Reporter | ||
Comment 10•12 years ago
|
||
Reporter | ||
Comment 11•12 years ago
|
||
Comment 12•12 years ago
|
||
Updated•12 years ago
|
Comment 13•12 years ago
|
||
Reporter | ||
Comment 14•12 years ago
|
||
Comment 15•12 years ago
|
||
Updated•12 years ago
|
Updated•9 years ago
|
Comment 16•7 years ago
|
||
Comment 17•7 years ago
|
||
Comment 18•6 years ago
|
||
We received a webcompat report about a site serving an image file with content-type: text/plain; charset=utf-8
. This response renders as plain text (i.e. you see a lot of binary output) in Firefox, but Chrome renders the image. During research, I stumbled upon this issue.
From the original comment:
Firefox should offer to download/save the file instead.
In the MIME Sniffing spec, I found two potentially relevant paragraphs: § 7.2. Sniffing a mislabeled binary resource, and § 8.2. Sniffing in an image context. I am not sure if the second paragraphs applies, but given 7.2, I don't think we should be displaying the content, but instead treat is application/octet-stream
, the response in question starts with 0xFF 0xD8 0xFF
, which is none of the plain text-"approved" resource headers, but the byte pattern for a JPEG image, which even is added to the mimesniff spec.
Is this me misunderstanding the spec or Firefox doing something wrong? :)
Comment 19•6 years ago
|
||
text/plain; charset=utf-8
is one of the MIME types which should nonetheless be sniffed due to the Apache bug. bz, do you know why that's not implemented?
Comment 20•6 years ago
|
||
Added the URL from the mentioned WebCompat report for easier reproducing.
Comment 21•6 years ago
•
|
||
Annevk, when you say "Apache bug" I assume mean "the issue that Apache httpd used to have a content-type default"? Wasn't that using an ISO-8859-1 encoding?
EDIT: OK, I see that this goes back to the first versions of draft-abarth-mime-sniff - I'm still puzzled why this was needed though.
![]() |
||
Comment 22•6 years ago
|
||
Different versions of Apache had different behavior there; some had "ISO-8859-1" and some had "iso-8859-1" and some had "UTF-8". We have logic for all of those to treat as binary. See https://searchfox.org/mozilla-central/rev/60c4067b1cbb0f94d7dc2d7cdfa27ed579817fee/netwerk/streamconv/converters/nsUnknownDecoder.cpp#851-853
The type mentioned in comment 19 has "utf-8", which is not a thing Apache ever used to do, so we don't have special-casing for it.
Past that, what we implement has pretty much nothing to do with the minesniff standard in general in all sorts of ways, and the same for other browsers. But in this specific instance, the relevant part of mimesniff is https://mimesniff.spec.whatwg.org/#supplied-mime-type-detection-algorithm step 2.2 which sets the "check-for-apache-bug flag" in exactly the cases our current code sets it in, and in particular not for "text/plain; charset=utf-8".
Past all that, the issue with the headers from comment 5 is the "Content-Encoding: gzip". Obviously if the data is gzipped, trying to detect whether that (gzipped) data is binary or not is pointless; it's binary. So our code doesn't do that. See https://searchfox.org/mozilla-central/rev/60c4067b1cbb0f94d7dc2d7cdfa27ed579817fee/netwerk/streamconv/converters/nsUnknownDecoder.cpp#857-866. Since the buggy Apache configuration did not include sending Content-Encoding, this wasn't an issue for the Apache workaround. I can't tell whether https://mimesniff.spec.whatwg.org/#rules-for-text-or-binary is operating after undoing content-encodings or not, or whether the issue was even considered.
At this point, this bug is probably fairly useless, since it's "covering" at least two completely separate issues: (1) what do do with "text/plain" when Content-Encoding is set, (2) what to do with "text/plain; charset=utf-8".
Updated•2 years ago
|
Description
•