Skip to content

Commit 37b152c

Browse files
martinRenouSylvainCorlay
authored andcommitted
GHSL-2021-1022
1 parent d2d44d4 commit 37b152c

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

nbconvert/exporters/tests/files/notebook_inject.ipynb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,48 @@
6060
}
6161
],
6262
"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": [""]
63105
}
64106
],
65107
"metadata": {

nbconvert/exporters/tests/test_html.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,7 @@ def test_javascript_injection(self):
155155
# Check injection in svg output
156156
assert "<script>alert('image/svg+xml output')</script>" not in output
157157
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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ unknown type {{ cell.type }}
156156
{% block data_png scoped %}
157157
<div class="output_png output_subarea {{ extra_class }}">
158158
{%- 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 }}"
160160
{%- else %}
161161
<img src="data:image/png;base64,{{ output.data['image/png'] }}"
162162
{%- endif %}
@@ -182,7 +182,7 @@ alt="{{ alttext }}"
182182
{% block data_jpg scoped %}
183183
<div class="output_jpeg output_subarea {{ extra_class }}">
184184
{%- 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 }}"
186186
{%- else %}
187187
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
188188
{%- endif %}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ unknown type {{ cell.type }}
174174
{% block data_png scoped %}
175175
<div class="jp-RenderedImage jp-OutputArea-output {{ extra_class }}">
176176
{%- 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 }}"
178178
{%- else %}
179179
<img src="data:image/png;base64,{{ output.data['image/png'] }}"
180180
{%- endif %}
@@ -204,7 +204,7 @@ jp-needs-dark-background
204204
{% block data_jpg scoped %}
205205
<div class="jp-RenderedImage jp-OutputArea-output {{ extra_class }}">
206206
{%- 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 }}"
208208
{%- else %}
209209
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
210210
{%- endif %}

0 commit comments

Comments
 (0)