-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Security warning: avoid using function constructor. #897
Comments
I think this is the line: https://github.com/scijs/cwise-compiler/blob/master/lib/compile.js#L351 cwise is a library that performs operations on ndarrays. It doesn't look like plotly uses the cwise browserify transform when bundling plotly.js, but I believe even the transformed version that does the parsing ahead of time still compiles an optimized version (i.e. Long story short, this is pretty central to what cwise does, so I'm not totally sure of a good workaround, unless there's a way to short-circuit the optimization and just perform naive operations on data. Edit: more precisely, this looks like it might be coming from ndarray-ops, which is already transformed, but the problem remains the same. Looks like it's coming from here. That wouldn't be too hard to rewrite naively, but I'd be surprised if cwise didn't creep in somewhere else in the dependencies. |
The plotly build step doesn't explicitly list the |
I'm also running into this problem. Can't run my (Meteor) app because of this. |
When I tried to bring plotly.js into my Electron application (via ember-plotly-shim) it triggers a security warning. In fact, since I have a set a Content-Security-Policy per the recommendations, it does not run at all. Would someone be willing to write some / point to some documentation that describes how to incorporate plotly w/o using a pipeline that evaluates strings as code? |
Still seeing this as well. Hasn't been addressed at all. |
Nothing has changed since #897 (comment), so yes this hasn't been addressed at all 😱 The problematic |
Thanks for the advice! I'll take a look at that. |
Does anyone have the CSP header they've used to keep security as tight as possible but still use plotly? |
I recommend starting with the strictest options and gradually relaxing restrictions until your application functions properly. There may be other parts of your work that won't work when fully restricted. As an example only, here is one I have used (inside of an electron app): See MDN |
Looks like the direct Does anyone know if it is feasible for The |
@anders-kiaer you may be interested in https://www.npmjs.com/package/plotly.js-gl2d-dist, you can install it using
which has no dependencies. |
Thanks @etpinard 🙂 Hmm, not sure if I understand, isn't the import dash
import dash_html_components as html
from flask_talisman import Talisman
app = dash.Dash(
__name__, external_scripts=["https://cdn.plot.ly/plotly-gl2d-latest.min.js"]
)
CSP = {
"default-src": "'self'",
"script-src": [
"'self'",
"https://cdn.plot.ly",
# "'unsafe-eval'",
"'sha256-jZlsGVOhUAIcH+4PVs7QuGZkthRMgvT2n0ilH6/zTM0='",
],
"style-src": ["'self'", "'unsafe-inline'"],
}
Talisman(app.server, content_security_policy=CSP, force_https=False)
app.layout = html.Span("Hello Dash!")
if __name__ == "__main__":
app.run_server() which when looking at the browser console gives a
unless |
My mistake. I thought you were worried about the "unsafe-eval" behavior of Unfortunately, there's no easy way for us to simply replace |
But, the That is, bundles that include trace types other than |
FWIW I don't think it would be unreasonable to explore making an eval-free version of |
From v1.48.3 to v1.52.2 and downgrade from full to basic (to avoid plotly/plotly.js#897)
The current version 1.52.2 (https://raw.githubusercontent.com/plotly/plotly.js/v1.52.2/dist/plotly.js) uses
|
* Update plotly-min.js From v1.48.3 to v1.52.2 and downgrade from full to basic (to avoid plotly/plotly.js#897) * Add "img-src blob:" is for Plotly download feature and comments
@anders-kiaer this is done in #4929 and #4930 and available in plotly.js >= v1.54.4 |
🎉 The v2.5.0 release removed calls to function constructor from various dependencies of It is now possible to apply CSP directives e.g.
stackgl-based traces using "strict" or "gl3d" bundles.
|
Addressed by various PRs. Now one could use the strict bundles e.g. https://www.npmjs.com/package/plotly.js-strict-dist-min |
* Update plotly-min.js From v1.48.3 to v1.52.2 and downgrade from full to basic (to avoid plotly/plotly.js#897) * Add "img-src blob:" is for Plotly download feature and comments
I 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:
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 ?
The text was updated successfully, but these errors were encountered: