mirror of
https://github.com/chatmail/relay.git
synced 2026-08-15 21:10:51 +00:00
feat(smtp-server): Log malformed SMTP commands (#118)
Closes #110 Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
committed by
GitHub
parent
0e1b7173ab
commit
1e356315da
@@ -1,6 +1,6 @@
|
|||||||
//! A simplified SMTP server implementation for internal communication.
|
//! A simplified SMTP server implementation for internal communication.
|
||||||
|
|
||||||
use crate::utils::extract_address;
|
use crate::utils::{extract_address, log_eml};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader, BufWriter};
|
||||||
@@ -103,7 +103,9 @@ where
|
|||||||
// Note: this will kill the connection if any line doesn't end with CRLF.
|
// Note: this will kill the connection if any line doesn't end with CRLF.
|
||||||
// This is intentional as stray LF most likely means an attempt to exploit the server.
|
// This is intentional as stray LF most likely means an attempt to exploit the server.
|
||||||
let Some(cmd) = line.strip_suffix("\r\n") else {
|
let Some(cmd) = line.strip_suffix("\r\n") else {
|
||||||
log::warn!("Malformed command without CRLF ending! Closing connection.");
|
log::warn!(
|
||||||
|
"Malformed command without CRLF ending! Received: {line:?} Closing connection."
|
||||||
|
);
|
||||||
break 'connection;
|
break 'connection;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,6 +173,15 @@ where
|
|||||||
|
|
||||||
if !data_line.ends_with("\r\n") {
|
if !data_line.ends_with("\r\n") {
|
||||||
log::warn!("Malformed DATA line without CRLF ending! Closing connection.");
|
log::warn!("Malformed DATA line without CRLF ending! Closing connection.");
|
||||||
|
data.extend_from_slice(data_line.as_bytes());
|
||||||
|
let eml_path = log_eml("malformed-data", &data)
|
||||||
|
.await
|
||||||
|
.map(|path| path.to_string_lossy().to_string())
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
log::error!("Failed to save rejected message to file: {e}");
|
||||||
|
"ERR".to_string()
|
||||||
|
});
|
||||||
|
log::info!("Rejected message stored at: {eml_path}");
|
||||||
break 'connection;
|
break 'connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user