Skip to content

Commit

Permalink
Convert input to string prior to escape HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou authored and SylvainCorlay committed Aug 9, 2022
1 parent 0818628 commit bef65d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
9 changes: 1 addition & 8 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@
)


def escape_html(s, quote=True):
if not isinstance(s, str):
return s
else:
return html.escape(s)


default_filters = {
"indent": filters.indent,
"markdown2html": filters.markdown2html,
Expand Down Expand Up @@ -78,7 +71,7 @@ def escape_html(s, quote=True):
"convert_pandoc": filters.convert_pandoc,
"json_dumps": json.dumps,
# For removing any HTML
"escape_html": escape_html,
"escape_html": lambda s: html.escape(str(s)),
# For sanitizing HTML for any XSS
"clean_html": clean_html,
"strip_trailing_newline": filters.strip_trailing_newline,
Expand Down
19 changes: 19 additions & 0 deletions nbconvert/exporters/tests/files/notebook_inject.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@
],
"source": [""]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d72e095a",
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/png": ["abcd"]
},
"execution_count": null,
"metadata": {
"width": ["><script>alert('output.metadata.width png injection')</script>"]
}
}
],
"source": [""]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit bef65d7

Please sign in to comment.