File tree Expand file tree Collapse file tree 4 files changed +24
-32
lines changed
nbconvert/exporters/tests
share/jupyter/nbconvert/templates Expand file tree Collapse file tree 4 files changed +24
-32
lines changed Original file line number Diff line number Diff line change 159159 {
160160 "cell_type" : " code" ,
161161 "execution_count" : null ,
162- "id" : " d72e635a " ,
162+ "id" : " ae4f574d " ,
163163 "metadata" : {},
164164 "outputs" : [
165165 {
174174 }
175175 ],
176176 "source" : [" " ]
177+ },
178+ {
179+ "cell_type" : " code" ,
180+ "execution_count" : null ,
181+ "id" : " w72e635a" ,
182+ "metadata" : {},
183+ "outputs" : [
184+ {
185+ "output_type" : " execute_result" ,
186+ "data" : {
187+ "application/vnd.jupyter.widget-view+json" : {"model_id" : " wid1" , "foo" : " \" </script><script>alert('output.data.application/vnd.jupyter.widget-view+json injection')//" }
188+ },
189+ "execution_count" : null ,
190+ "metadata" : {}
191+ }
192+ ],
193+ "source" : [" " ]
177194 }
178195 ],
179196 "metadata" : {
196213 "version" : " 3.10.5"
197214 },
198215 "widgets" : {
199- "application/vnd.jupyter.widget-state+json" : {"state" : " {} " , "foo" : " pwntester</script><script>alert('widgets');//" }
216+ "application/vnd.jupyter.widget-state+json" : {"state" : { "wid1" : {}} , "foo" : " pwntester</script><script>alert('widgets');//" }
200217 }
201218 },
202219 "nbformat" : 4 ,
Original file line number Diff line number Diff line change @@ -167,3 +167,6 @@ def test_javascript_injection(self):
167167 # Check injection in image width/height
168168 assert "<script>alert('output.metadata.width png injection')</script>" not in output
169169 assert "<script>alert('output.metadata.height png injection')</script>" not in output
170+
171+ # Check injection in widget view
172+ assert "<script>alert('output.data.application/vnd.jupyter.widget-view+json injection')" not in output
Original file line number Diff line number Diff line change @@ -241,20 +241,6 @@ var element = $('#{{ div_id }}');
241241</div >
242242{% - endblock -%}
243243
244- {% - block data_widget_state scoped %}
245- {% set div_id = uuid 4() %}
246- {% set datatype_list = output .data | filter_data_type %}
247- {% set datatype = datatype_list [0]%}
248- <div id =" {{ div_id }}" class =" output_subarea output_widget_state {{ extra_class }}" >
249- <script type =" text/javascript" >
250- var element = $ (' #{{ div_id }}' );
251- </script >
252- <script type =" {{ datatype }}" >
253- {{ output .data [datatype] | json_dumps }}
254- </script >
255- </div >
256- {% - endblock data_widget_state -%}
257-
258244{% - block data_widget_view scoped %}
259245{% set div_id = uuid 4() %}
260246{% set datatype_list = output .data | filter_data_type %}
@@ -264,7 +250,7 @@ var element = $('#{{ div_id }}');
264250var element = $ (' #{{ div_id }}' );
265251 </script >
266252<script type =" {{ datatype }}" >
267- {{ output .data [datatype] | json_dumps }}
253+ {{ output .data [datatype] | json_dumps | escape_html }}
268254 </script >
269255</div >
270256{% - endblock data_widget_view -%}
Original file line number Diff line number Diff line change @@ -273,20 +273,6 @@ var element = document.getElementById('{{ div_id }}');
273273</div >
274274{% - endblock -%}
275275
276- {% - block data_widget_state scoped %}
277- {% set div_id = uuid 4() %}
278- {% set datatype_list = output .data | filter_data_type %}
279- {% set datatype = datatype_list [0]%}
280- <div id =" {{ div_id }}" class =" output_subarea output_widget_state {{ extra_class }}" >
281- <script type =" text/javascript" >
282- var element = document .getElementById (' {{ div_id }}' );
283- </script >
284- <script type =" {{ datatype }}" >
285- {{ output .data [datatype] | json_dumps }}
286- </script >
287- </div >
288- {% - endblock data_widget_state -%}
289-
290276{% - block data_widget_view scoped %}
291277{% set div_id = uuid 4() %}
292278{% set datatype_list = output .data | filter_data_type %}
@@ -296,7 +282,7 @@ var element = document.getElementById('{{ div_id }}');
296282var element = document .getElementById (' {{ div_id }}' );
297283 </script >
298284<script type =" {{ datatype }}" >
299- {{ output .data [datatype] | json_dumps }}
285+ {{ output .data [datatype] | json_dumps | escape_html }}
300286 </script >
301287</div >
302288{% - endblock data_widget_view -%}
You can’t perform that action at this time.
0 commit comments