Merge pull request #761 from SISheogorath/feature/reportURI

Add config option for report URI in CSP
This commit is contained in:
Christoph (Sheogorath) Kern
2018-03-14 22:10:23 +01:00
committed by GitHub
4 changed files with 12 additions and 2 deletions

View File

@@ -18,7 +18,8 @@ module.exports = {
directives: {
},
addDefaults: true,
upgradeInsecureRequests: 'auto'
upgradeInsecureRequests: 'auto',
reportURI: undefined
},
protocolusessl: false,
usecdn: true,

View File

@@ -15,7 +15,8 @@ module.exports = {
preload: toBooleanConfig(process.env.HMD_HSTS_PRELOAD)
},
csp: {
enable: toBooleanConfig(process.env.HMD_CSP_ENABLE)
enable: toBooleanConfig(process.env.HMD_CSP_ENABLE),
reportURI: process.env.HMD_CSP_REPORTURI
},
protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
alloworigin: toArrayConfig(process.env.HMD_ALLOW_ORIGIN),

View File

@@ -30,6 +30,7 @@ CspStrategy.computeDirectives = function () {
addInlineScriptExceptions(directives)
}
addUpgradeUnsafeRequestsOptionTo(directives)
addReportURI(directives)
return directives
}
@@ -72,6 +73,12 @@ function addUpgradeUnsafeRequestsOptionTo (directives) {
}
}
function addReportURI (directives) {
if (config.csp.reportURI) {
directives.reportUri = config.csp.reportURI
}
}
CspStrategy.addNonceToLocals = function (req, res, next) {
res.locals.nonce = uuid.v4()
next()