GHSA-J84H-7GW3-W75X
Message and MIME builders allow CR/LF header injection in constructed messages and MultiPart\Form field names
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:L/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-J84H-7GW3-W75X divulgada · CVSS 5.3 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Impact
The `Psl\Message` and `Psl\MIME` builders wrote caller-supplied strings into header fields without rejecting CR, LF or NUL bytes. When an application passes untrusted input to them, an attacker can end the current header line and add header fields of their choice, or add a blank line and replace the body, in the message or form the application builds.
The following construction paths were affected:
- `Message::withFrom()`, `withSender()`, `withTo()`, `withCc()`, `withBcc()` and `withReplyTo()` given a string: the address parser kept CR and LF inside the address, so a value such as `"a@example.com\r\nX-Injected: 1"`, for example a reply-to address taken from a contact form, was written out as is.
- `Message\Address\Mailbox`: the local part, domain and comment were not validated. The display name escaped `"` but not `\`, and the comment escaped nothing, so a display name or comment could close its quoting and add addresses to an address field even without CR or LF. `Group` wrote display names containing `:`, `;` or `,` without quoting them, with the same effect.
- `Message\MessageId` (used by `withMessageId()`, `withInReplyTo()` and `withReferences()`) and `MIME\ContentId`.
- `Message::withHeader()` and `MIME\Headers::fromPairs()`, `with()` and `replace()`: field names and values were not validated.
- `MIME\Parameters` values, which are written inside quoted strings: for example the filename of a `Part\Data` attachment or of `ContentDisposition::attachment()`, often the client-supplied name of an uploaded file.
- `MIME\MultiPart\Form::addField()` and `addPart()`: the field name was written into the `name` parameter of `Content-Disposition` as is, so a field name taken from user input, for example by an upload proxy, could add header lines or complete fake parts to the `multipart/form-data` body.
- `Message\parse()` kept received header values that contain a bare CR, and `serialize()` wrote them out again; `Message::reply()`, `replyAll()` and `forward()` copied such a `Message-ID` into `In-Reply-To` and `References`. Software that treats a bare CR as a line break sees an extra header field.
An attacker can add or override header fields such as `Reply-To`, `From` display names or `Content-Type`, or replace the body of a message the application sends from its own domain. If the application DKIM-signs its mail, the injected body, and any injected field that the signer includes, carry its signature. `Psl\SMTP` builds the envelope from the message's typed recipient lists and refuses commands that contain CR or LF, so injected `To`, `Cc` or `Bcc` lines do not add envelope recipients there, but software that takes recipients from the header section, such as `sendmail -t`, would deliver to them. In `multipart/form-data` bodies, the attacker can add or override the fields the receiving server sees.
The attack is remote and unauthenticated wherever an application passes untrusted input to these APIs. `withSubject()` and mailbox display names were already RFC 2047 encoded, so CR and LF there did not start a new line.
Patches
Fixed in 6.4.0 https://github.com/php-standard-library/php-standard-library/releases/tag/6.4.0.
- `Headers`, and so `Message::withHeader()`, requires field names of printable ASCII without spaces or colons and rejects values that contain CR, LF or NUL; `Message::withSubject()` rejects the same bytes.
- `Mailbox` requires RFC 5322 local parts and domains (UTF-8 allowed as in RFC 6532), rejects CR, LF and NUL in display names and comments, escapes `\` in display names and escapes `\`, `(` and `)` in comments.
- `MessageId`, `ContentId`, `Group` display names and MIME parameter values reject CR, LF and NUL, and `Group` quotes display names that contain ASCII specials.
- `MultiPart\Form` percent-encodes CR, LF and `"` in field names (`%0D`, `%0A` and `%22`), as browsers do.
- Parsers stay lenient: received header fields with invalid names or unsafe values are skipped instead of failing the whole message, and `AddressList::parse()` and `Group::parse()` gain an optional `$lenient` flag.
Workarounds
Reject CR, LF and NUL in every untrusted value before passing it to these APIs (for example with `strpbrk($value, "\r\n\0") !== false`), validate untrusted email addresses before using them as a `Mailbox` or an address string, reject or escape `\`, `"`, `(` and `)` in untrusted display names and comments, and percent-encode CR, LF and `"` in untrusted form field names before calling `Form::addField()` or `addPart()`.
References
- RFC 5322 sections 2.2, 3.2.4 and 3.4 (header fields, quoted strings and addresses)
- RFC 2045 section 5.1 and RFC 2183 (MIME parameters and Content-Disposition)
- RFC 7578 section 4.2 (multipart/form-data field names)
- https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#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/message |
Corregida | 6.4.0 | — | — |
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-j84h-7gw3-w75xLas referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
