Skip to content

Commit 10f708e

Browse files
authored
Fetch: X-Content-Type-Options: nosniff parsing
For whatwg/fetch#818.
1 parent db7f862 commit 10f708e

10 files changed

+92
-66
lines changed

fetch/nosniff/parsing-nosniff.html

-28
This file was deleted.
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
promise_test(() => fetch("resources/x-content-type-options.json").then(res => res.json()).then(runTests), "Loading JSON…");
2+
3+
function runTests(allTestData) {
4+
for (let i = 0; i < allTestData.length; i++) {
5+
const testData = allTestData[i],
6+
input = encodeURIComponent(testData.input);
7+
async_test(t => {
8+
const script = document.createElement("script");
9+
t.add_cleanup(() => script.remove());
10+
// A <script> element loading a classic script does not care about the MIME type, unless
11+
// X-Content-Type-Options: nosniff is specified, in which case a JavaScript MIME type is
12+
// enforced, which x/x is not.
13+
if (testData.nosniff) {
14+
script.onerror = t.step_func_done();
15+
script.onload = t.unreached_func("Script should not have loaded");
16+
} else {
17+
script.onerror = t.unreached_func("Script should have loaded");
18+
script.onload = t.step_func_done();
19+
}
20+
script.src = "resources/nosniff.py?nosniff=" + input;
21+
document.body.appendChild(script);
22+
}, input);
23+
}
24+
}

fetch/nosniff/resources/nosniff-first.asis

-7
This file was deleted.

fetch/nosniff/resources/nosniff-last.asis

-7
This file was deleted.

fetch/nosniff/resources/nosniff-no-x.asis

-6
This file was deleted.

fetch/nosniff/resources/nosniff-quoted-single.asis

-6
This file was deleted.

fetch/nosniff/resources/nosniff-quoted.asis

-6
This file was deleted.

fetch/nosniff/resources/nosniff-uppercase.asis

-6
This file was deleted.

fetch/nosniff/resources/nosniff.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def main(request, response):
2+
response.add_required_headers = False
3+
output = "HTTP/1.1 220 YOU HAVE NO POWER HERE\r\n"
4+
output += "Content-Length: 22\r\n"
5+
output += "Content-Type: x/x\r\n"
6+
output += request.GET.first("nosniff") + "\r\n"
7+
output += "\r\n"
8+
output += "// nothing to see here"
9+
response.writer.write(output)
10+
response.close_connection = True
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[
2+
{
3+
"input": "X-Content-Type-Options: NOSNIFF",
4+
"nosniff": true
5+
},
6+
{
7+
"input": "x-content-type-OPTIONS: nosniff",
8+
"nosniff": true
9+
},
10+
{
11+
"input": "X-Content-Type-Options: nosniff,,@#$#%%&^&^*()()11!",
12+
"nosniff": true
13+
},
14+
{
15+
"input": "X-Content-Type-Options: @#$#%%&^&^*()()11!,nosniff",
16+
"nosniff": false
17+
},
18+
{
19+
"input": "X-Content-Type-Options: nosniff\r\nX-Content-Type-Options: no",
20+
"nosniff": true
21+
},
22+
{
23+
"input": "X-Content-Type-Options: no\r\nX-Content-Type-Options: nosniff",
24+
"nosniff": false
25+
},
26+
{
27+
"input": "X-Content-Type-Options:\r\nX-Content-Type-Options: nosniff",
28+
"nosniff": false
29+
},
30+
{
31+
"input": "X-Content-Type-Options: ,nosniff",
32+
"nosniff": false
33+
},
34+
{
35+
"input": "X-Content-Type-Options: nosniff\u000C",
36+
"nosniff": false
37+
},
38+
{
39+
"input": "X-Content-Type-Options: nosniff\u000B",
40+
"nosniff": false
41+
},
42+
{
43+
"input": "X-Content-Type-Options: nosniff\u000B,nosniff",
44+
"nosniff": false
45+
},
46+
{
47+
"input": "X-Content-Type-Options: 'NosniFF'",
48+
"nosniff": false
49+
},
50+
{
51+
"input": "X-Content-Type-Options: \"nosniFF\"",
52+
"nosniff": false
53+
},
54+
{
55+
"input": "Content-Type-Options: nosniff",
56+
"nosniff": false
57+
}
58+
]

0 commit comments

Comments
 (0)