Skip to content

Commit

Permalink
refactor(csp): remove unsafe-eval in dev mode (#7659)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Jul 2, 2020
1 parent d4363d4 commit 0342451
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/server/src/middleware/nuxt.js
Expand Up @@ -74,7 +74,7 @@ export default ({ options, nuxt, renderRoute, resources }) => async function nux
const isReportOnly = !!options.render.csp.reportOnly
const cspHeader = isReportOnly ? 'Content-Security-Policy-Report-Only' : 'Content-Security-Policy'

res.setHeader(cspHeader, getCspString({ cspScriptSrcHashes, allowedSources, policies, isDev: options.dev, isReportOnly }))
res.setHeader(cspHeader, getCspString({ cspScriptSrcHashes, allowedSources, policies, isReportOnly }))
}

// Send response
Expand Down Expand Up @@ -126,9 +126,9 @@ const defaultPushAssets = (preloadFiles, shouldPush, publicPath, options) => {
return links
}

const getCspString = ({ cspScriptSrcHashes, allowedSources, policies, isDev, isReportOnly }) => {
const getCspString = ({ cspScriptSrcHashes, allowedSources, policies, isReportOnly }) => {
const joinedHashes = cspScriptSrcHashes.join(' ')
const baseCspStr = `script-src 'self'${isDev ? ' \'unsafe-eval\'' : ''} ${joinedHashes}`
const baseCspStr = `script-src 'self' ${joinedHashes}`
const policyObjectAvailable = typeof policies === 'object' && policies !== null && !Array.isArray(policies)

if (Array.isArray(allowedSources) && allowedSources.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/middleware/nuxt.test.js
Expand Up @@ -265,7 +265,7 @@ describe('server: nuxtMiddleware', () => {
expect(res.setHeader).nthCalledWith(
1,
'Content-Security-Policy-Report-Only',
"script-src 'self' 'unsafe-eval' sha256-hashes /nuxt/*.js /nuxt/images/*"
"script-src 'self' sha256-hashes /nuxt/*.js /nuxt/images/*"
)
})

Expand Down

0 comments on commit 0342451

Please sign in to comment.