get-header-keys-for-browser.js
2.52 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
114
var config = require('./config')
function goodBrowser () {
return ['Content-Security-Policy']
}
var handlers = {
'Android Browser': function (browser, options) {
if (parseFloat(browser.os.version) < 4.4 || options.disableAndroid) {
return []
} else {
return ['Content-Security-Policy']
}
},
Chrome: function (browser) {
var version = parseFloat(browser.version)
if (version >= 14 && version < 25) {
return ['X-WebKit-CSP']
} else if (version >= 25) {
return ['Content-Security-Policy']
} else {
return []
}
},
'Chrome Mobile': function (browser) {
if (browser.os.family === 'iOS') {
return ['Content-Security-Policy']
} else {
return handlers['Android Browser'].apply(this, arguments)
}
},
Firefox: function (browser) {
var version = parseFloat(browser.version)
if (version >= 23) {
return ['Content-Security-Policy']
} else if (version >= 4 && version < 23) {
return ['X-Content-Security-Policy']
} else {
return []
}
},
'Firefox Mobile': function (browser) {
// Handles both Firefox for Android and Firefox OS
var family = browser.os.family
var version = parseFloat(browser.version)
if (family === 'Firefox OS') {
if (version >= 32) {
return ['Content-Security-Policy']
} else {
return ['X-Content-Security-Policy']
}
} else if (family === 'Android') {
if (version >= 25) {
return ['Content-Security-Policy']
} else {
return ['X-Content-Security-Policy']
}
}
return []
},
'Firefox for iOS': goodBrowser,
IE: function (browser) {
var version = parseFloat(browser.version)
var header = version < 12 ? 'X-Content-Security-Policy' : 'Content-Security-Policy'
return [header]
},
'Microsoft Edge': goodBrowser,
'Microsoft Edge Mobile': goodBrowser,
Opera: function (browser) {
if (parseFloat(browser.version) >= 15) {
return ['Content-Security-Policy']
} else {
return []
}
},
Safari: function (browser) {
var version = parseFloat(browser.version)
if (version >= 7) {
return ['Content-Security-Policy']
} else if (version >= 6) {
return ['X-WebKit-CSP']
} else {
return []
}
}
}
handlers['IE Mobile'] = handlers.IE
module.exports = function getHeaderKeysForBrowser (browser, options) {
var handler = handlers[browser.name]
if (handler) {
return handler(browser, options)
} else {
return config.allHeaders
}
}