1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
"use strict";
const SCRIPT = "var foo = 24;";
const CSS = "body { background-color: green; }";
// small red image
const IMG = atob(
"iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12" +
"P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
);
function handleRequest(request, response) {
const query = new URLSearchParams(request.queryString);
// avoid confusing cache behaviors
response.setHeader("Cache-Control", "no-cache", false);
// set the nosniff header
response.setHeader("X-Content-Type-Options", " NoSniFF , foo ", false);
if (query.has("cssCorrectType")) {
response.setHeader("Content-Type", "teXt/cSs", false);
response.write(CSS);
return;
}
if (query.has("cssWrongType")) {
response.setHeader("Content-Type", "text/html", false);
response.write(CSS);
return;
}
if (query.has("scriptCorrectType")) {
response.setHeader("Content-Type", "appLIcation/jAvaScriPt;blah", false);
response.write(SCRIPT);
return;
}
if (query.has("scriptWrongType")) {
response.setHeader("Content-Type", "text/html", false);
response.write(SCRIPT);
return;
}
if (query.has("imgCorrectType")) {
response.setHeader("Content-Type", "iMaGe/pnG;blah", false);
response.write(IMG);
return;
}
if (query.has("imgWrongType")) {
response.setHeader("Content-Type", "text/html", false);
response.write(IMG);
return;
}
// we should never get here, but just in case
response.setHeader("Content-Type", "text/html", false);
response.write("do'h");
}
|