VulnWatch by ve1ve2
medium 5.3 EPSS 0.93%

GHSA-9pqp-7h25-4f32 / CVE-2024-8925: Erroneous parsing of multipart form data

Source:
PHP releases (GitHub php/php-src tags)
Published:
Fetched:
Updated:
Affects:
php php-src

https://github.com/php/php-src/security/advisories/GHSA-9pqp-7h25-4f32 ↗

repo-advisoryCWE-1286securityrepo:php/php-srcstack

Erroneous parsing of multipart form data ### Summary Erroneous parsing of multipart form data contained in an HTTP POST request could lead to legitimate data not being processed thus, violating data integrity. ### Details A bug was discovered in the parsing of multipart form data contents, affecting both file and input form data. If a multipart form data payload contains a valid prefix `X` of the defined boundary `B` such that `5Kib` < `|X|` < `|B|` < `8Kib`, the logic responsible for parsing and storing the multipart payload fails to correctly extract the contents between two boundaries. This results in a violation of data integrity. The issue lies in the partial match handling in the following function: ```c // main/rfc1867.c:556 /* * Search for a string in a fixed-length byte string. * If partial is true, partial matches are allowed at the end of the buffer. * Returns NULL if not found, or a pointer to the start of the first match. */ static void *php_ap_memstr(char *haystack, int haystacklen, char *needle, int needlen, int partial) { int len = haystacklen; char *ptr = haystack; /* iterate through first character matches */ while( (ptr = memchr(ptr, needle[0], len)) ) { /* calculate length after match */ len = haystacklen - (ptr - (char *)haystack); // if (memcmp(needle, ptr, needlen < len ? needlen : len) == 0 && (partial || len >= needlen)) { // partial match here if partial != 0 break; } /* next character */ ptr++; len--; } return ptr; } ``` This is called by the following functions when the contents between two boundaries have to be extracted after parsing the MIME headers: ```c // main/rfc1867.c:580 static size_t multipart_buffer_read(multipart_buffer *self, char *buf, size_t bytes, int *end) { size_t len, max; char *bound; /* fill buffer if needed */ if (bytes > (size_t)self->bytes_in_buffer) { fill_buffer(self); } int i=0; while (self->buf_begin[i] && self->buf_begin[i] != '\r' ) i++; /* look for a potential boundary match, only read data up to that point */ if ((bound = php_ap_memstr(self->buf_begin, self->bytes_in_buffer, self->boundary_next, self->boundary_next_len, 1))) { // partial match on max = bound - self->buf_begin; if (end && php_ap_memstr(self->buf_begin, self->bytes_in_buffer, self->boundary_next, self->boundary_next_len, 0)) { *end = 1; } } else { max = self->bytes_in_buffer; } /* maximum number of bytes we are reading */ len = max < bytes-1 ? max : bytes-1; /* if we read any data... */ if (len > 0) { /* copy the data */ memcpy(buf, self->buf_begin, len); buf[len] = 0; if (bound && len > 0 && buf[len-1] == '\r') { buf[--len] = 0; } /* update the buffer */ self->bytes_in_buffer -= (int)len; self->buf_begin += len; } return len; } /* XXX: this is horrible memory-usage-wise, but we only expect to do this on small pieces of form data. */ static char *multipart_buffer_read_body(multipart_buffer * Patched: 8.1.30, 8.2.24, 8.3.12

Linked vulnerabilities (2)

CVE-2024-8925 medium 5.3 EPSS 0.93% (p61) NVDCVE.orgGHSA
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N

php8.2 - security update

CWE: CWE-1286Aliases: CVE-2024-8926, CVE-2024-8927, CVE-2024-9026, GHSA-9pqp-7h25-4f32
CVSS:3.1/AV:N/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N

Erroneous parsing of multipart form data

CWE: CWE-1286Aliases: CVE-2024-8925