Security warning: avoid using function constructor.
See original GitHub issueI recently discovered that one of plotly.js’s dependency is using Function
constructor.
Unfortunately, I can’t tell exactly which one, but the code doesn’t seems to belong to plotly itself.
Here is Chrome’s error message:
plotly.js:74222Uncaught 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'
www.google-analytics.com ajax.googleapis.com 'nonce-67df8dace6ea7feb57cab73e41ebe0c7'".
makeOp @ plotly.js:74222
(anonymous function) @ plotly.js:74244
455.cwise-compiler @ plotly.js:74271
s @ plotly.js:7
(anonymous function) @ plotly.js:7
129.ndarray @ plotly.js:25687
s @ plotly.js:7
(anonymous function) @ plotly.js:7
138../lib/shaders @ plotly.js:27330
s @ plotly.js:7
(anonymous function) @ plotly.js:7
798.../../constants/gl3d_dashes @ plotly.js:127609
s @ plotly.js:7
(anonymous function) @ plotly.js:7
800.../../constants/gl_markers @ plotly.js:128154
s @ plotly.js:7
(anonymous function) @ plotly.js:7
15.../src/traces/scatter3d @ plotly.js:355
s @ plotly.js:7
(anonymous function) @ plotly.js:7
12../bar @ plotly.js:312
s @ plotly.js:7
e @ plotly.js:7
(anonymous function) @ plotly.js:7
a @ plotly.js:7
(anonymous function) @ plotly.js:7
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ svg-to-png.js:2
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ commons.js:36658
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ index.js:1
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ bootstrap.js:9
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ index.js:3
__webpack_require__ @ bootstrap 08e5224…:585
fn @ bootstrap 08e5224…:109
(anonymous function) @ index.js:8
__webpack_require__ @ bootstrap 08e5224…:585
webpackJsonpCallback @ bootstrap 08e5224…:21
(anonymous function) @ index.js:1
Function constructor is considered by browser’s CSP as an equivalent of eval
.
Therefore, we can’t setup a good Content Security Policy, unless we allow 'unsafe-eval'
which is a whole in the policy itself.
It is possible to identify the faulty dependency, and maybe provide a workaround ?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:34 (20 by maintainers)
Top Results From Across the Web
JavaScript - Avoid use of Function Constructors
JavaScript - Avoid use of Function Constructors ... your program to random, unintended code which can be both slow and a security risk....
Read more >Function constructors should not be used - SonarSource Rules
In addition to being obtuse from a syntax perspective, function constructors are also dangerous: their execution evaluates the constructor's string arguments ...
Read more >Security considerations using "new Function(...)" (during ...
I avoid eval() whenever possible. But I'm not sure if it's secure enough to use new Function(...) which is also known as being...
Read more >no-new-func - ESLint - Pluggable JavaScript Linter
This error is raised to highlight the use of a bad practice. By passing a string to the Function constructor, you are requiring...
Read more >Function() constructor - JavaScript - MDN Web Docs
Calling the constructor directly can create functions dynamically, but suffers from security and similar (but far less significant) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
An update: thanks to generous sponsorship from Equinor, we have been able to make substantial progress on this issue! I’ve just posted the pre-release announcement for Plotly.js 2.0, which will include the following changes related to this issue:
basic
,cartesian
,finance
,geo
, andmapbox
.strict
will be supported from now on, and it contains the maximal subset of the library which is function-constructor-free (see link for list of trace types).strict
bundle will eventually grow to include the entire library, and such that we can eventually add thegl2d
andgl3d
partial bundles to the list of function-constructor-free bundles.strict
bundle that doesn’t happen to match what’s inbasic
,cartesian
,finance
,geo
, ormapbox
.Great news: Equinor is generously willing to sponsor $15k of this work if we can find sponsors for the rest! Please let us know if you’re able to contribute part of the remaining $30k-$35k and we can get started on this project 😃