CVE-2021-39159: Binderhub Remote Code Execution Vulnerability

CRITICAL
Advisory Identifier: GHSA-9jjr-qqfp-ppwx
CVSS 9.6
CWE-78 CWE-94
Published
Advisory Summary

CVE-2021-39159 is a CRITICAL (CVSS 9.6) remote code execution vulnerability (CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')) affecting Binderhub libraries in the PyPI ecosystem. The issue involves remote code execution via git repo provider. Remediation is available by upgrading affected packages to version 0.2.0.

CVE-2021-39159 at a Glance

CVE Identifier CVE-2021-39159
GHSA Identifier GHSA-9jjr-qqfp-ppwx
Severity CRITICAL
CVSS v3.1 Base Score 9.6
CWE Classification CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Affected Product Binderhub
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 9.6

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix CVE-2021-39159

To remediate this vulnerability, upgrade all affected Binderhub dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

binderhub fixed: 0.2.0
pip install binderhub>=0.2.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show binderhub

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2021-39159, inspect your installed packages using pip:

pip show binderhub

Analyze the terminal output to locate any version of Binderhub in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.2.0), your application is affected.

Note: The pip show binderhub command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection'), where the product constructs all or part of an os command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended os command when it is sent to a downstream component. In Binderhub, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact 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. ### Patches Patch below, or [on GitHub](https://github.com/jupyterhub/binderhub/commit/195caac172690456dcdc8cc7a6ca50e05abf8182.patch) ```diff From 9f4043d9dddc1174920e687773f27b7933f48ab6 Mon Sep 17 00:00:00 2001 From: Riccardo Castellotti <rcastell@cern.ch> Date: Thu, 19 Aug 2021 15:49:43 +0200 Subject: [PATCH] Explicitly separate git-ls-remote options from positional arguments --- binderhub/repoproviders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/binderhub/repoproviders.py b/binderhub/repoproviders.py index f33347b..5d4b87c 100755 --- a/binderhub/repoproviders.py +++ b/binderhub/repoproviders.py @@ -484,7 +484,7 @@ class GitRepoProvider(RepoProvider): self.sha1_validate(self.unresolved_ref) except ValueError: # The ref is a head/tag and we resolve it using `git ls-remote` - command = ["git", "ls-remote", self.repo, self.unresolved_ref] + command = ["git", "ls-remote", "--", self.repo, self.unresolved_ref] result = subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if result.returncode: raise RuntimeError("Unable to run git ls-remote to get the `resolved_ref`: {}".format(result.stderr)) -- 2.25.1 ``` ### Workarounds Disable the git repo provider by specifying the `BinderHub.repo_providers` config, e.g.: ```python from binderhub.repoproviders import (GitHubRepoProvider, GitLabRepoProvider, GistRepoProvider, ZenodoProvider, FigshareProvider, HydroshareProvider, DataverseProvider) c.BinderHub.repo_providers = { 'gh': GitHubRepoProvider, 'gist': GistRepoProvider, 'gl': GitLabRepoProvider, 'zenodo': ZenodoProvider, 'figshare': FigshareProvider, 'hydroshare': HydroshareProvider, 'dataverse': DataverseProvider, } ``` ### References Credit: Jose Carlos Luna Duran (CERN) and Riccardo Castellotti (CERN). ### For more information If you have any questions or comments about this advisory: * Email us at [security@ipython.org](mailto:security@ipython.org)

CVE-2021-39159 Affected Binderhub Versions

1 component(s)
Fixed Versions:
0.2.0
Product / Package Ecosystem Affected Versions Fixed Version
binderhub
PyPI
< 0.2.0
0.2.0

References

Frequently Asked Questions

