/
helmet.ts
42 lines (42 loc) · 1.24 KB
/
helmet.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
import helmet from "helmet";
import { Request, Response } from "express";
// Helmet does not export the config type - This is the way the recommend getting it on GitHub.
export const helmetConfiguration: Parameters<typeof helmet>[0] = {
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],
styleSrc: ["'self'"],
scriptSrc: [
"'self'",
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
(req: Request, res: Response): string =>
`'nonce-${res.locals.scriptNonce}'`,
"'sha256-+6WnXIl4mbFTCARd8N3COQmT3bJJmo32N8q8ZSQAIcU='",
"https://www.googletagmanager.com",
"https://www.google-analytics.com",
"https://ssl.google-analytics.com",
],
imgSrc: [
"'self'",
"data:",
"https://www.googletagmanager.com",
"https://www.google-analytics.com",
],
objectSrc: ["'none'"],
connectSrc: ["'self'", "https://www.google-analytics.com"],
},
},
dnsPrefetchControl: {
allow: false,
},
frameguard: {
action: "deny",
},
hsts: {
maxAge: 31536000, // 1 Year
preload: true,
includeSubDomains: true,
},
referrerPolicy: false,
permittedCrossDomainPolicies: false,
};