Security:
- SMTP smuggling (CVE-2023-51764 family): only <CRLF>.<CRLF> ends DATA
(strict CRLF framing); bare CR/LF in the text is stored as CR LF.
Before, '<LF>.<LF>' and four other variants ended the message and the
rest ran as fresh commands - a second, forged message was delivered.
- STARTTLS on port 25 (RFC 3207), using the configured tls cert; AUTH
is only offered/accepted once encrypted (538 5.7.11 otherwise).
- The 250 reply no longer discloses the queue file's full path.
- Queue file names %-encode the addresses ('/' or '|' in an address
broke the name or pointed it into another directory).
Conformance (RFC 5321, 1870, 2034, 2920, 3207, 3463, 3848, 4616, 4954,
6152):
- 500 for unknown/empty/over-long commands (no reply at all before -
clients hung); 501 for missing/invalid arguments (bare MAIL/RCPT/HELO
were out-of-bounds reads).
- HELO/EHLO required before MAIL; nested MAIL refused; EHLO/HELO/RSET/
end-of-DATA reset the transaction.
- MAIL: SIZE= (552 when over the limit), BODY=7BIT|8BITMIME, AUTH=;
555 for anything else; case-insensitive keywords; address syntax
checked.
- RCPT: postmaster (bare and any case) accepted; case-insensitive
domain and local-part; 550 5.1.1 unknown user vs 550 5.7.1 relay
denied; aliases accepted (they were rejected at RCPT before); 1000
recipient cap (452 4.5.3).
- ENHANCEDSTATUSCODES advertised and used on every reply.
- AUTH PLAIN added alongside LOGIN; strict base64; 535 5.7.8 on
failure; 503 before EHLO, during a transaction, or when already
authenticated (the last one sent no reply before).
- Received: per RFC 5321 4.4 with client IP, protocol per RFC 3848
(ESMTP/ESMTPS/ESMTPSA) and queue id; Return-Path: added at local
delivery.
tests/smtp_conformance.py: 112 checks. origin/master passes 37 of the
72 it can reach before the server stops answering; this passes 112/112.
tests/imap_pop3_regression.py: IMAPS/POP3S unaffected (3/3).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0121tAhQVe4qbCwYgVjKQS4B
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
# include "SMTPSession.h"
|
|
# include "SMTPServer.h"
|
|
# include "Log.h"
|
|
|
|
namespace mail {
|
|
|
|
SMTPSession::SMTPSession(core::EPoll &ePoll, core::TCPServer &server)
|
|
: TCPSession(ePoll, &server, "SMTP Client Session") {
|
|
// Only CR LF ends a line - see core::TCPSocket::strictCRLF. This is
|
|
// what closes SMTP smuggling: "<LF>.<LF>" (or any other bare CR/LF
|
|
// variant) inside a message is message text, never end-of-data.
|
|
strictCRLF = true;
|
|
// Upper bound for one line of either a command or message text.
|
|
// RFC 5322 2.1.1 caps a message line at 998 characters; this is far
|
|
// above that and exists only so a peer that never sends CR LF can't
|
|
// grow the line buffer without limit.
|
|
maxLineLength = 1024 * 1024;
|
|
}
|
|
|
|
void SMTPSession::onConnected() {
|
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "onConnected -> sending 220";
|
|
// RFC 5321 4.2 requires the greeting to name the server's own
|
|
// domain - the literal "localhost" was hardcoded here regardless
|
|
// of the hostName this server was actually configured with.
|
|
out << "220 " << ((SMTPServer *)server)->hostName << " ESMTP BARANTMail" << CRLF;
|
|
}
|
|
|
|
void SMTPSession::resetTransaction() {
|
|
from = "";
|
|
recipientList.clear();
|
|
mailData = "";
|
|
mode = WAIT_FOR_DATA;
|
|
state = greeted ? READY : CONNECT;
|
|
spfHeader.clear();
|
|
spfDomain.clear();
|
|
spfResult = SPFChecker::Result::None;
|
|
dataLineTooLong = false;
|
|
queueId.clear();
|
|
}
|
|
|
|
void SMTPSession::resetAll() {
|
|
greeted = false;
|
|
esmtp = false;
|
|
resetTransaction();
|
|
clientDomainName = "";
|
|
userName = "";
|
|
password = "";
|
|
authState = USER_UNKNOWN;
|
|
relay = false;
|
|
}
|
|
|
|
void SMTPSession::protocol(coreutils::ZString &data) {
|
|
if (grab == NULL && data.getLength() > maxCommandLine) {
|
|
out << "500 5.5.6 Line too long" << CRLF;
|
|
return;
|
|
}
|
|
if (!server->commands.processRequest(data, *this))
|
|
out << "500 5.5.2 Syntax error, command unrecognized" << CRLF;
|
|
}
|
|
|
|
void SMTPSession::onLineTooLong() {
|
|
if (mode == RECEIVE_DATA) {
|
|
// Can't reply in the middle of DATA (the client isn't reading
|
|
// until it has sent the terminator) - remember it and reject the
|
|
// message when the terminator arrives.
|
|
dataLineTooLong = true;
|
|
} else {
|
|
out << "500 5.5.6 Line too long" << CRLF;
|
|
send();
|
|
}
|
|
}
|
|
|
|
}
|