From 79fe51b206a5fb23e0e7b596dd74c0947edf22b1 Mon Sep 17 00:00:00 2001 From: tgiachi Date: Tue, 10 Nov 2026 11:52:30 +0100 Subject: [PATCH] fix(router): drop incoming List-Help/Archive/Owner/Subscribe, DKIM-Signature, Authentication-Results and ARC-* - Add the four list-management headers to the list that is already stripped on the way in. - Drop the author's DKIM-Signature (broken by our header and From changes) and any Authentication-Results / ARC-* header from outside. - Tests: every dropped header, repeated ARC headers, and similarly named headers kept. --- internal/router/headers.go | 11 +++++++++- internal/router/m2_test.go | 43 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/internal/router/headers.go b/internal/router/headers.go index 8847dea..e0e2e02 100644 --- a/internal/router/headers.go +++ b/internal/router/headers.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "net/mail" + "strings" "github.com/emersion/go-message/textproto" @@ -22,9 +23,17 @@ func rewrite(l store.List, data []byte) ([]byte, error) { } // Never trust list headers coming from outside. - for _, k := range []string{"List-Id", "List-Post", "List-Unsubscribe", "List-Unsubscribe-Post", "Precedence"} { + for _, k := range []string{"List-Id", "List-Post", "List-Unsubscribe", "List-Unsubscribe-Post", "Precedence", + "List-Help", "List-Archive", "List-Owner", "List-Subscribe", + // The author's signature and authentication results do not survive our changes: they only confuse receivers. + "DKIM-Signature", "Authentication-Results"} { h.Del(k) } + for f := h.Fields(); f.Next(); { + if strings.HasPrefix(strings.ToLower(f.Key()), "arc-") { + f.Del() + } + } id := l.Name + "." + l.Domain h.Set("List-Id", fmt.Sprintf("%s <%s>", l.Title, id)) diff --git a/internal/router/m2_test.go b/internal/router/m2_test.go index 1a1d1c6..25c3578 100644 --- a/internal/router/m2_test.go +++ b/internal/router/m2_test.go @@ -435,3 +435,46 @@ func TestIncomingListHeadersAreStripped(t *testing.T) { t.Errorf("Precedence = %v", h["Precedence"]) } } + +func TestIncomingListManagementAndAuthenticationHeadersAreStripped(t *testing.T) { + r := setup(t) + msg := "From: Alice \r\n" + + "List-Help: \r\nList-Archive: \r\n" + + "List-Owner: \r\nList-Subscribe: \r\n" + + "DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=x; h=from; bh=aa; b=bb\r\n" + + "Authentication-Results: mx.example.com; dkim=pass\r\n" + + "ARC-Seal: i=1; a=rsa-sha256; cv=none; d=example.com; s=x; b=cc\r\n" + + "ARC-Message-Signature: i=1; a=rsa-sha256; d=example.com; s=x; b=dd\r\n" + + "ARC-Authentication-Results: i=1; mx.example.com; dkim=pass\r\n" + + "Subject: hi\r\n\r\nx\r\n" + res, err := r.Route("alice@example.com", "dev@example.org", []byte(msg)) + if err != nil { + t.Fatal(err) + } + h := header(t, res.Data) + for _, k := range []string{"List-Help", "List-Archive", "List-Owner", "List-Subscribe", "DKIM-Signature", + "Authentication-Results", "ARC-Seal", "ARC-Message-Signature", "ARC-Authentication-Results"} { + if v := h.Get(k); v != "" { // Get canonicalizes the key + t.Errorf("%s survived: %v", k, v) + } + } + if h.Get("Subject") != "hi" { + t.Errorf("unrelated headers must stay: %v", h) + } +} + +func TestDroppingARCHeadersKeepsSimilarlyNamedOnes(t *testing.T) { + r := setup(t) + msg := "From: Alice \r\nARC-Seal: i=1\r\nArcade: keep\r\nX-ARC-Note: keep\r\nARC-Seal: i=2\r\n\r\nx\r\n" + res, err := r.Route("alice@example.com", "dev@example.org", []byte(msg)) + if err != nil { + t.Fatal(err) + } + h := header(t, res.Data) + if v := h["Arc-Seal"]; len(v) != 0 { + t.Errorf("every ARC-Seal must go: %v", v) + } + if h.Get("Arcade") != "keep" || h.Get("X-Arc-Note") != "keep" { + t.Errorf("only the ARC- prefix is dropped: %v", h) + } +}