The vulnerability is an SMTP header injection flaw in Mailpit's smtpd server. The root cause lies in the smtpd.session.serve function, which inadequately validated email addresses from MAIL FROM and RCPT TO commands. The regular expression used, [^<>\v], incorrectly allowed control characters, specifically carriage returns (\r), within the address.
An attacker could exploit this by sending an SMTP command with a crafted address, such as RCPT TO:<victim\rX-Injected-Header: value>. The serve function would accept this malicious address.
Subsequently, when the email data is being processed, the serve function calls smtpd.session.makeHeaders to generate the Received header. The makeHeaders function takes the tainted recipient address and inserts it directly into the header string, causing the injected header to be written into the raw email file. The patch addresses the vulnerability at the source by introducing a new function, extractAndValidateAddress, which uses the Go standard library's net/mail.ParseAddress for strict RFC-compliant validation, thus preventing any control characters from being accepted in the email address.