I'm using this method to detect CSP with eval
(also used in AngularJS):
function noUnsafeEval() {
try {
new Function('');
return false;
} catch (err) {
return true;
}
}
But I don't have a server with CSP at hand to thoroughly test it.
Is it reliable? Can the presence of new Function('')
line in code cause the error that cannot be caught?
What is err
? Which kind of error is caught there (Error
, TypeError
, etc)? What does the message of CSP error say?
I couldn't find the documentation on runtime errors in CSP.