# CVE-2021-41134: Stored XSS in Jupyter nbdime

> Attackers can execute arbitrary scripts in Jupyter notebooks via unsanitized file names in nbdime, requiring users to update the library.

- **Severity:** High 8.7 (`CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 3 Nov 2021
- **Updated:** 4 Aug 2024
- **Also known as:** GHSA-p6rw-44q7-3fw4, PYSEC-2021-428, openSUSE-SU-2024:11630-1

## What is CVE-2021-41134?

CVE-2021-41134 is a high-severity cross-site scripting vulnerability in jupyter nbdime, published on 3 Nov 2021. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.

### Official description

nbdime provides tools for diffing and merging of Jupyter Notebooks. In affected versions a stored cross-site scripting (XSS) issue exists within the Jupyter-owned nbdime project. It appears that when reading the file name and path from disk, the extension does not sanitize the string it constructs before returning it to be displayed. The diffNotebookCheckpoint function within nbdime causes this issue. When attempting to display the name of the local notebook (diffNotebookCheckpoint), nbdime appears to simply append .ipynb to the name of the input file. The NbdimeWidget is then created, and the base string is passed through to the request API function. From there, the frontend simply renders the HTML tag and anything along with it. Users are advised to patch to the most recent version of the affected product.

Weakness: CWE-79 (Improper Neutralization of Input During Web Page Generation)

## Which versions are affected by CVE-2021-41134?

15 open source packages ship an affected version, including nbdime-jupyterlab and nbdime. It affects 2 products.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `nbdime-jupyterlab` | npm | All versions | 1.0.1 |
| `nbdime-jupyterlab` | npm | All versions | 1.0.1 |
| `nbdime-jupyterlab` | npm | From 2.0.0 | 2.1.1 |
| `nbdime-jupyterlab` | npm | From 2.0.0 | 2.1.1 |
| `nbdime` | PyPI | All versions | 1.1.1, 2.1.1, 3.1.1 |
| `nbdime` | PyPI | All versions | 1.1.1 |
| `nbdime` | PyPI | All versions | 1.1.1 |
| `nbdime` | PyPI | From 2.0.0 | 2.1.1 |
| `nbdime` | PyPI | From 2.0.0 | 2.1.1 |
| `nbdime` | PyPI | From 3.0.0 | 3.1.1 |
| `nbdime` | PyPI | From 3.0.0 | 3.1.1 |
| `nbdime` | npm | All versions | 5.0.2 |
| `nbdime` | npm | All versions | 5.0.2 |
| `nbdime` | npm | From 6.0.0 | 6.1.2 |
| `nbdime` | npm | From 6.0.0 | 6.1.2 |

Products: Jupyter Nbdime, Jupyter Nbdime-Jupyterlab.

## How do I fix CVE-2021-41134?

Upgrade nbdime-jupyterlab to a fixed version for your release line: 1.0.1 or 2.1.1.

## Is CVE-2021-41134 being exploited?

There is no known exploitation of CVE-2021-41134 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-41134 and fix it if it is affected.

What it is: CVE-2021-41134 is a high-severity cross-site scripting vulnerability in jupyter nbdime, published on 3 Nov 2021. Any signed-in user can exploit it over the network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-41134 in the wild and no public exploit code.

Affected packages and fixed versions:
- nbdime-jupyterlab (npm): affected all versions; fixed in 1.0.1
- nbdime-jupyterlab (npm): affected all versions; fixed in 1.0.1
- nbdime-jupyterlab (npm): affected from 2.0.0; fixed in 2.1.1
- nbdime-jupyterlab (npm): affected from 2.0.0; fixed in 2.1.1
- nbdime (PyPI): affected all versions; fixed in 1.1.1, 2.1.1, 3.1.1
- nbdime (PyPI): affected all versions; fixed in 1.1.1
- nbdime (PyPI): affected all versions; fixed in 1.1.1
- nbdime (PyPI): affected from 2.0.0; fixed in 2.1.1
- nbdime (PyPI): affected from 2.0.0; fixed in 2.1.1
- nbdime (PyPI): affected from 3.0.0; fixed in 3.1.1
- nbdime (PyPI): affected from 3.0.0; fixed in 3.1.1
- nbdime (npm): affected all versions; fixed in 5.0.2

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-41134/ (Markdown: https://insights.sbomify.com/CVE-2021-41134/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-41134
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-41134
- OSV: https://osv.dev/vulnerability/CVE-2021-41134

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-41134/
Summaries are generated and may contain mistakes; the official description above is the record.
