-
Notifications
You must be signed in to change notification settings - Fork 1
/
csp.config.js
64 lines (59 loc) · 1.79 KB
/
csp.config.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
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
/*
* Content-Security-Policy
*/
const SELF = "'self'"
const PRODUCTION = '*.core.ac.uk core.ac.uk'
const config = {
'default-src': [SELF, PRODUCTION],
'script-src': [
SELF,
'*.google-analytics.com',
'*.doubleclick.net',
'*.googletagmanager.com',
'*.cloudflareinsights.com',
],
'script-src-elem': [
SELF,
'*.google-analytics.com',
'*.doubleclick.net',
'*.googletagmanager.com',
'*.cloudflareinsights.com',
],
// TODO: Move 'unsafe-inline' to dev when the Next.js' bug is resolved
// See more: https://github.com/vercel/next.js/issues/17445
'style-src': [SELF, "'unsafe-inline'"],
'img-src': [
SELF,
PRODUCTION,
'data:',
'*.openstreetmap.org',
// Google Analytics may transport data via image:
// https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#transport
'*.google-analytics.com',
'*.doubleclick.net',
'*.googletagmanager.com',
'*.cloudflareinsights.com',
],
'connect-src': [
SELF,
PRODUCTION,
'sentry.io',
'*.google-analytics.com',
'*.doubleclick.net',
'*.googletagmanager.com',
'*.cloudflareinsights.com',
],
}
if (process.env.NODE_ENV !== 'production') {
// Allow hot module replacement using inlined scripts and styles
config['script-src'].push("'unsafe-inline'", "'unsafe-eval'")
config['script-src-elem'].push("'unsafe-inline'", "'unsafe-eval'")
// Allow connection to the local hosts in development:
// - local API is running on a different port
// - `localhost` and `127.0.0.1` are not the same domain technically
config['connect-src'].push('localhost:* 127.0.0.1:* api-dev.core.ac.uk')
}
const policy = Object.entries(config)
.map(([directive, value]) => `${directive} ${value.join(' ')}`)
.join(';')
module.exports = policy