You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
gomail.v1 has a concurrency issue when sending multiple e-mails in parallel, where the body of one e-mail gets delivered to the intended recipient of another e-mail. This can leak sensitive information, and thus is also a security issue.
The problem arises from a concurrency issue in gomail.v1 in flattenHeader:
funcflattenHeader(msg*mail.Message, bccstring) []byte {
buf:=getBuffer()
deferputBuffer(buf)
// ... (write data to buf)returnbuf.Bytes()
}
This function reserves a buffer, writes data to it, and then returns the contents.
However, after returning the contents, the buffer is recycled and can be used by another thread. The underlying bytes are shared between the recycled buffer and the []byte that is returned.
It is expected to print "bytes1 testing" followed by "bytes2 hello", but instead it prints "bytes1 hellong" followed by "bytes2 hello".
A security issue arises where the contents of an e-mail intended for one e-mail address are sent to another e-mail address. This arises because flattenHeader is used to send e-mail:
Send1 calls flattenHeader and appends the body to the same byte buffer.
Before the e-mail is sent, we call Send(...) again (Send2) for user2@example.com.
Send2 calls flattenHeader and then appends the second e-mail's body. The same byte buffer is recycled, overwriting the original contents.
Now Send1 makes the m.send call. The recipient is set to user1@example.com (since it has already been read in step 2), but the contents of the e-mail body are that of the second call (since the bytes have been overwritten).
This can easily be fixed (i.e. remove the getBuffer/putBuffer system and just create a new buffer on each call), but since this project and especially v1 is no longer maintained, a better solution is to switch to another library such as https://github.com/wneessen/go-mail
The text was updated successfully, but these errors were encountered:
uakfdotb
added a commit
to LunaNode/gomail
that referenced
this issue
Sep 7, 2024
This can result in a security issue when sending multiple e-mails in parallel
where the contents of an e-mail intended for one user are sent to another user.
See go-gomail#200 for details.
gomail.v1 has a concurrency issue when sending multiple e-mails in parallel, where the body of one e-mail gets delivered to the intended recipient of another e-mail. This can leak sensitive information, and thus is also a security issue.
The problem arises from a concurrency issue in gomail.v1 in flattenHeader:
https://github.com/go-gomail/gomail/blob/11b919ab4933936a28fb6aeda5c6523091266f37/mailer.go#L126C1-L150C2
This function reserves a buffer, writes data to it, and then returns the contents.
However, after returning the contents, the buffer is recycled and can be used by another thread. The underlying bytes are shared between the recycled buffer and the []byte that is returned.
Here is a minimal example showing the problem:
Here, the getBuffer/putBuffer logic is copied from https://github.com/go-gomail/gomail/blob/v1/gomail.go.
It is expected to print "bytes1 testing" followed by "bytes2 hello", but instead it prints "bytes1 hellong" followed by "bytes2 hello".
A security issue arises where the contents of an e-mail intended for one e-mail address are sent to another e-mail address. This arises because flattenHeader is used to send e-mail:
Here is the timeline of an example security problem:
m.send
call. The recipient is set to user1@example.com (since it has already been read in step 2), but the contents of the e-mail body are that of the second call (since the bytes have been overwritten).This can easily be fixed (i.e. remove the getBuffer/putBuffer system and just create a new buffer on each call), but since this project and especially v1 is no longer maintained, a better solution is to switch to another library such as https://github.com/wneessen/go-mail
The text was updated successfully, but these errors were encountered: