question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content Security Policy: Uncaught EvalError

See original GitHub issue

Uncaught 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
morasumucommented, Aug 15, 2022

I’m still running into the same issue… Is there any update?

2reactions
ExE-Bosscommented, Oct 30, 2019

That won’t work in this case, because EJS works by transpiling the .ejs file into a JavaScript function at runtime.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found