Content Security Policy: Uncaught EvalError
See original GitHub issueUncaught EvalError: Refused to evaluate a string as JavaScript because ‘unsafe-eval’ is not an allowed source of script in the following Content Security Policy directive: “script-src ‘self’ blob: filesystem:”.
I’m using EJS to render templates in a Browser Extension and the use of new Function("return this;")
is throwing a CSP error. I’m building from the npm package, but looked into the client side distribution and noticed the same eval occurs there as well. (https://github.com/mde/ejs/blob/v2.6.2/lib/ejs.js#L106)
Here’s an example of a fix that works in the browser extension context. I’d be happy to open a PR and validate the fix in the context if it’s an acceptable change.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:9 (1 by maintainers)
Top Results From Across the Web
"Uncaught EvalError: Refused to evaluate a string as ...
The error you're seeing is related to the Content Security Policy that's set in the headers of your site. Among other things, default-src...
Read more >Chrome: default-src eval: Refused to evaluate a string as ...
Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security...
Read more >ERROR EvalError: Content Security Policy - EJ 2 Forums
ERROR EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content ...
Read more >Working with strict Content Security Policies - Unpoly
For example, the following callback would crash the fragment update with an error like Uncaught EvalError: call to Function() blocked by CSP :...
Read more >Customizer requires a relaxed CSP with 'unsafe-eval' specified
If you're using Content Security Policy headers, 'unsafe-eval' have to be ... Uncaught EvalError: Refused to evaluate a string as JavaScript because ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m still running into the same issue… Is there any update?
That won’t work in this case, because EJS works by transpiling the
.ejs
file into a JavaScript function at runtime.