GHSA-H47R-XW6C-XWWM
MIME multipart parser buffers the preamble and part header sections without limit, enabling memory exhaustion
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-H47R-XW6C-XWWM divulgada · CVSS 7.5 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Impact
`Psl\MIME\MultiPart\Parser` streams part bodies to spool handles and enforces its `maxParts` and `maxPartSize` limits, but two other sections of the input were read into memory without any limit:
- Preamble. To find the first boundary delimiter, `parse()` appended every chunk it read to a buffer and searched the whole buffer again after each 8 KiB read. The preamble before the first delimiter (RFC 2046 section 5.1.1) has no size limit and is chosen by the sender, so a body with a huge preamble, or with no boundary at all, was read into memory in full, and then copied again, before parsing started. The repeated search made the CPU cost grow with the square of the preamble size.
- Part header sections. The header section of each part was buffered until a blank line ended it, with no limit and with the same repeated search. A part whose headers never end made the parser read the rest of the input into memory. Part headers that used LF line endings had the same effect even on well-formed input, because the parser first searched the whole remaining input for a CRLF blank line.
An attacker who can submit a multipart body to an application that parses it with `MultiPart\Parser`, for example a `multipart/form-data` request body or a multipart email, can make the process allocate memory in proportion to the size of the body, and spend CPU time in proportion to its square, whatever `maxParts` and `maxPartSize` are set to. Once the process exceeds PHP's `memory_limit`, it ends with a fatal error, together with every other request it was serving. Applications that cap the size of the body before it reaches the parser limit the memory to that cap, but a cap sized for large uploads still lets a single request exhaust memory. The attacker needs no privileges beyond whatever the application requires to submit a body.
PSL does not call the parser itself; applications that call it on untrusted input are affected.
Patches
Fixed in 6.4.0 https://github.com/php-standard-library/php-standard-library/releases/tag/6.4.0.
- The preamble is skipped in constant memory: between reads, only the last `strlen($delimiter) - 1` bytes are kept, which is enough to find a delimiter split across two reads.
- The new constructor argument `$maxHeaderSize` (16 KiB by default, 0 for unlimited) bounds each part header section. A larger section fails with `MultiPartException` after at most the limit plus one read chunk has been buffered. Part header sections larger than 16 KiB are now rejected unless a larger limit is passed.
- A part header section ends at its first blank line, whether CRLF or LF, instead of the rest of the input being searched for a CRLF blank line first.
- The `maxParts` limit is enforced as soon as a delimiter shows that another part follows, before any of the extra part is read.
Workarounds
Bound the input before the parser sees it: wrap the handle in `Psl\IO\BoundedReadHandle` with the largest body you accept, or enforce a request body size limit in the web server or proxy in front of the application. This caps memory use at that limit but does not restore a per-section limit, so keep it as small as the application allows.
References
- RFC 2046 section 5.1.1 (multipart common syntax, preamble and body part headers)
- RFC 7578 (`multipart/form-data`)
- https://github.com/php-standard-library/php-standard-library/releases/tag/6.4.0
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistphp-standard-library/mime |
Corregida | 6.4.0 | — | — |
Packagistphp-standard-library/php-standard-library |
Corregida | 6.4.0 | — | — |
6.4.0Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/php-standard-library/php-standard-library/security/advisories/GHSA-h47r-xw6c-xwwmLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
