GHSA-5PPM-JRF6-PGXG
Jupyter Enterprise Gateway: OS command injection via KERNEL_* env in DistributedProcessProxy SSH startup command (CWE-78)
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-5PPM-JRF6-PGXG divulgada | |
| 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 |
Jupyter Enterprise Gateway builds the kernel startup command for SSH-distributed deployments by concatenating client-supplied environment variables into a shell string that is then executed on a remote host over SSH. The values are placed inside double quotes using json.dumps(), which escapes double quotes and backslashes but does NOT escape the POSIX shell substitution metacharacters $() and backticks. A client that can reach the kernel-start API can therefore set a KERNEL_* environment variable whose value contains a command substitution; that substitution is evaluated by the remote login shell when the gateway launches the kernel, yielding arbitrary command execution on the remote compute host as the gateway's SSH user. The kernel-start API does not require authentication in a default install (the auth token defaults to empty, which disables the token check), so default DistributedProcessProxy deployments are exploitable unauthenticated; deployments that set eg_auth_token require a valid low-privilege token. This sink is in the SSH/distributed launch path and was NOT addressed by the 3.3.0 security round, which only hardened the Kubernetes/container Jinja2 template paths.
## Technical detail
Untrusted-input to sink trace (local clone HEAD 1444437, version 3.4.0.dev0):
- Entry / trust boundary: `enterprise_gateway/services/kernels/handlers.py:24` MainKernelHandler(TokenAuthorizationMixin). The POST /api/kernels body is read at `handlers.py:96` get_json_body(); the request `env` dict is attacker-controlled.
- Weak validation: `handlers.py:39-56` _build_kernel_env(). For every key starting with KERNEL_ (`:46`) the ONLY checks are isinstance(value, str) (`:47`) and len(value) <= 4096 (`:21,:51`). No metacharacter allowlist/denylist, no shell quoting; the value is stored verbatim at `:55`.
- Re-injection: `remotemanager.py:510-529` _capture_user_overrides() copies every KERNEL_* key from the request env into user_overrides unfiltered, and `:568` merges them back into the launch env.
- Vulnerable sink: `enterprise_gateway/services/processproxies/distributed.py:147-179` _build_startup_command(), non-local-host branch (`:164`):
for key, value in env_dict.items():
cmd += "export {}={};".format(key, json.dumps(value).replace("'", "''"))json.dumps wraps the value in DOUBLE quotes and escapes embedded double quotes/backslashes, but does NOT escape $, $(), or backticks. The trailing single-quote replace is inert inside a double-quoted token.
5. Execution: `distributed.py:141` self.rsh(self.ip, cmd) -> `processproxy.py:744` ssh.exec_command(command) (paramiko) runs the string through the remote login shell, so any $(...) / backtick substitution inside the double-quoted value is evaluated on the remote host.
No shlex / shell quoting exists anywhere in enterprise_gateway/services (grep for shlex|quote returns nothing).
Why command substitution and NOT quote-breakout: a naive payload attempting to break out of the quotes is neutralized because json.dumps escapes the double quote. The working primitive is POSIX command substitution, which executes INSIDE double quotes: a value like x$(touch /tmp/pwned) renders to export KERNEL_FOO="x$(touch /tmp/pwned)"; and executes. Backticks behave identically.
Novelty: OSV.dev and the repo security-advisories list exactly three published advisories, all fixed in 3.3.0 and all in the Container/Kubernetes Jinja2 paths (GHSA-cfw7-6c5v-2wjq/CVE-2026-44182, GHSA-f49j-v924-fx9w/CVE-2026-44181, GHSA-chq7-94j8-cj28/CVE-2026-44180). The 3.3.0 hardening does not touch distributed.py. The DistributedProcessProxy SSH shell sink is a distinct, unremediated path at HEAD 3.4.0.dev0 and all prior releases.
## Proof of concept (static / request-difference, no third-party system)
Reproduce the exact string-construction logic of distributed.py:168 and show the command the gateway would hand to ssh.exec_command:
python3
>>> import json
>>> v = "x$(touch /tmp/eg_pwned)"
>>> print("export KERNEL_FOO=" + json.dumps(v).replace("'", "''") + ";")
export KERNEL_FOO="x$(touch /tmp/eg_pwned)";The command substitution survives json.dumps. Confirm POSIX execution under the remote login shell semantics:
sh -c 'export KERNEL_FOO="x$(echo PWNED > /tmp/eg_poc)"; true'; cat /tmp/eg_pocprints PWNED, proving the value-embedded substitution executed. The over-the-wire request to a DistributedProcessProxy-configured gateway:
POST /api/kernels
Content-Type: application/json
{"name":"python_distributed","env":{"KERNEL_ID":"<valid-uuid4>","KERNEL_FOO":"x$(touch /tmp/eg_rce)"}}(If eg_auth_token is configured, add Authorization: token <token>.) The static artifact (rendered SSH command string + proven POSIX execution of the substitution) establishes the injection primitive without the live SSH fleet.
## Suggested fix
In distributed.py _build_startup_command (lines 167-171) stop hand-quoting and use shlex.quote per value so each is a single, fully-neutralized shell token:
import shlex
for key, value in env_dict.items():
cmd += "export {}={};".format(shlex.quote(str(key)), shlex.quote(str(value)))shlex.quote single-quotes values and escapes embedded single quotes, suppressing $(), backticks, $VAR and quote-breakout. Defense in depth: validate KERNEL_* values at the handlers.py boundary, rejecting shell metacharacters (mirroring the K8s allowlist added in 3.3.0); the argv elements at distributed.py:174-175 should also be quoted. I am happy to send this as a PR.
## Impact / severity (honest, both ways)
Ceiling: unauthenticated remote command execution on a separate compute host (default install with empty auth token + DistributedProcessProxy/SSH mode). Floor: authenticated low-privilege RCE when eg_auth_token is set. Vector (ceiling) CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H; floor with PR:L = 9.0. Scope is Changed because the gateway injects into and executes on a different remote host than the vulnerable component. Filed as High (see applicability); the maintainer may rate Critical for the default-unauthenticated distributed deployment.
## Applicability (most disputable point, stated up front)
This sink fires ONLY when the gateway is configured with DistributedProcessProxy (SSH fan-out) AND the selected host is non-local (ip_is_local False). The local-host branch (distributed.py:162-163) returns argv unmodified and is NOT injectable. DistributedProcessProxy is a documented, supported deployment mode, not the default, so impact is conditional-on-configuration, not universal. Default eg_auth_token is empty (disables the token check), so distributed installs are unauthenticated by default. A full end-to-end demonstration of code on a live remote host needs a configured DistributedProcessProxy plus a second SSH-reachable VM (operator-owned); the static proof above establishes the injection primitive without it.
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
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-5ppm-jrf6-pgxgLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