What is CVE-2021-39159?
CVE-2021-39159 is a security vulnerability in Binderhub involving remote code execution via git repo provider under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
Which Binderhub versions are affected?
Affected versions include releases prior to 0.2.0 across affected packages: binderhub.
What version fixes CVE-2021-39159?
Upgrading to 0.2.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is binderhub affected?
Yes, binderhub is affected in releases prior to 0.2.0. Upgrade your dependency to 0.2.0 or later.
What is the CVSS score of CVE-2021-39159?
CVE-2021-39159 has a CVSS v3.1 base score of 9.6 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H.
What CWE is associated with CVE-2021-39159?
CVE-2021-39159 is classified under CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection') (The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component.).
How can I check PyPI dependencies for CVE-2021-39159?
Run the dependency tree command: 'pip show binderhub'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-9jjr-qqfp-ppwx",
  "modified" : "2024-09-13T18:05:58Z",
  "published" : "2021-08-30T16:16:58Z",
  "aliases" : [ "CVE-2021-39159" ],
  "summary" : "remote code execution via git repo provider",
  "details" : "### Impact\n\nA 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.\n\n### Patches\n\nPatch below, or [on GitHub](https://github.com/jupyterhub/binderhub/commit/195caac172690456dcdc8cc7a6ca50e05abf8182.patch)\n\n```diff\nFrom 9f4043d9dddc1174920e687773f27b7933f48ab6 Mon Sep 17 00:00:00 2001\nFrom: Riccardo Castellotti <rcastell@cern.ch>\nDate: Thu, 19 Aug 2021 15:49:43 +0200\nSubject: [PATCH] Explicitly separate git-ls-remote options from positional\n arguments\n\n---\n binderhub/repoproviders.py | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/binderhub/repoproviders.py b/binderhub/repoproviders.py\nindex f33347b..5d4b87c 100755\n--- a/binderhub/repoproviders.py\n+++ b/binderhub/repoproviders.py\n@@ -484,7 +484,7 @@ class GitRepoProvider(RepoProvider):\n             self.sha1_validate(self.unresolved_ref)\n         except ValueError:\n             # The ref is a head/tag and we resolve it using `git ls-remote`\n-            command = [\"git\", \"ls-remote\", self.repo, self.unresolved_ref]\n+            command = [\"git\", \"ls-remote\", \"--\", self.repo, self.unresolved_ref]\n             result = subprocess.run(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n             if result.returncode:\n                 raise RuntimeError(\"Unable to run git ls-remote to get the `resolved_ref`: {}\".format(result.stderr))\n-- \n2.25.1\n\n```\n\n### Workarounds\n\nDisable the git repo provider by specifying the `BinderHub.repo_providers` config, e.g.:\n\n```python\nfrom binderhub.repoproviders import (GitHubRepoProvider,\n                            GitLabRepoProvider, GistRepoProvider,\n                            ZenodoProvider, FigshareProvider, HydroshareProvider,\n                            DataverseProvider)\n\nc.BinderHub.repo_providers =  {\n            'gh': GitHubRepoProvider,\n            'gist': GistRepoProvider,\n            'gl': GitLabRepoProvider,\n            'zenodo': ZenodoProvider,\n            'figshare': FigshareProvider,\n            'hydroshare': HydroshareProvider,\n            'dataverse': DataverseProvider,\n        }\n```\n\n### References\n\nCredit: Jose Carlos Luna Duran (CERN) and Riccardo Castellotti (CERN).\n\n### For more information\n\nIf you have any questions or comments about this advisory:\n\n* Email us at [security@ipython.org](mailto:security@ipython.org)\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:H/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "binderhub"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.2.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/jupyterhub/binderhub/security/advisories/GHSA-9jjr-qqfp-ppwx"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2021-39159"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jupyterhub/binderhub/commit/195caac172690456dcdc8cc7a6ca50e05abf8182"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/jupyterhub/binderhub/commit/195caac172690456dcdc8cc7a6ca50e05abf8182.patch"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/jupyterhub/binderhub"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/binderhub/PYSEC-2021-371.yaml"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-78", "CWE-94" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2021-08-25T15:20:56Z",
    "nvd_published_at" : "2021-08-25T19:15:00Z"
  }
}