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

Fetch: test nosniff parsing better #13559

Merged
merged 6 commits into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions fetch/nosniff/parsing-nosniff.html

This file was deleted.

24 changes: 24 additions & 0 deletions fetch/nosniff/parsing-nosniff.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
promise_test(() => fetch("resources/x-content-type-options.json").then(res => res.json()).then(runTests), "Loading JSON…");

function runTests(allTestData) {
for (let i = 0; i < allTestData.length; i++) {
const testData = allTestData[i],
input = encodeURIComponent(testData.input);
async_test(t => {
const script = document.createElement("script");
t.add_cleanup(() => script.remove());
// A <script> element loading a classic script does not care about the MIME type, unless
// X-Content-Type-Options: nosniff is specified, in which case a JavaScript MIME type is
// enforced, which x/x is not.
if (testData.nosniff) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I live completely in network land, so am far from knowledgeable about Javascript or the web platform, beyond HTTP (Admittedly, in Chrome, that also includes the MIME sniffing logic), but looking at the updated test, I still find it non-obvious why the nosniff results in errors. The sniffed as text -> treated as valid Javascipt connection isn't obvious to me.

That having been said, I do think that this makes it much clearer that the onerror cases correspond to nosniff being respected.

Maybe just something along the lines of "The resource must be sniffed as test to be successfully loaded as a script."

script.onerror = t.step_func_done();
script.onload = t.unreached_func("Script should not have loaded");
} else {
script.onerror = t.unreached_func("Script should have loaded");
script.onload = t.step_func_done();
}
script.src = "resources/nosniff.py?nosniff=" + input;
document.body.appendChild(script);
}, input);
}
}
7 changes: 0 additions & 7 deletions fetch/nosniff/resources/nosniff-first.asis

This file was deleted.

7 changes: 0 additions & 7 deletions fetch/nosniff/resources/nosniff-last.asis

This file was deleted.

6 changes: 0 additions & 6 deletions fetch/nosniff/resources/nosniff-no-x.asis

This file was deleted.

6 changes: 0 additions & 6 deletions fetch/nosniff/resources/nosniff-quoted-single.asis

This file was deleted.

6 changes: 0 additions & 6 deletions fetch/nosniff/resources/nosniff-quoted.asis

This file was deleted.

6 changes: 0 additions & 6 deletions fetch/nosniff/resources/nosniff-uppercase.asis

This file was deleted.

10 changes: 10 additions & 0 deletions fetch/nosniff/resources/nosniff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def main(request, response):
response.add_required_headers = False
output = "HTTP/1.1 220 YOU HAVE NO POWER HERE\r\n"
output += "Content-Length: 22\r\n"
output += "Content-Type: x/x\r\n"
output += request.GET.first("nosniff") + "\r\n"
output += "\r\n"
output += "// nothing to see here"
response.writer.write(output)
response.close_connection = True
58 changes: 58 additions & 0 deletions fetch/nosniff/resources/x-content-type-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"input": "X-Content-Type-Options: NOSNIFF",
"nosniff": true
},
{
"input": "x-content-type-OPTIONS: nosniff",
"nosniff": true
},
{
"input": "X-Content-Type-Options: nosniff,,@#$#%%&^&^*()()11!",
"nosniff": true
},
{
"input": "X-Content-Type-Options: @#$#%%&^&^*()()11!,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\r\nX-Content-Type-Options: no",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Should probably use consistent indentation for all of these (x3)

"nosniff": true
},
{
"input": "X-Content-Type-Options: no\r\nX-Content-Type-Options: nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options:\r\nX-Content-Type-Options: nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: ,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000C",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000B",
"nosniff": false
},
{
"input": "X-Content-Type-Options: nosniff\u000B,nosniff",
"nosniff": false
},
{
"input": "X-Content-Type-Options: 'NosniFF'",
"nosniff": false
},
{
"input": "X-Content-Type-Options: \"nosniFF\"",
"nosniff": false
},
{
"input": "Content-Type-Options: nosniff",
"nosniff": false
}
]