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

Cannot be used in Chrome/Firefox extensions because bundle contains eval() #141

Closed
felixfbecker opened this issue Dec 19, 2018 · 6 comments · Fixed by #197
Closed

Cannot be used in Chrome/Firefox extensions because bundle contains eval() #141

felixfbecker opened this issue Dec 19, 2018 · 6 comments · Fixed by #197

Comments

@felixfbecker
Copy link
Contributor

When trying to use this library in a browser extension (Chrome or Firefox) the extension will throw with

Error: 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:".

Chrome and Firefox do not allow eval( in extensions because it is a security risk.

This seems to be related to some Google library bundled (I assume for Proto support?), search https://github.com/lightstep/lightstep-tracer-javascript/blob/master/dist/lightstep-tracer.js for eval(.

@felixfbecker
Copy link
Contributor Author

Related: protocolbuffers/protobuf#5464

Ideally though I should be able to use this library through plain HTTP.

felixfbecker added a commit to sourcegraph/lightstep-tracer-javascript that referenced this issue Dec 19, 2018
Google Protobufs use eval() so cannot run in browser extensions lightstep#141
The transport was not used by default and bloated the bundle size.
@iredelmeier
Copy link
Contributor

Interesting, and thanks for hunting down the upstream problem! I'll investigating some other options for compilation, e.g., protobuf.js.

When you say "plain HTTP", do you mean json over HTTP?

@felixfbecker
Copy link
Contributor Author

What I mean is that as a consumer of Lightstep, I don't really care how the data is transported. I just care that it works (including in extensions and webworkers) and doesn't bloat my bundle. Maybe there is one, but I don't understand the need for neither Thrift nor Protobuf libraries, and would at least like to avoid having both in my bundle, especially if they cause issues like this.

iredelmeier added a commit that referenced this issue Dec 21, 2018
@iredelmeier
Copy link
Contributor

Thanks for the explanation! I completely agree, and we're moving in the direction of no longer requiring code for unused transports.

@JulesPatry
Copy link

JulesPatry commented Apr 23, 2021

This is a rather old issue, but today I'm facing the same issue because our CSP does not allow the use of eval.

The protobuf library (a dependency on lightstep-tracer-javascript), does not package their code with commonjs_strict which then polutes the build with javascript code using eval. protocolbuffers/protobuf-javascript#25

Could lightstep-tracer-javascript work without this protobuff library?

@JulesPatry
Copy link

For anyone also experiencing a problem with using eval try using this branch in your package json
https://github.com/lightstep/lightstep-tracer-javascript/tree/v0.30.2-no-protobuf

Simply add "lightstep-tracer": "v0.30.2-no-protobuf", in your package.json and eval errors will not show up

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