From dbfe3c27119bac5890d34c13b18bc379465d6183 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Wed, 11 Nov 2026 12:15:28 -0700 Subject: [PATCH] Reports: take report-address mail on our domains without an account DMARC and TLS reports go to postmaster@ (the default report address) on every domain, and RCPT refused them on any domain where no account had that address, before the report could be read. An unauthenticated RCPT to a report address on one of our domains is now taken even with no account behind it. DATA reads any report in the message and then drops the address; a message that isn't a report and has no other recipient is refused there with the same 550 5.1.2 RCPT would have given. Fixes #373 --- crates/smtp/src/core/mod.rs | 6 +++ crates/smtp/src/inbound/data.rs | 25 ++++++++++ crates/smtp/src/inbound/rcpt.rs | 19 ++++++++ crates/smtp/src/inbound/session.rs | 1 + tests/src/smtp/reporting/analyze.rs | 75 +++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+) diff --git a/crates/smtp/src/core/mod.rs b/crates/smtp/src/core/mod.rs index ef409303..202ffb35 100644 --- a/crates/smtp/src/core/mod.rs +++ b/crates/smtp/src/core/mod.rs @@ -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, + // 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, } /// 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(), } } } diff --git a/crates/smtp/src/inbound/data.rs b/crates/smtp/src/inbound/data.rs index 9ac61587..a8fe8295 100644 --- a/crates/smtp/src/inbound/data.rs +++ b/crates/smtp/src/inbound/data.rs @@ -484,6 +484,9 @@ impl Session { (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 Session { .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 Session { } } + // 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); diff --git a/crates/smtp/src/inbound/rcpt.rs b/crates/smtp/src/inbound/rcpt.rs index 1eb25e09..ab640fd7 100644 --- a/crates/smtp/src/inbound/rcpt.rs +++ b/crates/smtp/src/inbound/rcpt.rs @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * 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 Session { 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), diff --git a/crates/smtp/src/inbound/session.rs b/crates/smtp/src/inbound/session.rs index 7a982eef..e191fd8f 100644 --- a/crates/smtp/src/inbound/session.rs +++ b/crates/smtp/src/inbound/session.rs @@ -514,6 +514,7 @@ impl Session { 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) { diff --git a/tests/src/smtp/reporting/analyze.rs b/tests/src/smtp/reporting/analyze.rs index b7568119..7fa26d53 100644 --- a/tests/src/smtp/reporting/analyze.rs +++ b/tests/src/smtp/reporting/analyze.rs @@ -2,6 +2,8 @@ * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * 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("john@test.org", "250").await; + session.rcpt_to("nobody@reports-local.org", "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( + "john@test.org", + &["postmaster@reports-local.org"], + "report:dmarc1", + "250", + ) + .await; + test.assert_no_events(); + let admin = test.account("admin"); + for _ in 0..50 { + if admin.registry_get_all::().await.len() == 1 { + break; + } + tokio::time::sleep(Duration::from_millis(100)).await; + } + assert_eq!( + admin.registry_get_all::().await.len(), + 1 + ); + + // Anything else to it is refused once DATA shows it isn't a report + session + .send_message( + "john@test.org", + &["postmaster@reports-local.org"], + "From: john@test.org\r\nTo: postmaster@reports-local.org\r\nSubject: hello\r\n\r\nNot a report.\r\n", + "550", + ) + .await; + test.assert_no_events(); +} -- 2.54.0