mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-08-08 04:18:53 +00:00
chasquid: Detect email loops
This patch implements some measures against email loops, such as keeping a limit on the lenght of an address, and rejecting email that has too many Received headers. It's not perfect (a server could be actively removing Received headers), but it should cover the normal accidents and misconfigurations.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
# Ignore the user databases - we create them each time.
|
||||
t-*/config/**/users
|
||||
t-*/?/**/users
|
||||
|
||||
|
||||
@@ -13,13 +13,13 @@ chasquid -v=2 --log_dir=.logs --config_dir=config &
|
||||
wait_until_ready 1025
|
||||
|
||||
function send_and_check() {
|
||||
run_msmtp $1@testserver < content
|
||||
shift
|
||||
for i in $@; do
|
||||
wait_for_file .mail/$i@testserver
|
||||
mail_diff content .mail/$i@testserver
|
||||
rm -f .mail/$i@testserver
|
||||
done
|
||||
run_msmtp $1@testserver < content
|
||||
shift
|
||||
for i in $@; do
|
||||
wait_for_file .mail/$i@testserver
|
||||
mail_diff content .mail/$i@testserver
|
||||
rm -f .mail/$i@testserver
|
||||
done
|
||||
}
|
||||
|
||||
# Test email aliases.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
smtp_address: ":1025"
|
||||
submission_address: ":1587"
|
||||
monitoring_address: ":1099"
|
||||
|
||||
mail_delivery_agent_bin: "test-mda"
|
||||
mail_delivery_agent_args: "%to%"
|
||||
|
||||
data_dir: "../.data-A"
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
aliasA: aliasB@srv-B
|
||||
@@ -0,0 +1,8 @@
|
||||
smtp_address: ":2025"
|
||||
submission_address: ":2587"
|
||||
monitoring_address: ":2099"
|
||||
|
||||
mail_delivery_agent_bin: "test-mda"
|
||||
mail_delivery_agent_args: "%to%"
|
||||
|
||||
data_dir: "../.data-B"
|
||||
@@ -0,0 +1 @@
|
||||
aliasB: aliasA@srv-A
|
||||
@@ -0,0 +1,9 @@
|
||||
From: userA@srv-A
|
||||
To: aliasB@srv-B
|
||||
Subject: Los espejos
|
||||
|
||||
Yo que sentí el horror de los espejos
|
||||
no sólo ante el cristal impenetrable
|
||||
donde acaba y empieza, inhabitable,
|
||||
un imposible espacio de reflejos
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
srv-A localhost
|
||||
srv-B localhost
|
||||
@@ -0,0 +1,14 @@
|
||||
account default
|
||||
|
||||
host srv-A
|
||||
port 1587
|
||||
|
||||
tls on
|
||||
tls_trust_file A/certs/srv-A/fullchain.pem
|
||||
|
||||
from userA@srv-A
|
||||
|
||||
auth on
|
||||
user userA@srv-A
|
||||
password userA
|
||||
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
. $(dirname ${0})/../util/lib.sh
|
||||
|
||||
init
|
||||
|
||||
rm -rf .data-A .data-B .mail
|
||||
|
||||
# Two servers:
|
||||
# A - listens on :1025, hosts srv-A
|
||||
# B - listens on :2015, hosts srv-B
|
||||
#
|
||||
# We cause the following loop:
|
||||
# userA -> aliasB -> aliasA -> aliasB -> ...
|
||||
|
||||
CONFDIR=A generate_certs_for srv-A
|
||||
CONFDIR=A add_user srv-A userA userA
|
||||
|
||||
CONFDIR=B generate_certs_for srv-B
|
||||
|
||||
mkdir -p .logs-A .logs-B
|
||||
|
||||
chasquid -v=2 --log_dir=.logs-A --config_dir=A \
|
||||
--testing__outgoing_smtp_port=2025 &
|
||||
chasquid -v=2 --log_dir=.logs-B --config_dir=B \
|
||||
--testing__outgoing_smtp_port=1025 &
|
||||
|
||||
wait_until_ready 1025
|
||||
wait_until_ready 2025
|
||||
|
||||
run_msmtp aliasB@srv-B < content
|
||||
|
||||
# Wait until one of them has noticed and stopped the loop.
|
||||
while sleep 0.1; do
|
||||
wget -q -O .data-A/vars http://localhost:1099/debug/vars
|
||||
wget -q -O .data-B/vars http://localhost:2099/debug/vars
|
||||
if grep -q '"chasquid/smtpIn/loopsDetected": 1,' .data-?/vars; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
success
|
||||
Reference in New Issue
Block a user