Skip to content

Commit bef65d7

Browse files
martinRenouSylvainCorlay
authored andcommitted
Convert input to string prior to escape HTML
1 parent 0818628 commit bef65d7

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

nbconvert/exporters/templateexporter.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
)
4141

4242

43-
def escape_html(s, quote=True):
44-
if not isinstance(s, str):
45-
return s
46-
else:
47-
return html.escape(s)
48-
49-
5043
default_filters = {
5144
"indent": filters.indent,
5245
"markdown2html": filters.markdown2html,
@@ -78,7 +71,7 @@ def escape_html(s, quote=True):
7871
"convert_pandoc": filters.convert_pandoc,
7972
"json_dumps": json.dumps,
8073
# For removing any HTML
81-
"escape_html": escape_html,
74+
"escape_html": lambda s: html.escape(str(s)),
8275
# For sanitizing HTML for any XSS
8376
"clean_html": clean_html,
8477
"strip_trailing_newline": filters.strip_trailing_newline,

nbconvert/exporters/tests/files/notebook_inject.ipynb

+19
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@
156156
],
157157
"source": [""]
158158
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"id": "d72e095a",
163+
"metadata": {},
164+
"outputs": [
165+
{
166+
"output_type": "execute_result",
167+
"data": {
168+
"image/png": ["abcd"]
169+
},
170+
"execution_count": null,
171+
"metadata": {
172+
"width": ["><script>alert('output.metadata.width png injection')</script>"]
173+
}
174+
}
175+
],
176+
"source": [""]
177+
},
159178
{
160179
"cell_type": "code",
161180
"execution_count": null,

0 commit comments

Comments
 (0)