GHSA-868C-7H7M-MMJ9
Windows document-root escape in `sanitizedPathJoin` (SCRIPT_FILENAME)
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-868C-7H7M-MMJ9 divulgada · CVSS 8.1 (GitHub) | |
| Divulgación | Modificada | Última actualización del registro | |
| 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 |
Summary
On Windows, FrankenPHP’s CGI path join helper (`sanitizedPathJoin`) does not keep request-derived paths under the configured document root. A remote client can craft a URL path such that `SCRIPT_FILENAME` (and `PATH_TRANSLATED`) resolve to an absolute filesystem path outside the web root. If a PHP file exists at that location, the SAPI executes it.
This is the same failure class Caddy already fixed in `caddyhttp.SanitizedPathJoin` (`path.Clean` + `filepath.IsLocal` + `filepath.FromSlash`). FrankenPHP still uses the older `filepath.Join(root, filepath.Clean("/"+reqPath))` form adapted from historical FastCGI code.
Impact
- Wrong-file PHP execution relative to the document-root trust boundary (potential RCE when an outside `.php` is reachable on disk).
- Path disclosure / sensitive file targeting via `PATH_TRANSLATED` and apps that open it.
- Who is affected: any Windows deployment of FrankenPHP (standalone binary, Windows packages, embedders calling `ServeHTTP` / `NewRequestWithContext` with a Windows document root). Default `php_server` `try_files` may reduce exposure when Caddy never forwards a traversable path; library mode and bare `php` are fully exposed.
Details
Vulnerable code
`cgi.go` (current `main`):
func sanitizedPathJoin(root, reqPath string) string {
if root == "" {
root = "."
}
path := filepath.Join(root, filepath.Clean("/"+reqPath))
// trailing-slash restore omitted
return path
}Call sites:
- `splitCgiPath` → `fc.scriptFilename = sanitizedPathJoin(fc.documentRoot, fc.scriptName)` (drives `php_execute_script`).
- `go_update_request_info` → `path_translated = sanitizedPathJoin(fc.documentRoot, fc.pathInfo)`.
Why Windows breaks
For a normal absolute URL path `/../../outside/shell.php`:
- `"/"+reqPath` → `"//../../outside/shell.php"`.
- On Windows, `filepath.Clean` of that form does not produce a simple root-relative segment the way Unix does (UNC / volume handling keeps `..` material that later recombines badly).
- `filepath.Join` with a drive-absolute root then applies `..` against real directories and exits the document root.
Caddy’s fixed algorithm (v2.11.4 `modules/caddyhttp/caddyhttp.go`):
relPath := path.Clean("/" + reqPath)[1:] // slash-only clean, drop leading /
if relPath != "" && !filepath.IsLocal(relPath) {
return root
}
return filepath.Join(root, filepath.FromSlash(relPath))PoC
A. Stdlib-only (no FrankenPHP binary)
# mirrors cgi.go sanitizedPathJoin under Windows filepath rules
GOOS=windows go run ss001-windows-path-poc.goObserved:
in="/index.php" out="C:\inetpub\wwwroot\index.php" under_root=true
in="/../../outside/shell.php" out="C:\outside\shell.php" under_root=false
in="/../Windows/win.ini" out="C:\inetpub\Windows\win.ini" under_root=falseEvidence file in this audit dir: `ss001-windows-path-poc.go`.
B. Full stack (Windows host)
- Install FrankenPHP for Windows; set document root to e.g. `C:\app\public` with a normal `index.php`.
- Place a marker script outside the root, e.g. `C:\outside\shell.php` containing `<?php echo "ESCAPED\n";`.
- Use bare `php` (no `try_files`) or the Go library API so the request path is not rewritten away:
```
GET /../../outside/shell.php HTTP/1.1
Host: localhost
```
- Response body is `ESCAPED` (or whatever the outside script prints).
Unix control: the same URL must stay under the document root.
Proposed fix
Replace `sanitizedPathJoin` with Caddy’s algorithm (or factor a shared helper). Add Windows unit tests covering at least:
- `/..\windows\win.ini`
- deep `..` chains
- drive-letter / absolute second-segment probes
Related prior work
- Caddy `SanitizedPathJoin` + `filepath.IsLocal` (Go issue discussion https://github.com/golang/go/issues/56336).
- FrankenPHP already hardens Unicode path-split (GHSA-3g8v-8r37-cgjm / GHSA-g966-83w7-6w38); this is a separate Windows join bug.
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 |
|---|---|---|---|---|
gogithub.com/dunglas/frankenphp |
Corregida | v1.13.0 | 0 d | v1.13.6 no afectada |
v1.13.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/php/frankenphp/security/advisories/GHSA-868c-7h7m-mmj9Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
