Reports: take report-address mail on our domains without an account #379

Merged
jcoffey-dev merged 1 commits from feat/report-address-no-mailbox into main 2026-11-11 19:28:45 +00:00
5 changed files with 126 additions and 0 deletions

No files matched your search

+6
View File
@@ -112,6 +112,10 @@ pub struct SessionData {
// inbuxa: RL-23: a message a relay took on port 25, judged here as if
// this server had taken the session
pub relayed: Option<Relayed>,
// inbuxa (#373): recipients RCPT took only because they are report
// addresses on one of our domains; no account has them, so DATA drops
// them once any report in the message has been read
pub report_only_rcpts: Vec<String>,
}
/// inbuxa: RL-23: what a relay saw of the session it took a message in.
@@ -217,6 +221,7 @@ impl SessionData {
journal_added: Vec::new(),
access_token: None,
relayed: None,
report_only_rcpts: Vec::new(),
}
}
}
@@ -347,6 +352,7 @@ impl SessionData {
journal_added: Vec::new(),
access_token: None,
relayed: None,
report_only_rcpts: Vec::new(),
}
}
}
+25
View File
@@ -484,6 +484,9 @@ impl<T: SessionStream> Session<T> {
(None, None)
};
// inbuxa (#373): report addresses RCPT took with no account behind them
let report_only = std::mem::take(&mut self.data.report_only_rcpts);
// Analyze reports
if is_report && ReportData::is_present(&parsed_message) {
if !rc.analysis.forward {
@@ -491,6 +494,12 @@ impl<T: SessionStream> Session<T> {
.rcpt_to
.retain(|rcpt| !rc.analysis.is_report_address(rcpt.orig_address()));
}
if !report_only.is_empty() {
// Even when reports are forwarded, there is no one to forward these to
self.data
.rcpt_to
.retain(|rcpt| !report_only.contains(&rcpt.address_lcase));
}
if self.data.rcpt_to.is_empty() {
self.server.analyze_report(
@@ -527,6 +536,22 @@ impl<T: SessionStream> Session<T> {
}
}
// inbuxa (#373): anything other than a report to an address with no
// account is refused as RCPT would have refused it
if !report_only.is_empty() {
self.data
.rcpt_to
.retain(|rcpt| !report_only.contains(&rcpt.address_lcase));
if self.data.rcpt_to.is_empty() {
trc::event!(
Smtp(SmtpEvent::MailboxDoesNotExist),
SpanId = self.data.session_id,
To = report_only,
);
return (b"550 5.1.2 Mailbox does not exist.\r\n"[..]).into();
}
}
// Add Received header
let message_id = self.server.inner.data.queue_id_gen.generate();
let mut headers = Vec::with_capacity(64);
+19
View File
@@ -2,6 +2,8 @@
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*
* Modified by Coffey Labs in 2026 for INBUXA.
*/
use crate::{
@@ -218,6 +220,23 @@ impl<T: SessionStream> Session<T> {
Ok(RcptResolution::Expand(members)) => {
rcpt_members = Some(members);
}
// inbuxa (#373): DMARC and TLS reports go to postmaster@ (or
// whatever the report addresses say) on every domain, and an admin
// shouldn't need an account for each. Take them from senders who
// haven't signed in; DATA reads the report and drops the address.
Ok(RcptResolution::UnknownRecipient)
if !self.is_authenticated()
&& self
.server
.core
.smtp
.report
.analysis
.is_report_address(&rcpt.address_lcase) =>
{
let address = rcpt.address_lcase.clone();
self.data.report_only_rcpts.push(address);
}
Ok(RcptResolution::UnknownRecipient) => {
trc::event!(
Smtp(SmtpEvent::MailboxDoesNotExist),
+1
View File
@@ -514,6 +514,7 @@ impl<T: AsyncWrite + AsyncRead + Unpin> Session<T> {
self.data.mailflow_queue = None;
self.data.journal_marks.clear();
self.data.journal_added.clear();
self.data.report_only_rcpts.clear();
}
pub fn reset_tls(&mut self) {
+75
View File
@@ -2,6 +2,8 @@
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*
* Modified by Coffey Labs in 2026 for INBUXA.
*/
use crate::{smtp::session::TestSession, utils::server::TestServerBuilder};
@@ -374,3 +376,76 @@ fn zip(
out
}
// INBUXA (#373): a report to postmaster@ on one of our domains is taken and
// read even when no account has that address; nothing else gets through.
#[tokio::test(flavor = "multi_thread")]
async fn report_to_address_without_account() {
let mut test = TestServerBuilder::new("smtp_report_no_account_test")
.await
.with_http_listener(19060)
.await
.capture_queue()
.build()
.await;
let admin = test.account("admin");
admin.find_or_create_domain("reports-local.org").await;
admin
.registry_create_object(ReportSettings {
inbound_report_addresses: Map::new(vec!["postmaster@*".to_string()]),
inbound_report_forwarding: true,
inbound_report_max_size: MAX_REPORT_SIZE,
..Default::default()
})
.await;
admin.mta_no_auth().await;
admin.mta_allow_non_fqdn().await;
admin.reload_settings().await;
test.reload_core();
test.expect_reload_settings().await;
let mut session = test.new_mta_session();
session.data.remote_ip_str = "10.0.0.1".into();
session.eval_session_params().await;
session.ehlo("mx.test.org").await;
// An address that isn't a report address is still refused at RCPT
session.mail_from("[email protected]", "250").await;
session.rcpt_to("[email protected]", "550").await;
session.cmd("RSET", "250").await;
// A report is read, and nothing is queued for the missing mailbox,
// even with forwarding on
session
.send_message(
"[email protected]",
&["[email protected]"],
"report:dmarc1",
"250",
)
.await;
test.assert_no_events();
let admin = test.account("admin");
for _ in 0..50 {
if admin.registry_get_all::<DmarcExternalReport>().await.len() == 1 {
break;
}
tokio::time::sleep(Duration::from_millis(100)).await;
}
assert_eq!(
admin.registry_get_all::<DmarcExternalReport>().await.len(),
1
);
// Anything else to it is refused once DATA shows it isn't a report
session
.send_message(
"[email protected]",
&["[email protected]"],
"From: [email protected]\r\nTo: [email protected]\r\nSubject: hello\r\n\r\nNot a report.\r\n",
"550",
)
.await;
test.assert_no_events();
}