Skip to content
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

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive #258

Open
nop33 opened this issue Jul 16, 2024 · 1 comment

Comments

@nop33
Copy link

nop33 commented Jul 16, 2024

Seems like when using this library in a browser environment where the CSP does not allow for 'unsafe-eval' it doesn't work.

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' 'unsafe-inline'".

We discovered that the source of the problem are these lines of binary-parser:

compile() {
const importPath = "imports";
const ctx = this.getContext(importPath);
this.compiled = new Function(
importPath,
"TextDecoder",
`return function (buffer, constructorFn) { ${ctx.code} };`,
)(ctx.imports, TextDecoder);
}

@keichi
Copy link
Owner

keichi commented Jul 17, 2024

Thanks for pointing this out. Using Function()/eval() was an early design choice to optimize for performance. We currently do not have plans to remove this limitation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants