llamaCVEVulnerability Intelligence
/
Advisory · GitHub · Go · github.com/dunglas/frankenphp

GHSA-996F-W38M-F574

`putenv` dual-writes process-wide OS environment (sandbox incomplete)

Texto original en inglés · Ver en español

Parche disponible
Descargar PNG JSON
CVSS 3.1
6.4
Media
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:C/C:H/I:L/A:N Fuente: GitHub
ExplotaciónSin evidenciaNo figura en CISA KEV
Exploits públicos0Ninguno conocido
Parche1 versiónPrimer parche el mismo día de la divulgación
Exposición48 dDesde la divulgación, 4 oct 2026, 9:04 a. m.
Detección46 dDesde la divulgación hasta su ingreso al índice
Decisión estimadaSeguir
Remediar en la ventana regular de mantenimiento
Estimación de Llama con el árbol SSVC de CISA a partir de vector CVSS 3.1 y la evidencia de explotación (sin evaluación oficial): sin explotación conocida, no automatizable e impacto técnico parcial. Hay versiones corregidas disponibles.
Un riesgo moderado es un riesgo con modales.Ni pánico ni ignorarla: término medio.
Timeline

Ciclo de vida de la vulnerabilidad

Hoy
Divulgación
Publicada
Explotación
Remediación
Parche v1.13.0
Monitoreo
Detectada +1
4 oct 26
19 nov 26
21 nov 26
4 oct 26
16 oct 26
28 oct 26
9 nov 26
21 nov 26
FechaFaseEventoDetalle
Divulgación Publicada GHSA-996F-W38M-F574 divulgada · CVSS 6.4 (GitHub)
Remediación Parche v1.13.0 github.com/dunglas/frankenphp · 0 d desde divulgación
Monitoreo Detectada Ingresó al índice
Monitoreo Verificada Última verificación contra las fuentes
Resumen
Descripción del advisory
Texto original · GitHub · en inglés

Summary

FrankenPHP overrides PHP’s `putenv` / `getenv` to implement a thread-local environment sandbox. The override still calls Go `os.Setenv` / `os.Unsetenv` on every `putenv`, which mutates the process-wide operating-system environment. Request teardown resets only the thread-local hash table; it never restores the OS environ.

In FrankenPHP’s multi-threaded model, many concurrent requests share one process. Request A’s `putenv` therefore remains visible to:

  • child processes started by request B (`proc_open`, `exec`, `passthru`, `shell_exec`, … without an explicit env array), and
  • C extensions (and any other code) that call libc `getenv` rather than PHP’s sandboxed `getenv`.

PHP’s own `getenv()` on other threads remains sandboxed, which makes the failure easy to miss in tests that only assert PHP-level isolation. Documentation claims the sandbox prevents races on the global C environment; the implementation still writes that global on every putenv.

Impact

  • Cross-request secret leakage into subprocess environments: a secret one request places in the environment (API key, token, DB password) is readable by a child process that a different request spawns with the default environment.
  • Cross-thread env races on the process environ: `os.Setenv` is process-global, so the last `putenv` wins across all threads.
  • Who is affected: multi-threaded FrankenPHP deployments where application or dependency code calls `putenv` with sensitive or request-derived values. Classic FPM is process-isolated; this cross-request isolation failure is specific to FrankenPHP’s shared-process thread pool.

Generic `getenv` inheritance (`PATH`, `LD_*`, a C extension reading libc `getenv`) is standard PHP behavior in every SAPI and is not claimed here beyond the cross-request delta above; it would raise severity only with a concrete high-impact consumer demonstrated.

Distinction from documented worker behavior

Worker-mode persistence of `$_ENV`, statics, and same-thread `putenv` across `frankenphp_handle_request` iterations is documented (`docs/security.md`). That note does not cover process-wide OS env pollution visible to *other threads’* children. This advisory is about the OS dual-write, not the documented same-thread worker state model.

Details

Write path

`frankenphp.c`: `PHP_FUNCTION(frankenphp_putenv)` always calls `go_putenv`, then updates TLS `sandboxed_env`.

`env.go`:

//export go_putenv
func go_putenv(name *C.char, nameLen C.int, val *C.char, valLen C.int) C.bool {
	goName := C.GoStringN(name, nameLen)
	if val == nil {
		return C.bool(os.Unsetenv(goName) == nil)
	}
	goVal := C.GoStringN(val, valLen)
	return C.bool(os.Setenv(goName, goVal) == nil)
}
Read path (PHP only)

`frankenphp_getenv` / SAPI `frankenphp_getenv` consult `sandboxed_env` → `prepared_env` → `main_thread_env` only. They never read live OS environ. So:

| Consumer | Sees OS putenv from other thread? |
|---|---|
| PHP `getenv` on another thread | No (sandboxed) |
| `proc_open` / `exec` child (default env) | Yes |
| C code reading libc `getenv` (e.g. an extension) | Yes |

Reset path

`reset_sandboxed_environment()` releases TLS `sandboxed_env` and `prepared_env` only. No `os.Unsetenv` / snapshot restore of the process environ.

Documentation mismatch
  • `docs/security.md`: putenv/getenv “operate on a thread-local `sandboxed_env` so concurrent threads don’t race on the global C environment.”
  • `docs/internals.md`: same claim; notes worker-mode sandbox lifetime but not OS dual-write.

Reproduced in regular (non-worker) mode: request A calls `putenv`; request B's PHP `getenv` correctly returns `false` (the sandbox works), but a `proc_open` child started by request B inherits the value from the process environment.

Frame the leak as a victim-originated secret, not an attacker setting and reading its own value. It matters when one request places a server-side secret into the environment and a *different* request's child exposes it.

Request A (victim / application path) puts a server-side secret into the environment, e.g. a framework or app doing:

<?php
// value comes from server-side config or another user's session, not the caller
putenv('APP_DB_PASSWORD=' . $serverSideSecret);

Request B (attacker-reachable path) spawns a child with the default environment and returns or acts on its output:

<?php
var_export(getenv('APP_DB_PASSWORD')); // false: PHP getenv is sandboxed
$p = proc_open('printenv APP_DB_PASSWORD', [1 => ['pipe', 'w']], $pipes);
echo stream_get_contents($pipes[1]); // the secret from request A
proc_close($p);

The negative control is the trap: PHP `getenv` on request B returns `false`, so a test that only checks PHP-level isolation passes while the OS-environ channel still leaks.

Single-thread residual: even without concurrency, after request A finishes in regular mode the OS environ still holds its keys for later requests' children until overwrite or process exit; `reset_sandboxed_environment` does not clean OS env.

Proposed fix

Each option has a trade-off; none is free.

Preferred: stop calling `os.Setenv` / `os.Unsetenv` from request-path `putenv`, keeping mutations only in TLS `sandboxed_env`. Trade-off: a child spawned in the *same* request no longer inherits values set via PHP `putenv` unless the application passes an explicit env array to `proc_open`. Document that behavior change; it is the safe default and matches per-request isolation.

Alternative: snapshot the OS environ at request start and restore it at request end. Unsafe under real concurrency: two requests on different threads clobber each other's restores. Not viable without a per-request child-env rewriter.

Tests to add:

  1. Request A `putenv('K=V')`; request B `proc_open('printenv K')` must not see `V` after the fix.
  2. PHP `getenv` sandbox tests remain green.
  3. Document the intentional child-env behavior in `docs/security.md` / `internals.md`.

Related prior work

  • Putenv/getenv override origin: env refactor #1185; sandboxed env moved to the C side in #2058.
  • FrankenPHP has treated cross-request isolation failures as security advisories before, e.g. GHSA-v3ph-cgqh-r8p5 (session state shared across requests). That case demonstrated broader confidentiality/integrity/availability impact; this one is a narrower environment channel gated on application `putenv` of sensitive data, hence Medium.
Vector CVSS 3.1

Desglose de métricas

Opción resaltada = valor del vector · izquierda = peor caso · GitHub
Vector de ataqueAV:L
RedAdyacenteLocalFísica
ComplejidadAC:H
BajaAlta
PrivilegiosPR:L
NingunoBajosAltos
InteracciónUI:N
NingunaRequerida
AlcanceS:C
CambiadoSin cambio
ConfidencialidadC:H
AltoBajoNinguno
IntegridadI:L
AltoBajoNinguno
DisponibilidadA:N
AltoBajoNinguno
Score de explotaciónQué tan fácil y probable es que la exploten
4.8/ 10Medio
Vector 4.8 (moderada) · sin evidencia de explotación.
Versiones

Rangos afectados

Afectada Corregida Última
github.com/dunglas/frankenphp≥ 1.5.0 ≤ 1.12.7
1.5.0
1.12.7
v1.13.6
Remediación

Estado del parche por paquete

Paquete / productoEstadoCorregida enDesde divulgaciónÚltima versión
gogithub.com/dunglas/frankenphp
Corregida v1.13.0 0 d v1.13.6 no afectada
Versiones corregidasv1.13.0
Explotación

Arsenal público

Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.

Referencias
Advisoryhttps://github.com/php/frankenphp/security/advisories/GHSA-996f-w38m-f574

Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.