The vulnerability lies in the form-data library's handling of field names and filenames when constructing multipart/form-data payloads. The root cause is the lack of escaping for Carriage Return (CR) and Line Feed (LF) characters in the field and filename parameters. An attacker can supply a specially crafted string containing \r\n to the FormData.prototype.append function. This input is then used by the internal functions FormData.prototype._multiPartHeader and FormData.prototype._getContentDisposition to construct the Content-Disposition header. Because the input is not sanitized, the CRLF characters are interpreted as the end of a header line, allowing the attacker to inject new headers or even new multipart body parts. This can lead to various security issues, such as session fixation, cross-site scripting (XSS) if the backend reflects the headers, or bypassing security controls by injecting fields like is_admin=true.
The patch addresses this by introducing a new function, escapeHeaderParam, which escapes \r, \n, and " characters in the field name and filename before they are included in the header. The vulnerable functions _multiPartHeader and _getContentDisposition were modified to use this new escaping function, thus mitigating the CRLF injection vulnerability.