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

Browser bundle includes an eval pattern, triggering some static analysis #3559

Open
dimovpetar opened this issue Aug 12, 2021 · 3 comments
Open
Labels

Comments

@dimovpetar
Copy link

dimovpetar commented Aug 12, 2021

Hello,

There are some usages of Function in the lodash package, which requires unsafe-eval to be used. In the built version https://github.com/jshint/jshint/blob/master/dist/jshint.js you can find Function('return this')(); and Function(importsKeys, sourceURL + 'return ' + source). The second one is not used at all.
This makes usage of JSHint impossible in restricted environments, where only script-src: self is set. Any chance to remove them?
More information about Unsafe eval expessions.

@jugglinmike
Copy link
Member

Thanks for taking the time to file an issue! Lodash is expected to load "just fine" in a CSP-restricted environment. Judging from that library's source code, it seems as though an error will only be encountered if the binding named self is not defined globally. Is that the case for you?

@dimovpetar
Copy link
Author

Hello! The problem is that scan tools report such usages, even if not used. The issue you have referenced is from 2014, and back then this code wasn't part of root.js. I've found that this is already addressed with lodash/lodash#4985 and globalThis is suggested.
For the other occurence of eval, which is in lodash.template - since you are not using this function, is it possible to prune it from your bundle? It will also decrease the total size.

@jugglinmike jugglinmike changed the title CSP 'script-src' directive is violated Browser bundle includes an eval pattern, triggering some static analysis Aug 29, 2021
@jugglinmike
Copy link
Member

Got it. I've updated the title of this issue since there aren't any known Content-Security Policy violations.

A sufficiently advanced build process would likely infer that JSHint doesn't use the offending code and omit it from the final product. Unfortunately, this project's build system is not up to the task right now. I'll gladly review patches to modernize it!

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

No branches or pull requests

2 participants