-
Notifications
You must be signed in to change notification settings - Fork 20
/
csp.js
30 lines (26 loc) · 850 Bytes
/
csp.js
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
const apiOrigin = process.env.API_ORIGIN;
const isProd = process.env.NODE_ENV === 'production';
const isFirefox = process.env.TARGET_BROWSER === 'firefox';
const cspObject = {
'default-src': ["'self'", apiOrigin],
'base-uri': ["'self'"],
'connect-src': [
apiOrigin,
...(isFirefox ? [] : ['https://www.google-analytics.com']),
...(isProd ? [] : ['ws:'])
],
'img-src': ['https://gravatar.com', 'https://*.wp.com', apiOrigin],
'font-src': ['https://fonts.gstatic.com'],
'object-src': ["'self'"],
'script-src': ["'self'"],
'style-src': ["'self'", 'https://fonts.googleapis.com/', "'unsafe-inline'"]
};
const buildPolicy = policyObj =>
Object.keys(policyObj)
.map(key => `${key} ${policyObj[key].join(' ')}`)
.join('; ');
const cspString = buildPolicy(cspObject);
module.exports = {
cspObject,
cspString
};