GHSA-JWVC-HJ95-82HH
Host Confusion via Incomplete Bracketed Host Validation in guzzlehttp/psr7
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-JWVC-HJ95-82HH divulgada · CVSS 4.8 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
In affected versions, `GuzzleHttp\Psr7\Uri` accepts a bracketed host that continues after its closing bracket, such as `[::1]:8080]`. `Uri::getHost()` returns that whole text and `Uri::getPort()` the URI's own port, while a transport that reads the authority itself, such as PHP's stream wrapper, takes the first `]` as the end of the host and connects to `::1` on port `8080`. The issue is fixed in `2.13.4`.
Details
Since `2.12.3`, the first release to check brackets at all, `Uri::assertValidHost()` requires a host that contains a bracket to begin with `[` and end with `]`, but not that the first `]` is the last. GHSA-c2w2-prh8-qm98 described that release as rejecting a host with an embedded port; this form embeds one after the bracketed literal and passed the check. `Uri::withHost()` and `Uri::fromParts()` accept it as given, and so does `Request` when it generates a `Host` header from another `UriInterface` implementation. A URI string carries it when the authority has userinfo or the URI is a network-path reference: `http://user@[::1]:8080]:80/` and `//[::1]:8080]:80/` both give the host `[::1]:8080]`, in every release before `2.13.4`. From `2.12.3` to `2.13.3` the parser also decodes a percent-encoded bracket after it has matched the host, so `http://[::1%5D:8080]/` gives the same host; that route was introduced by the fix for GHSA-c2w2-prh8-qm98.
PHP's stream transport reads `tcp://[::1]:8080]:80` as host `::1`, port `8080`, and its `http` wrapper does the same with the URI string. libcurl `7.52.1` also connects to the inner port; `7.61.1`, `7.64.0`, `7.74.0` and `8.14.1` reject the URL.
This is a summary; the patches are the authority. The issue is fixed in `2.13.4`, which rejects a host whose first `]` is not its last character: `Uri::withHost()` throws `InvalidArgumentException`, and parsing and `Uri::fromParts()` throw `MalformedUriException`. Bracketed hosts that end at their closing bracket stay accepted on the 2 line even when they do not enclose an IPv6 address, as GHSA-c2w2-prh8-qm98 documented: `[127.0.0.1]`, `[localhost]` and `[gggg::1]` are stored as written. A transport may read them its own way: PHP's stream transport connects to `127.0.0.1` and `localhost` for the first two. `guzzlehttp/psr7` 3 is not affected, because it already has stronger input validation, introduced as part of a breaking change: since `3.0.0`, `Uri` accepts a bracketed host only if it is an IPv6 or IPvFuture literal. Versions before `2.13.4` are affected; `1.x` is end-of-life and will not receive a patch.
Proof of concept
A vulnerable flow, reproduced over a real socket on `2.13.3`, is:
- An application builds a `Uri` from an untrusted URL and checks `getHost()` and `getPort()` before fetching: it refuses loopback and private addresses, for example, or allows only ports 80 and 443.
- The attacker supplies `http://user@[127.0.0.1]:6379]:80/`.
- `Uri::getHost()` returns `[127.0.0.1]:6379]` and `Uri::getPort()` returns `null`. The host is not an IP address, and the port appears to be the default.
- The application opens the URI with PHP's stream wrapper, as in `fopen((string) $uri, 'r')`.
- PHP connects to `127.0.0.1` on port `6379` and sends the request with `Host: [127.0.0.1]:6379]`.
Impact
An attacker who controls a URI, or a host passed to `Uri::withHost()`, can make an application decide on one host and port while the request goes to another, and so reach a destination that its check excluded. `guzzlehttp/psr7` opens no connection itself, so the outcome depends on the component that sends the request. `guzzlehttp/guzzle` 7 is affected through its stream handler, and `7.16.3` (GHSA-hpvq-6rrx-pc47) rejects these hosts in its handlers as well.
Exploitation requires the application to build a `Uri` from untrusted input, to rely on `getHost()` or `getPort()` for a security decision, and to send the request with a transport that takes the first `]` as the end of the host. Applications that only handle URIs they construct themselves, that compare the host with an exact allowlist, or whose transport rejects the URL are not affected.
If you cannot upgrade, reject any `Uri` whose `getHost()` contains a `]` anywhere but at its end before acting on it.
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 |
|---|---|---|---|---|
Packagistguzzlehttp/psr7 |
Corregida | 2.13.4 | — | — |
2.13.4Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/guzzle/psr7/security/advisories/GHSA-jwvc-hj95-82hhLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
