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

Whitelist Function("return this") from DANGEROUS_EVAL #4814

Open
Juraj-Masiar opened this issue Apr 21, 2023 · 2 comments
Open

Whitelist Function("return this") from DANGEROUS_EVAL #4814

Juraj-Masiar opened this issue Apr 21, 2023 · 2 comments

Comments

@Juraj-Masiar
Copy link

Juraj-Masiar commented Apr 21, 2023

Describe the problem and steps to reproduce it:

There is a huge bunch of libraries that uses this technique to "do something", although I can't tell for sure what it does:

Function("return this")
// returns global this??? This must be some legacy crap.

Example search of my "node_modules" folder with 44 matches:
image
(and some more that uses single quotes)

What happened?

DANGEROUS_EVAL          The Function constructor is eval.

The problem is that linter marks all these as DANGEROUS_EVAL, which is obviously not true, maybe SAFE_EVAL would be better :).

What did you expect to happen?

It would be nice to whitelist these from the detection.

┆Issue is synchronized with this Jira Task

@Rob--W
Copy link
Member

Rob--W commented Apr 21, 2023

In general the Function constructor with a fixed string is safe.

@Rob--W
Copy link
Member

Rob--W commented Apr 27, 2023

We decided to accept this given the harmlessness of this, along with the prevalence of this pattern.

While a fixed string is safe from the perspective of not offering remote code execution, we are only allowing known-safe strings (e.g. return this) instead of arbitrary strings, because allowing arbitrary strings can make it easier to obfuscate code with string escapes.

Patches are welcome :)

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

No branches or pull requests

3 participants