Skip to content

Commit

Permalink
GHSL-2021-1023
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou authored and SylvainCorlay committed Aug 9, 2022
1 parent 37b152c commit df5cb60
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
34 changes: 34 additions & 0 deletions nbconvert/exporters/tests/files/notebook_inject.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,40 @@
}
],
"source": [""]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b72e635a",
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/png": ["\"><script>alert('image/png output')</script>"]
},
"execution_count": null,
"metadata": {}
}
],
"source": [""]
},
{
"cell_type": "code",
"execution_count": null,
"id": "p72e635a",
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/jpeg": ["\"><script>alert('image/jpeg output')</script>"]
},
"execution_count": null,
"metadata": {}
}
],
"source": [""]
}
],
"metadata": {
Expand Down
4 changes: 4 additions & 0 deletions nbconvert/exporters/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,7 @@ def test_javascript_injection(self):
# Check injection in image filenames
assert "<script>alert('png filenames')</script>" not in output
assert "<script>alert('jpg filenames')</script>" not in output

# Check injection in image data
assert "<script>alert('image/png output')</script>" not in output
assert "<script>alert('image/jpeg output')</script>" not in output
4 changes: 2 additions & 2 deletions share/jupyter/nbconvert/templates/classic/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ unknown type {{ cell.type }}
{%- if 'image/png' in output.metadata.get('filenames', {}) %}
<img src="{{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
{%- else %}
<img src="data:image/png;base64,{{ output.data['image/png'] }}"
<img src="data:image/png;base64,{{ output.data['image/png'] | escape_html }}"
{%- endif %}
{%- set width=output | get_metadata('width', 'image/png') -%}
{%- if width is not none %}
Expand All @@ -184,7 +184,7 @@ alt="{{ alttext }}"
{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
<img src="{{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
{%- else %}
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] | escape_html }}"
{%- endif %}
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
{%- if width is not none %}
Expand Down
4 changes: 2 additions & 2 deletions share/jupyter/nbconvert/templates/lab/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ unknown type {{ cell.type }}
{%- if 'image/png' in output.metadata.get('filenames', {}) %}
<img src="{{ output.metadata.filenames['image/png'] | posix_path | escape_html }}"
{%- else %}
<img src="data:image/png;base64,{{ output.data['image/png'] }}"
<img src="data:image/png;base64,{{ output.data['image/png'] | escape_html }}"
{%- endif %}
{%- set width=output | get_metadata('width', 'image/png') -%}
{%- if width is not none %}
Expand Down Expand Up @@ -206,7 +206,7 @@ jp-needs-dark-background
{%- if 'image/jpeg' in output.metadata.get('filenames', {}) %}
<img src="{{ output.metadata.filenames['image/jpeg'] | posix_path | escape_html }}"
{%- else %}
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] }}"
<img src="data:image/jpeg;base64,{{ output.data['image/jpeg'] | escape_html }}"
{%- endif %}
{%- set width=output | get_metadata('width', 'image/jpeg') -%}
{%- if width is not none %}
Expand Down

0 comments on commit df5cb60

Please sign in to comment.