# CVE-2021-39159: Remote code execution in Binderhub

> Attackers can execute arbitrary code in BinderHub via malicious input, potentially stealing credentials and escalating privileges within the Kubernetes deployment.

- **Severity:** Critical 9.6 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 25 Aug 2021
- **Updated:** 4 Aug 2024
- **Also known as:** GHSA-9jjr-qqfp-ppwx, PYSEC-2021-371

## What is CVE-2021-39159?

CVE-2021-39159 is a critical command injection vulnerability in jupyterhub binderhub, published on 25 Aug 2021. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official description

BinderHub is a kubernetes-based cloud service that allows users to share reproducible interactive computing environments from code repositories. In affected versions a remote code execution vulnerability has been identified in BinderHub, where providing BinderHub with maliciously crafted input could execute code in the BinderHub context, with the potential to egress credentials of the BinderHub deployment, including JupyterHub API tokens, kubernetes service accounts, and docker registry credentials. This may provide the ability to manipulate images and other user created pods in the deployment, with the potential to escalate to the host depending on the underlying kubernetes configuration. Users are advised to update to version 0.2.0-n653. If users are unable to update they may disable the git repo provider by specifying the `BinderHub.repo_providers` as a workaround.

Weakness: CWE-78 (Improper Neutralization of Special Elements used in an OS Command), CWE-94 (Improper Control of Generation of Code)

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

3 open source packages ship an affected version, including binderhub. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `binderhub` | PyPI | All versions | 0.2.0 |
| `binderhub` | PyPI | All versions | 0.2.0 |
| `binderhub` | PyPI | All versions | 0.2.0-n653 |

Products: Jupyter Binderhub.

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

Upgrade binderhub to a fixed version for your release line: 0.2.0 or 0.2.0-n653.

## Is CVE-2021-39159 being exploited?

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

## Fix prompt for AI coding agents

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

What it is: CVE-2021-39159 is a critical command injection vulnerability in jupyterhub binderhub, published on 25 Aug 2021. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-39159 in the wild and no public exploit code.

Affected packages and fixed versions:
- binderhub (PyPI): affected all versions; fixed in 0.2.0
- binderhub (PyPI): affected all versions; fixed in 0.2.0
- binderhub (PyPI): affected all versions; fixed in 0.2.0-n653

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-39159/ (Markdown: https://insights.sbomify.com/CVE-2021-39159/index.md)
```

## Sources

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

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