author | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-10-25 19:42:08 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2016-11-01 23:56:04 UTC |
parent | 8cbc4f9ca68485bd978e4f14a81453afa498de46 |
internal/smtpsrv/conn.go | +9 | -2 |
test/t-09-loop/run.sh | +1 | -0 |
diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go index 877475d..29920f4 100644 --- a/internal/smtpsrv/conn.go +++ b/internal/smtpsrv/conn.go @@ -5,6 +5,7 @@ import ( "context" "crypto/tls" "expvar" + "flag" "fmt" "io" "io/ioutil" @@ -44,6 +45,11 @@ var ( hookResults = expvar.NewMap("chasquid/smtpIn/hookResults") ) +var ( + maxReceivedHeaders = flag.Int("testing__max_received_headers", 50, + "max Received headers, for loop detection; ONLY FOR TESTING") +) + // Mode for a socket (listening or connection). // We keep them distinct, as policies can differ between them. type SocketMode string @@ -619,9 +625,10 @@ func checkData(data []byte) error { // This serves as a basic form of loop prevention. It's not infallible but // should catch most instances of accidental looping. // https://tools.ietf.org/html/rfc5321#section-6.3 - if len(msg.Header["Received"]) > 50 { + if len(msg.Header["Received"]) > *maxReceivedHeaders { loopsDetected.Add(1) - return fmt.Errorf("email passed through more than 50 MTAs, looping?") + return fmt.Errorf("email passed through more than %d MTAs, looping?", + *maxReceivedHeaders) } return nil diff --git a/test/t-09-loop/run.sh b/test/t-09-loop/run.sh index 3c51145..efddcb7 100755 --- a/test/t-09-loop/run.sh +++ b/test/t-09-loop/run.sh @@ -22,6 +22,7 @@ CONFDIR=B generate_certs_for srv-B mkdir -p .logs-A .logs-B chasquid -v=2 --logfile=.logs-A/chasquid.log --config_dir=A \ + --testing__max_received_headers=5 \ --testing__outgoing_smtp_port=2025 & chasquid -v=2 --logfile=.logs-B/chasquid.log --config_dir=B \ --testing__outgoing_smtp_port=1025 &