Permalink
Browse files

minor improvements for #2608

  • Loading branch information...
pi0 committed Jan 16, 2018
1 parent 5ebf60f commit 95c85bba62d5fbc4a9128cb19e01b9ad85a76e74
Showing with 11 additions and 7 deletions.
  1. +3 −1 lib/common/options.js
  2. +4 −3 lib/core/middleware/nuxt.js
  3. +4 −3 lib/core/renderer.js
View
@@ -306,7 +306,9 @@ Options.defaults = {
weak: false
},
csp: {
allowedSouces: []
enabled: false,
hashAlgorithm: 'sha256',
allowedSources: []
}
},
watchers: {
@@ -67,11 +67,12 @@ module.exports = async function nuxtMiddleware(req, res, next) {
res.setHeader('Link', pushAssets.join(','))
}
if (this.options.render.csp.hashAlgorithm) {
let allowedSources = cspScriptSrcHashes.concat(this.options.render.csp.allowedSources)
if (this.options.render.csp && this.options.render.csp.enabled) {
const allowedSources = cspScriptSrcHashes.concat(this.options.render.csp.allowedSources)
res.setHeader(
'Content-Security-Policy',
`script-src 'self' ${(allowedSources || []).join(' ')}`
`script-src 'self' ${(allowedSources).join(' ')}`
)
}
View
@@ -357,11 +357,12 @@ module.exports = class Renderer {
HEAD += context.renderResourceHints()
}
let serializedSession = `window.__NUXT__=${serialize(context.nuxt, {
const serializedSession = `window.__NUXT__=${serialize(context.nuxt, {
isJSON: true
})};`
let cspScriptSrcHashes = []
if (this.options.render.csp.hashAlgorithm) {
const cspScriptSrcHashes = []
if (this.options.render.csp && this.options.render.csp.enabled) {
let hash = crypto.createHash(this.options.render.csp.hashAlgorithm)
hash.update(serializedSession)
cspScriptSrcHashes.push(

0 comments on commit 95c85bb

Please sign in to comment.