File tree Expand file tree Collapse file tree 4 files changed +50
-4
lines changed
nbconvert/exporters/tests
share/jupyter/nbconvert/templates Expand file tree Collapse file tree 4 files changed +50
-4
lines changed Original file line number Diff line number Diff line change 60
60
}
61
61
],
62
62
"source" : [" " ]
63
+ },
64
+ {
65
+ "cell_type" : " code" ,
66
+ "execution_count" : null ,
67
+ "id" : " b72e63fa" ,
68
+ "metadata" : {},
69
+ "outputs" : [
70
+ {
71
+ "output_type" : " execute_result" ,
72
+ "data" : {
73
+ "image/png" : [" " ]
74
+ },
75
+ "execution_count" : null ,
76
+ "metadata" : {
77
+ "filenames" : {
78
+ "image/png" : " \" ><script>alert('png filenames')</script>"
79
+ }
80
+ }
81
+ }
82
+ ],
83
+ "source" : [" " ]
84
+ },
85
+ {
86
+ "cell_type" : " code" ,
87
+ "execution_count" : null ,
88
+ "id" : " b72e63f3" ,
89
+ "metadata" : {},
90
+ "outputs" : [
91
+ {
92
+ "output_type" : " execute_result" ,
93
+ "data" : {
94
+ "image/jpeg" : [" " ]
95
+ },
96
+ "execution_count" : null ,
97
+ "metadata" : {
98
+ "filenames" : {
99
+ "image/jpeg" : " \" ><script>alert('jpg filenames')</script>"
100
+ }
101
+ }
102
+ }
103
+ ],
104
+ "source" : [" " ]
63
105
}
64
106
],
65
107
"metadata" : {
Original file line number Diff line number Diff line change @@ -155,3 +155,7 @@ def test_javascript_injection(self):
155
155
# Check injection in svg output
156
156
assert "<script>alert('image/svg+xml output')</script>" not in output
157
157
assert "<script>alert('svg_filename')</script>" not in output
158
+
159
+ # Check injection in image filenames
160
+ assert "<script>alert('png filenames')</script>" not in output
161
+ assert "<script>alert('jpg filenames')</script>" not in output
Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ unknown type {{ cell.type }}
156
156
{% block data_png scoped %}
157
157
<div class =" output_png output_subarea {{ extra_class }}" >
158
158
{% - if 'image/png' in output .metadata .get ('filenames' , {}) %}
159
- <img src =" {{ output.metadata.filenames['image/png'] | posix_path }}"
159
+ <img src =" {{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
160
160
{%- else %}
161
161
<img src =" data:image/png;base64,{{ output.data['image/png'] }}"
162
162
{%- endif %}
@@ -182,7 +182,7 @@ alt="{{ alttext }}"
182
182
{% block data_jpg scoped %}
183
183
<div class =" output_jpeg output_subarea {{ extra_class }}" >
184
184
{% - if 'image/jpeg' in output .metadata .get ('filenames' , {}) %}
185
- <img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path }}"
185
+ <img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
186
186
{%- else %}
187
187
<img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
188
188
{%- endif %}
Original file line number Diff line number Diff line change @@ -174,7 +174,7 @@ unknown type {{ cell.type }}
174
174
{% block data_png scoped %}
175
175
<div class =" jp-RenderedImage jp-OutputArea-output {{ extra_class }}" >
176
176
{% - if 'image/png' in output .metadata .get ('filenames' , {}) %}
177
- <img src =" {{ output.metadata.filenames['image/png'] | posix_path }}"
177
+ <img src =" {{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
178
178
{%- else %}
179
179
<img src =" data:image/png;base64,{{ output.data['image/png'] }}"
180
180
{%- endif %}
@@ -204,7 +204,7 @@ jp-needs-dark-background
204
204
{% block data_jpg scoped %}
205
205
<div class =" jp-RenderedImage jp-OutputArea-output {{ extra_class }}" >
206
206
{% - if 'image/jpeg' in output .metadata .get ('filenames' , {}) %}
207
- <img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path }}"
207
+ <img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
208
208
{%- else %}
209
209
<img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
210
210
{%- endif %}
You can’t perform that action at this time.
0 commit comments