Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves #4183 - Implemementing context-based MIME type sniffing #7842

Closed
wants to merge 1 commit into from

Conversation

@Yoric
Copy link
Contributor

Yoric commented Oct 3, 2015

As mentioned in #4183, I'm not sure how to test this.

Review on Reviewable

@highfive
Copy link

highfive commented Oct 3, 2015

Thanks for the pull request, and welcome! The Servo team is excited to review your changes, and you should hear from @larsbergstrom (or someone else) soon.

@jdm jdm added the S-fails-tidy label Oct 3, 2015
// 1. If the supplied MIME type is undefined, [unspecified at the time of this implementation, so fallback to Browsing]
// 2. The computed MIME type is the supplied MIME type.
match *supplied_type {
None => self.classify(LoadContext::Browsing, no_sniff_flag, apache_bug_flag, supplied_type, data),

This comment has been minimized.

Copy link
@eefriedman

eefriedman Oct 3, 2015

Contributor

The actual algorithm should be something like this:

  1. If the supplied MIME type is undefined, the computed MIME type is "text/css".
  2. The computed MIME type is the supplied MIME type.

This comment has been minimized.

Copy link
@Yoric

Yoric Oct 4, 2015

Author Contributor

Fine with me. I just wanted to make sure that I didn't accidentally add something incompatible.

// 1. If the supplied MIME type is undefined, [unspecified at the time of this implementation, so fallback to Browsing]
// 2. The computed MIME type is the supplied MIME type.
match *supplied_type {
None => self.classify(LoadContext::Browsing, no_sniff_flag, apache_bug_flag, supplied_type, data),

This comment has been minimized.

Copy link
@eefriedman

eefriedman Oct 3, 2015

Contributor

Script should default to "application/javascript".

This comment has been minimized.

Copy link
@Yoric

Yoric Oct 4, 2015

Author Contributor

What, no vbscript :) ?
I'll do that.

@eefriedman
Copy link
Contributor

eefriedman commented Oct 3, 2015

In terms of testing this... we don't actually examine the mime type in non-browser contexts, so I'm pretty sure it's impossible to test without other changes. That said, it would probably be pretty easy to add some sensitivity. For example, if we only tried to render images which have a known mimetype, you could check that in an <img> tag an image served as text/html application/mathml+xml doesn't get rendered, but an image served as application/octet-stream does.

@Yoric Yoric force-pushed the Yoric:4183 branch from de8f675 to 9c775ad Oct 4, 2015
@Yoric
Copy link
Contributor Author

Yoric commented Oct 4, 2015

That said, it would probably be pretty easy to add some sensitivity. For example, if we only tried to render images which have a known mimetype, you could check that in an tag an image served as text/html doesn't get rendered, but an image served as application/octet-stream does.

Do you think we want this in Servo? Perhaps if sniffing is deactivated?

@Yoric Yoric force-pushed the Yoric:4183 branch from 9c775ad to 3b26540 Oct 4, 2015
//
// 4. The computed MIME type is the supplied MIME type.
match MIMEClassifier::maybe_get_media_type(supplied_type) {
Some(MediaType::Xml) | Some(MediaType::Html) => supplied_type.clone(),

This comment has been minimized.

Copy link
@eefriedman

eefriedman Oct 4, 2015

Contributor

"1. If the supplied MIME type is an XML type," doesn't mention HTML.

This comment has been minimized.

Copy link
@Yoric

Yoric Oct 4, 2015

Author Contributor

My bad, misread the definition of XML type.

@Yoric Yoric force-pushed the Yoric:4183 branch from 3b26540 to 9910617 Oct 4, 2015
@eefriedman
Copy link
Contributor

eefriedman commented Oct 4, 2015

Do you think we want this in Servo? Perhaps if sniffing is deactivated?

For testing purposes, perhaps only if sniffing is activated (which will be the default eventually).

@Yoric
Copy link
Contributor Author

Yoric commented Oct 5, 2015

I have applied the change you suggested to the image cache, but I haven't been able to see any different behavior. I suspect that the actual culprit is actually my lack of mastery of Apache, though, as Rust and Firefox seem to have the exact same behavior.

What's the next step?

@jdm jdm self-assigned this Oct 5, 2015
@bors-servo
Copy link
Contributor

bors-servo commented Oct 6, 2015

The latest upstream changes (presumably #7882) made this pull request unmergeable. Please resolve the merge conflicts.

@Yoric Yoric force-pushed the Yoric:4183 branch from 9910617 to ace3c71 Oct 7, 2015
@Yoric
Copy link
Contributor Author

Yoric commented Oct 7, 2015

Rebased. @jdm, I'm waiting for your instructions.

@bors-servo
Copy link
Contributor

bors-servo commented Oct 14, 2015

The latest upstream changes (presumably #7967) made this pull request unmergeable. Please resolve the merge conflicts.

@jdm
Copy link
Member

jdm commented Oct 18, 2015

For testing, you could add a MIME type check to the font-loading code (with a server that returns no Content-Type), and look at the Content-Type response header for an XHR to the same font.
-S-awaiting-review +S-needs-code-changes


Reviewed 12 of 12 files at r1, 3 of 3 files at r2, 5 of 5 files at r3.
Review status: all files reviewed at latest revision, 10 unresolved discussions, some commit checks failed.


components/net/http_loader.rs, line 141 [r1] (raw file):
The should be the same context as the original load.


components/net/mime_classifier.rs, line 76 [r1] (raw file):
It's generally preferred to have comments like // Step 1 rather than quoting the full spec text.


components/net/mime_classifier.rs, line 79 [r1] (raw file):
nit: . should be on the next line


components/net/mime_classifier.rs, line 90 [r1] (raw file):
Remove the HTML here.


components/net/mime_classifier.rs, line 109 [r1] (raw file):
@elifriedman Do you have sources to back this up? MIME sniffing is really hairy; I'd rather stick to implementing the precise spec text to start (i.e. don't take any action here)


components/net/mime_classifier.rs, line 118 [r1] (raw file):
This does not sound like a good idea to me; script sniffing-related errors are some of the most easily exploited. I'd rather take no action at all until the spec is clarified.


components/net/mime_classifier.rs, line 228 [r1] (raw file):
supplied_type.map(|(ref media_type, ref media_subtype)| {
MIMEClassifier::get_media_type(media_type, media_subtype)
})


components/net_traits/lib.rs, line 137 [r2] (raw file):
Let's use /// so it shows up in the docs.


components/script/document_loader.rs, line 41 [r1] (raw file):
nit: | on the previous line, please.


Comments from the review on Reviewable.io

@eefriedman
Copy link
Contributor

eefriedman commented Oct 18, 2015

Review status: all files reviewed at latest revision, 10 unresolved discussions, some commit checks failed.


components/net/mime_classifier.rs, line 109 [r1] (raw file):
Firefox also picks text/css for an unspecified MIME type; see http://mxr.mozilla.org/mozilla-central/source/layout/style/Loader.cpp#925 .

Granted, this is known to be a tricky area; sniffing CSS can lead to cross-origin attacks. See http://blogs.msdn.com/b/ie/archive/2010/10/26/mime-handling-changes-in-internet-explorer.aspx etc.

If we wanted to be extremely conservative, we could sniff to text/plain if the MIME type is unspecified.


components/net/mime_classifier.rs, line 118 [r1] (raw file):
Err, I'm not sure exactly what you think the risk is here? Firefox doesn't check the MIME type of JavaScript at all.


Comments from the review on Reviewable.io

The version of the standard is not finalized at the time of this writing.
Specifications may be found here: https://mimesniff.spec.whatwg.org/#context-specific-sniffing .
@Yoric Yoric force-pushed the Yoric:4183 branch from ace3c71 to a178e64 Oct 20, 2015
@jdm
Copy link
Member

jdm commented Oct 25, 2015

Rebased in #8190.

@jdm jdm closed this Oct 25, 2015
bors-servo added a commit that referenced this pull request Nov 26, 2015
Implemementing context-based MIME type sniffing

This is a rebase of #7842 that also adds a test.

@Yoric, how's this look to you?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8190)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Nov 26, 2015
Implemementing context-based MIME type sniffing

This is a rebase of #7842 that also adds a test.

@Yoric, how's this look to you?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8190)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Dec 31, 2015
Implemementing context-based MIME type sniffing

This is a rebase of #7842 that also adds a test.
Fixes #4183.

@Yoric, how's this look to you?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8190)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Dec 31, 2015
Implemementing context-based MIME type sniffing

This is a rebase of #7842 that also adds a test.
Fixes #4183.

@Yoric, how's this look to you?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8190)
<!-- Reviewable:end -->
bors-servo added a commit that referenced this pull request Dec 31, 2015
Implemementing context-based MIME type sniffing

This is a rebase of #7842 that also adds a test.
Fixes #4183.

@Yoric, how's this look to you?

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8190)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.