get-header-keys-for-browser.js
3.58 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var config_1 = __importDefault(require("./config"));
function goodBrowser() {
return ['Content-Security-Policy'];
}
var handlersByBrowserName = {
'Android Browser': function (browser) {
var osVersionName = browser.getOS().versionName;
if (osVersionName && parseFloat(osVersionName) < 4.4) {
return [];
}
return ['Content-Security-Policy'];
},
Chrome: function (browser) {
var browserVersion = parseFloat(browser.getBrowserVersion());
if (browserVersion >= 14 && browserVersion < 25) {
return ['X-WebKit-CSP'];
}
else if (browserVersion >= 25) {
return ['Content-Security-Policy'];
}
else {
return [];
}
},
'Chrome Mobile': function (browser, options) {
if (browser.getOSName() === 'iOS') {
return ['Content-Security-Policy'];
}
else {
return handlersByBrowserName['Android Browser'](browser, options);
}
},
Firefox: function (browser) {
var osName = browser.getOSName();
if (osName === 'iOS') {
return ['Content-Security-Policy'];
}
var browserVersion = parseFloat(browser.getBrowserVersion());
if (osName === 'Android') {
if (browserVersion >= 25) {
return ['Content-Security-Policy'];
}
else {
return ['X-Content-Security-Policy'];
}
}
else if (browser.getPlatformType(true) === 'mobile') {
// This is probably Firefox OS.
if (browserVersion >= 32) {
return ['Content-Security-Policy'];
}
else {
return ['X-Content-Security-Policy'];
}
}
else if (browserVersion >= 23) {
return ['Content-Security-Policy'];
}
else if (browserVersion >= 4 && browserVersion < 23) {
return ['X-Content-Security-Policy'];
}
else {
return [];
}
},
'Internet Explorer': function (browser) {
var browserVersion = parseFloat(browser.getBrowserVersion());
var header = browserVersion < 12 ? 'X-Content-Security-Policy' : 'Content-Security-Policy';
return [header];
},
'Microsoft Edge': goodBrowser,
'Microsoft Edge Mobile': goodBrowser,
Opera: function (browser) {
var browserVersion = parseFloat(browser.getBrowserVersion());
if (browserVersion >= 15) {
return ['Content-Security-Policy'];
}
else {
return [];
}
},
Safari: function (browser) {
var browserVersion = parseFloat(browser.getBrowserVersion());
if (browserVersion >= 7) {
return ['Content-Security-Policy'];
}
else if (browserVersion >= 6) {
return ['X-WebKit-CSP'];
}
else {
return [];
}
},
};
module.exports = function getHeaderKeysForBrowser(browser, options) {
if (!browser) {
return config_1.default.allHeaders;
}
if (options.disableAndroid && browser.getOSName() === 'Android') {
return [];
}
var browserName = browser.getBrowserName();
if (Object.prototype.hasOwnProperty.call(handlersByBrowserName, browserName)) {
return handlersByBrowserName[browserName](browser, options);
}
else {
return config_1.default.allHeaders;
}
};