-
Notifications
You must be signed in to change notification settings - Fork 34
/
withCsp.ts
47 lines (42 loc) · 1.47 KB
/
withCsp.ts
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
import { withSecureHeaders } from 'next-secure-headers';
import getConfig from 'next/config';
import { FC } from 'react';
import { CustomAppProps } from 'types';
const { serverRuntimeConfig } = getConfig();
const { cspTrustedHosts, cspReportOnly, cspReportUri } = serverRuntimeConfig;
const trustedHosts = cspTrustedHosts
? cspTrustedHosts.split(',')
: ['https://*.lido.fi'];
const reportOnly = cspReportOnly === 'true';
export const contentSecurityPolicy = {
directives: {
styleSrc: ["'self'", 'https://fonts.googleapis.com', "'unsafe-inline'"],
fontSrc: ["'self'", 'https://fonts.gstatic.com', ...trustedHosts],
imgSrc: ["'self'", 'data:', ...trustedHosts],
scriptSrc: ["'self'", "'unsafe-eval'", "'unsafe-inline'", ...trustedHosts],
connectSrc: [
"'self'",
'wss://*.walletconnect.org',
'https://*.walletconnect.org',
...trustedHosts,
],
prefetchSrc: ["'self'", ...trustedHosts],
formAction: ["'self'", ...trustedHosts],
frameAncestors: ['*'],
manifestSrc: ["'self'", ...trustedHosts],
mediaSrc: ["'self'", ...trustedHosts],
childSrc: ["'self'", ...trustedHosts],
objectSrc: ["'self'", ...trustedHosts],
defaultSrc: ["'self'", ...trustedHosts],
baseUri: ["'none'"],
reportURI: cspReportUri,
},
reportOnly: reportOnly,
};
export const withCsp = (
app: ({ config, ...appProps }: CustomAppProps) => JSX.Element,
): FC =>
withSecureHeaders({
contentSecurityPolicy,
frameGuard: false,
})(app);