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

unsafe-eval in generated javascript code #5464

Closed
zlk89 opened this issue Dec 13, 2018 · 3 comments
Closed

unsafe-eval in generated javascript code #5464

zlk89 opened this issue Dec 13, 2018 · 3 comments
Assignees

Comments

@zlk89
Copy link

zlk89 commented Dec 13, 2018

What version of protobuf and what language are you using?
Version: v3.6.1
Language: Javascript

What operating system (Linux, Windows, ...) and version?
Mac OS 10.12.6

What runtime / compiler are you using (e.g., python version or gcc version)
Use the v3.6.1 compiled binary file protoc to compile

What did you do?
Steps to reproduce the behavior:

  1. Compile proto file into js using command like this: protoc --js_out=import_style=commonjs,binary:output_dir schema.proto
  2. You will find a line in generated javascript code:
    var global = Function('return this')();
    which is an unsafe eval that triggers error on user browser, if csp header doesn't whitelist unsafe-eval

What did you expect to see
Generated code shouldn't use any unsafe eval.
It can be replaced by something like
var global = (typeof self == "undefined" ? typeof global == "undefined"? this : global : self);

What did you see instead?
Seeing an unnecessary unsafe eval.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).

Anything else we should know about your project / environment

@TeBoring TeBoring self-assigned this Dec 17, 2018
@felixfbecker
Copy link

felixfbecker commented Dec 19, 2018

This prevents using Protobuf and in turn https://github.com/lightstep/lightstep-tracer-javascript from being used in Chrome/Firefox extensions which disallow eval().

@rhanesoghlyan
Copy link

I have the same problem. Any news ?

@dlj-NaN
Copy link
Contributor

dlj-NaN commented Dec 8, 2020

I'm going to call this issue a duplicate of protocolbuffers/protobuf-javascript#25. Even though this issue is older, I think the newer issue has a bit more background to start collecting further discussion.

Thanks for filing this issue! And please do feel free to chime in on protocolbuffers/protobuf-javascript#25 if you would like.

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

5 participants