Skip to content

Commit df9663b

Browse files
committed
detect CSP violations with proper warning
1 parent 27a6f02 commit df9663b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/parsers/expression.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const pathTestRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['.*?'\]|\[".*?"\]|\
2929
const identRE = /[^\w$\.](?:[A-Za-z_$][\w$]*)/g
3030
const booleanLiteralRE = /^(?:true|false)$/
3131

32+
function noop () {}
33+
3234
/**
3335
* Save / Rewrite / Restore
3436
*
@@ -140,10 +142,23 @@ function makeGetterFn (body) {
140142
return new Function('scope', 'return ' + body + ';')
141143
/* eslint-enable no-new-func */
142144
} catch (e) {
143-
process.env.NODE_ENV !== 'production' && warn(
144-
'Invalid expression. ' +
145-
'Generated function body: ' + body
146-
)
145+
if (process.env.NODE_ENV !== 'production') {
146+
/* istanbul ignore if */
147+
if (e.toString().match(/unsafe-eval/)) {
148+
warn(
149+
'It seems you are using the default build of Vue.js in an environment ' +
150+
'with Content Security Policy that prohibits unsafe-eval. ' +
151+
'Use the CSP-compliant build instead: ' +
152+
'http://vuejs.org/guide/installation.html#CSP-compliant-build'
153+
)
154+
} else {
155+
warn(
156+
'Invalid expression. ' +
157+
'Generated function body: ' + body
158+
)
159+
}
160+
}
161+
return noop
147162
}
148163
}
149164

0 commit comments

Comments
 (0)