Skip to content

Commit 5f0aeba

Browse files
delsimdelsim
andauthored
Sandbox permissions (#419)
* Update gitignore * Add code generation of sandbox exception list Co-authored-by: delsim <dev@gibbsconsulting.ca>
1 parent 4ac19fe commit 5f0aeba

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,6 @@ TOKENS
105105

106106
# testing
107107
.pytest_cache/
108+
109+
# emacs backup files
110+
**/*~
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div style="{{dstyle}}">
2-
<iframe src="{{app.base_url}}" style="{{istyle}}" frameborder="{{fbs}}" sandbox="allow-downloads allow-scripts allow-same-origin"></iframe>
2+
<iframe src="{{app.base_url}}" style="{{istyle}}" frameborder="{{fbs}}" sandbox="{{sandbox_settings}}"></iframe>
33
</div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div class="embed-responsive embed-responsive-{{aspect}}">
2-
<iframe src="{{app.base_url}}" class="embed-responsive-item" sandbox="allow-downloads allow-scripts allow-same-origin"></iframe>
2+
<iframe src="{{app.base_url}}" class="embed-responsive-item" sandbox="{{sandbox_settings}}"></iframe>
33
</div>

django_plotly_dash/templatetags/plotly_dash.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,25 @@
3131
from django_plotly_dash.models import DashApp
3232
from django_plotly_dash.util import pipe_ws_endpoint_name, store_initial_arguments
3333

34+
3435
register = template.Library()
3536

37+
3638
ws_default_url = "/%s" % pipe_ws_endpoint_name()
3739

40+
41+
SANDBOX_SETTINGS = ["allow-downloads",
42+
"allow-scripts",
43+
"allow-same-origin",
44+
"allow-modals",
45+
"allow-popups",
46+
"allow-popups-to-escape-sandbox",
47+
]
48+
49+
50+
SANDBOX_STRING = " ".join(SANDBOX_SETTINGS)
51+
52+
3853
def _locate_daapp(name, slug, da, cache_id=None):
3954

4055
app = None
@@ -75,8 +90,11 @@ def plotly_app(context, name=None, slug=None, da=None, ratio=0.1, use_frameborde
7590

7691
da, app = _locate_daapp(name, slug, da, cache_id=cache_id)
7792

93+
sandbox_settings = SANDBOX_STRING
94+
7895
return locals()
7996

97+
8098
@register.inclusion_tag("django_plotly_dash/plotly_app_bootstrap.html", takes_context=True)
8199
def plotly_app_bootstrap(context, name=None, slug=None, da=None, aspect="4by3", initial_arguments=None):
82100
'Insert a dash application using a html iframe'
@@ -95,18 +113,23 @@ def plotly_app_bootstrap(context, name=None, slug=None, da=None, aspect="4by3",
95113

96114
da, app = _locate_daapp(name, slug, da, cache_id=cache_id)
97115

116+
sandbox_settings = SANDBOX_STRING
117+
98118
return locals()
99119

120+
100121
@register.simple_tag(takes_context=True)
101122
def plotly_header(context):
102123
'Insert placeholder for django-plotly-dash header content'
103124
return context.request.dpd_content_handler.header_placeholder
104125

126+
105127
@register.simple_tag(takes_context=True)
106128
def plotly_footer(context):
107129
'Insert placeholder for django-plotly-dash footer content'
108130
return context.request.dpd_content_handler.footer_placeholder
109131

132+
110133
@register.inclusion_tag("django_plotly_dash/plotly_direct.html", takes_context=True)
111134
def plotly_direct(context, name=None, slug=None, da=None):
112135
'Direct insertion of a Dash app'
@@ -130,12 +153,14 @@ def plotly_direct(context, name=None, slug=None, da=None):
130153

131154
return locals()
132155

156+
133157
@register.inclusion_tag("django_plotly_dash/plotly_messaging.html", takes_context=True)
134158
def plotly_message_pipe(context, url=None):
135159
'Insert script for providing background websocket connection'
136160
url = url if url else ws_default_url
137161
return locals()
138162

163+
139164
@register.simple_tag()
140165
def plotly_app_identifier(name=None, slug=None, da=None, postfix=None):
141166
'Return a slug-friendly identifier'
@@ -148,6 +173,7 @@ def plotly_app_identifier(name=None, slug=None, da=None, postfix=None):
148173
return "%s-%s" %(slugified_id, postfix)
149174
return slugified_id
150175

176+
151177
@register.simple_tag()
152178
def plotly_class(name=None, slug=None, da=None, prefix=None, postfix=None, template_type=None):
153179
'Return a string of space-separated class names'
@@ -158,6 +184,7 @@ def plotly_class(name=None, slug=None, da=None, prefix=None, postfix=None, templ
158184
postfix=postfix,
159185
template_type=template_type)
160186

187+
161188
@register.simple_tag(takes_context=True)
162189
def site_root_url(context):
163190
'Provide the root url of the demo site'

0 commit comments

Comments
 (0)