-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1204 from govuk-one-login/revert-1203-origin/AUT-…
…1706/fix-CSP-issues Revert "AUT-1706: Review and fix CSP issues"
- Loading branch information
Showing
7 changed files
with
40 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,43 @@ | ||
import helmet from "helmet"; | ||
import { Request, Response } from "express"; | ||
import { supportFrameAncestorsFormActionsCspHeaders } from "../config"; | ||
// Helmet does not export the config type - This is the way the recommend getting it on GitHub. | ||
export function helmetConfiguration(): Parameters<typeof helmet>[0] { | ||
const helmetConfig = { | ||
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"], | ||
"frame-ancestors": [""], | ||
"form-action": [""], | ||
}, | ||
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, | ||
}, | ||
expectCt: false, | ||
frameguard: { | ||
action: "deny", | ||
}, | ||
hsts: { | ||
maxAge: 31536000, // 1 Year | ||
preload: true, | ||
includeSubDomains: true, | ||
}, | ||
permittedCrossDomainPolicies: false, | ||
referrerPolicy: false, | ||
}; | ||
if (supportFrameAncestorsFormActionsCspHeaders()) { | ||
helmetConfig.contentSecurityPolicy.directives["frame-ancestors"] = [ | ||
"'self'", | ||
"https://*.account.gov.uk", | ||
]; | ||
helmetConfig.contentSecurityPolicy.directives["form-action"] = [ | ||
"'self'", | ||
"https://*.account.gov.uk", | ||
]; | ||
} | ||
return helmetConfig; | ||
} | ||
}, | ||
dnsPrefetchControl: { | ||
allow: false, | ||
}, | ||
frameguard: { | ||
action: "deny", | ||
}, | ||
hsts: { | ||
maxAge: 31536000, // 1 Year | ||
preload: true, | ||
includeSubDomains: true, | ||
}, | ||
referrerPolicy: false, | ||
permittedCrossDomainPolicies: false, | ||
expectCt: false, | ||
}; |