File tree 4 files changed +42
-4
lines changed
nbconvert/exporters/tests
share/jupyter/nbconvert/templates
4 files changed +42
-4
lines changed Original file line number Diff line number Diff line change 102
102
}
103
103
],
104
104
"source" : [" " ]
105
+ },
106
+ {
107
+ "cell_type" : " code" ,
108
+ "execution_count" : null ,
109
+ "id" : " b72e635a" ,
110
+ "metadata" : {},
111
+ "outputs" : [
112
+ {
113
+ "output_type" : " execute_result" ,
114
+ "data" : {
115
+ "image/png" : [" \" ><script>alert('image/png output')</script>" ]
116
+ },
117
+ "execution_count" : null ,
118
+ "metadata" : {}
119
+ }
120
+ ],
121
+ "source" : [" " ]
122
+ },
123
+ {
124
+ "cell_type" : " code" ,
125
+ "execution_count" : null ,
126
+ "id" : " p72e635a" ,
127
+ "metadata" : {},
128
+ "outputs" : [
129
+ {
130
+ "output_type" : " execute_result" ,
131
+ "data" : {
132
+ "image/jpeg" : [" \" ><script>alert('image/jpeg output')</script>" ]
133
+ },
134
+ "execution_count" : null ,
135
+ "metadata" : {}
136
+ }
137
+ ],
138
+ "source" : [" " ]
105
139
}
106
140
],
107
141
"metadata" : {
Original file line number Diff line number Diff line change @@ -159,3 +159,7 @@ def test_javascript_injection(self):
159
159
# Check injection in image filenames
160
160
assert "<script>alert('png filenames')</script>" not in output
161
161
assert "<script>alert('jpg filenames')</script>" not in output
162
+
163
+ # Check injection in image data
164
+ assert "<script>alert('image/png output')</script>" not in output
165
+ assert "<script>alert('image/jpeg output')</script>" not in output
Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ unknown type {{ cell.type }}
158
158
{% - if 'image/png' in output .metadata .get ('filenames' , {}) %}
159
159
<img src =" {{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
160
160
{%- else %}
161
- <img src =" data:image/png;base64,{{ output.data['image/png'] }}"
161
+ <img src =" data:image/png;base64,{{ output.data['image/png'] | escape_html }}"
162
162
{%- endif %}
163
163
{%- set width =output | get_metadata( ' width' , ' image/png' ) -%}
164
164
{%- if width is not none %}
@@ -184,7 +184,7 @@ alt="{{ alttext }}"
184
184
{% - if 'image/jpeg' in output .metadata .get ('filenames' , {}) %}
185
185
<img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
186
186
{%- else %}
187
- <img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
187
+ <img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] | escape_html }}"
188
188
{%- endif %}
189
189
{%- set width =output | get_metadata( ' width' , ' image/jpeg' ) -%}
190
190
{%- if width is not none %}
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ unknown type {{ cell.type }}
176
176
{% - if 'image/png' in output .metadata .get ('filenames' , {}) %}
177
177
<img src =" {{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
178
178
{%- else %}
179
- <img src =" data:image/png;base64,{{ output.data['image/png'] }}"
179
+ <img src =" data:image/png;base64,{{ output.data['image/png'] | escape_html }}"
180
180
{%- endif %}
181
181
{%- set width =output | get_metadata( ' width' , ' image/png' ) -%}
182
182
{%- if width is not none %}
@@ -206,7 +206,7 @@ jp-needs-dark-background
206
206
{% - if 'image/jpeg' in output .metadata .get ('filenames' , {}) %}
207
207
<img src =" {{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
208
208
{%- else %}
209
- <img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
209
+ <img src =" data:image/jpeg;base64,{{ output.data['image/jpeg'] | escape_html }}"
210
210
{%- endif %}
211
211
{%- set width =output | get_metadata( ' width' , ' image/jpeg' ) -%}
212
212
{%- if width is not none %}
You can’t perform that action at this time.
0 commit comments