Skip to content

Commit df5cb60

Browse files
martinRenouSylvainCorlay
authored andcommitted
GHSL-2021-1023
1 parent 37b152c commit df5cb60

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

nbconvert/exporters/tests/files/notebook_inject.ipynb

+34
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,40 @@
102102
}
103103
],
104104
"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": [""]
105139
}
106140
],
107141
"metadata": {

nbconvert/exporters/tests/test_html.py

+4
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,7 @@ def test_javascript_injection(self):
159159
# Check injection in image filenames
160160
assert "<script>alert('png filenames')</script>" not in output
161161
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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ unknown type {{ cell.type }}
158158
{%- if 'image/png' in output.metadata.get('filenames', {}) %}
159159
<img src="{{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
160160
{%- 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 }}"
162162
{%- endif %}
163163
{%- set width=output | get_metadata('width', 'image/png') -%}
164164
{%- if width is not none %}
@@ -184,7 +184,7 @@ alt="{{ alttext }}"
184184
{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
185185
<img src="{{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
186186
{%- 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 }}"
188188
{%- endif %}
189189
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
190190
{%- if width is not none %}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ unknown type {{ cell.type }}
176176
{%- if 'image/png' in output.metadata.get('filenames', {}) %}
177177
<img src="{{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
178178
{%- 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 }}"
180180
{%- endif %}
181181
{%- set width=output | get_metadata('width', 'image/png') -%}
182182
{%- if width is not none %}
@@ -206,7 +206,7 @@ jp-needs-dark-background
206206
{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
207207
<img src="{{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
208208
{%- 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 }}"
210210
{%- endif %}
211211
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
212212
{%- if width is not none %}

0 commit comments

Comments
 (0)