Dash is a CSP friendly framework, enabling writing XSS safe applications, however this had a setback in #367.
With pip install 'dash==0.38.0' dash_html_components flask-talisman you could test quite strict CSP settings in Dash locally with success:
importdashimportdash_html_componentsashtmlfromflask_talismanimportTalismanapp=dash.Dash(__name__)
app.css.config.serve_locally=Trueapp.scripts.config.serve_locally=Truecsp= {
'default-src': '\'self\'',
'script-src': '\'self\'',
'style-src': '\'self\''
}
Talisman(app.server, content_security_policy=csp, force_https=False)
app.layout=html.Div(children=['Hello Dash!'])
if__name__=='__main__':
app.run_server()With dash==0.39.0 however this fails due to the new inline script
| self.renderer='var renderer = new DashRenderer();' |
A work-around could be to add hash of the current Dash generated inline script (sha256-jZlsGVOhUAIcH+4PVs7QuGZkthRMgvT2n0ilH6/zTM0=) to the server CSP script src headers, however that would be in need of update when the dash renderer string/configuration changes.
Not sure if it is feasible/fits the overall framework/plans, but could one suggestion be to follow the same concept as when the user e.g. wants to override the default favicon.ico (i.e. a file favicon.ico is placed in the assets folder - here in this case it could be e.g. a file dash-renderer-config.js). In addition to following the same concept in terms of overriding default assets and continue not having inline scripts in Dash core, it perhaps also better facilitates separation of Python- and JavaScript code.
Dash is a CSP friendly framework, enabling writing XSS safe applications, however this had a setback in #367.
With
pip install 'dash==0.38.0' dash_html_components flask-talismanyou could test quite strict CSP settings in Dash locally with success:With
dash==0.39.0however this fails due to the new inline scriptdash/dash/dash.py
Line 174 in 0554546
A work-around could be to add hash of the current Dash generated inline script (
sha256-jZlsGVOhUAIcH+4PVs7QuGZkthRMgvT2n0ilH6/zTM0=) to the server CSP script src headers, however that would be in need of update when the dash renderer string/configuration changes.Not sure if it is feasible/fits the overall framework/plans, but could one suggestion be to follow the same concept as when the user e.g. wants to override the default
favicon.ico(i.e. a filefavicon.icois placed in theassetsfolder - here in this case it could be e.g. a filedash-renderer-config.js). In addition to following the same concept in terms of overriding default assets and continue not having inline scripts in Dash core, it perhaps also better facilitates separation of Python- and JavaScript code.