Skip to content

Commit 48fe71e

Browse files
martinRenouSylvainCorlay
authored andcommitted
GHSL-2021-1024
1 parent df5cb60 commit 48fe71e

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

nbconvert/exporters/tests/files/notebook_inject.ipynb

+38
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,44 @@
136136
}
137137
],
138138
"source": [""]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"id": "d72e635a",
144+
"metadata": {},
145+
"outputs": [
146+
{
147+
"output_type": "execute_result",
148+
"data": {
149+
"image/png": ["abcd"]
150+
},
151+
"execution_count": null,
152+
"metadata": {
153+
"width": "><script>alert('output.metadata.width png injection')</script>"
154+
}
155+
}
156+
],
157+
"source": [""]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"id": "d72e635a",
163+
"metadata": {},
164+
"outputs": [
165+
{
166+
"output_type": "execute_result",
167+
"data": {
168+
"image/png": ["abcd"]
169+
},
170+
"execution_count": null,
171+
"metadata": {
172+
"height": "><script>alert('output.metadata.height png injection')</script>"
173+
}
174+
}
175+
],
176+
"source": [""]
139177
}
140178
],
141179
"metadata": {

nbconvert/exporters/tests/test_html.py

+4
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,7 @@ def test_javascript_injection(self):
163163
# Check injection in image data
164164
assert "<script>alert('image/png output')</script>" not in output
165165
assert "<script>alert('image/jpeg output')</script>" not in output
166+
167+
# Check injection in image width/height
168+
assert "<script>alert('output.metadata.width png injection')</script>" not in output
169+
assert "<script>alert('output.metadata.height png injection')</script>" not in output

share/jupyter/nbconvert/templates/classic/base.html.j2

+6-6
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,18 @@ unknown type {{ cell.type }}
162162
{%- endif %}
163163
{%- set width=output | get_metadata('width', 'image/png') -%}
164164
{%- if width is not none %}
165-
width={{ width }}
165+
width={{ width | escape_html }}
166166
{%- endif %}
167167
{%- set height=output | get_metadata('height', 'image/png') -%}
168168
{%- if height is not none %}
169-
height={{ height }}
169+
height={{ height | escape_html }}
170170
{%- endif %}
171171
{%- if output | get_metadata('unconfined', 'image/png') %}
172172
class="unconfined"
173173
{%- endif %}
174174
{%- set alttext=(output | get_metadata('alt', 'image/png')) or (cell | get_metadata('alt')) -%}
175175
{%- if alttext is not none %}
176-
alt="{{ alttext }}"
176+
alt="{{ alttext | escape_html }}"
177177
{%- endif %}
178178
>
179179
</div>
@@ -188,18 +188,18 @@ alt="{{ alttext }}"
188188
{%- endif %}
189189
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
190190
{%- if width is not none %}
191-
width={{ width }}
191+
width={{ width | escape_html }}
192192
{%- endif %}
193193
{%- set height=output | get_metadata('height', 'image/jpeg') -%}
194194
{%- if height is not none %}
195-
height={{ height }}
195+
height={{ height | escape_html }}
196196
{%- endif %}
197197
{%- if output | get_metadata('unconfined', 'image/jpeg') %}
198198
class="unconfined"
199199
{%- endif %}
200200
{%- set alttext=(output | get_metadata('alt', 'image/jpeg')) or (cell | get_metadata('alt')) -%}
201201
{%- if alttext is not none %}
202-
alt="{{ alttext }}"
202+
alt="{{ alttext | escape_html }}"
203203
{%- endif %}
204204
>
205205
</div>

share/jupyter/nbconvert/templates/lab/base.html.j2

+4-4
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,11 @@ unknown type {{ cell.type }}
180180
{%- endif %}
181181
{%- set width=output | get_metadata('width', 'image/png') -%}
182182
{%- if width is not none %}
183-
width={{ width }}
183+
width={{ width | escape_html }}
184184
{%- endif %}
185185
{%- set height=output | get_metadata('height', 'image/png') -%}
186186
{%- if height is not none %}
187-
height={{ height }}
187+
height={{ height | escape_html }}
188188
{%- endif %}
189189
class="
190190
{%- if output | get_metadata('unconfined', 'image/png') %}
@@ -210,11 +210,11 @@ jp-needs-dark-background
210210
{%- endif %}
211211
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
212212
{%- if width is not none %}
213-
width={{ width }}
213+
width={{ width | escape_html }}
214214
{%- endif %}
215215
{%- set height=output | get_metadata('height', 'image/jpeg') -%}
216216
{%- if height is not none %}
217-
height={{ height }}
217+
height={{ height | escape_html }}
218218
{%- endif %}
219219
class="
220220
{%- if output | get_metadata('unconfined', 'image/jpeg') %}

0 commit comments

Comments
 (0)