-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
content_security_policy - EvalError: Refused to evaluate a string #4535
Comments
I don't know the root cause, but we introduced it in 12db9db after I tracked it via |
This issue keeps us for a while from updating to any version of Mocha newer than 8.1.3, and I assume that applies to everyone who uses Mocha to test a browser extension. Right now, we could as a workaround relax the |
@snoack what about a PR from your side? |
Hello. So, this issue was investigated with an eye on seeing how to help out or at least get some direction. Like @outsideris mentioned, a It seems like that block of code gets indirectly introduced by Relevant to this discussion is also this post which seems to very closely mirror this exact issue we're experiencing. @boneskull Sorry for the random ping but would you perhaps be able to add some insight into this? Thank you so much! |
As @goatonabicycle concluded above, the offender here is If it's acceptable to drop support for Internet Explorer 11 (which is the only browser listed in diff --git a/rollup.config.js b/rollup.config.js
index 4b4f3494..5fae0247 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -43,5 +43,6 @@ const config = {
version: 3,
proposals: false
- }
+ },
+ exclude: ["transform-regenerator"]
}
] Note that @juergba, what do you think? |
@goatonabicycle @snoack thanks for your support. I'm willing to solve this issue, but you have to take the lead. Unfortunately we haven't dropped the support of IE11. But we started using modern Javascript and transpiling since Mocha v8.1.0.
I'm afraid no.
This commit landed in v8.2.0, and would explain why v8.1.3 is still working. Do you have any other suggestions, please? @outsideris ? |
The obvious solution if supporting Internet Explorer is a requirement would be to refactor the code to again not use Or if you prefer to keep using |
No, no way! facebook still breaking things:
This PR states, that v8.1.3 is working, above link says v8.1.0 isn't working. I'm starting to doubt that the root cause is the use of This |
Indeed, this doesn't quite match up. But I just double checked, and this regression was introduced in 8.2.0. 8.1.0 and 8.1.3 work fine and don't include the offending code from
If in doubt just remove any
Babel, or rather |
We all are sick of IE11, but decided to keep supporting it.
|
@snoack - First, thanks for pinging me - that blog post morphed a couple times as I worked through the problems - sorry for the confusion. Clarifications in a nutshell:
Let me know if you need more info or further clarification. |
There seems to be another option. If we update try {
regeneratorRuntime = runtime;
} catch (accidentalStrictMode) {
// This module should not be running in strict mode, so the above
// assignment should always work unless something is misconfigured. Just
// in case runtime.js accidentally runs in strict mode, we can escape
// strict mode using a global Function call. This could conceivably fail
// if a Content Security Policy forbids using Function, but in that case
// the proper solution is to fix the accidental strict mode problem. If
// you've misconfigured your bundler to force strict mode and applied a
// CSP to forbid Function, and you're not willing to fix either of those
// problems, please detail your unique predicament in a GitHub issue.
Function("r", "regeneratorRuntime = r")(runtime);
} This will still fail in strict mode without unsafe eval. But now we can just add This will give us a bundle that will work both on Internet Explorer 11, and in environments that don't allow unsafe eval. |
Above statement of @dfkaye is worrying me. Are we hunting ghosts?
The bundled file is part of Mocha's npm package. |
Mocha 8.3.0 does not work without unsafe eval. Feel free to see for yourself. Here is a simple test case. Just put this code into an HTML file and open it in Chrome or Firefox: <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="script-src https: 'unsafe-inline'">
<link rel="stylesheet" href="https://unpkg.com/mocha@8.3.0/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="https://unpkg.com/mocha@8.3.0/mocha.js"></script>
<script>
mocha.setup('bdd');
it('works', () => {});
mocha.run();
</script>
</body>
</html> You will see a blank page, and find an |
Is there an ETA for a release with this fix? |
This weekend, probably. |
The problem: I've had to add the following line to a chrome extension manifest file in order for the latest version of Mocha to work:
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self';",
Without this line, mocha scripts fails to run with the following error:
The mentioned workaround was found here: https://stackoverflow.com/a/48047578 but ideally we don't want to meddle with the content_security_policy
The error seems related to the following piece of code in
mocha.js
:This looks like a regression in the newer versions of Mocha as this issue doesn't occur after downgrading to Mocha 8.1.3 .
What I've tried:
Experimented with different
devtool
settings including"cheap-module-source-map"
andfalse
How I'm running Mocha: Slightly differently because of testing a chrome extension with a specific page. But the core idea works in other projects and shouldn't be related to the described error.
How I'm working around this at the moment: Downgraded to Mocha 8.1.3
The text was updated successfully, but these errors were encountered: