-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Changes from all commits
a3241bd
7dd984b
ee3c287
18280c2
fd3b2fa
882ac0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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) { | ||
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); | ||
} | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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 |
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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
] |
There was a problem hiding this comment.
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."