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.
This commit is contained in:
tgiachi 2026-11-10 11:52:30 +01:00
commit 79fe51b206
2 changed files with 53 additions and 1 deletions

View file

@ -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))

View file

@ -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 <alice@example.com>\r\n" +
"List-Help: <mailto:evil@x.com?subject=help>\r\nList-Archive: <https://evil.example/a>\r\n" +
"List-Owner: <mailto:evil@x.com>\r\nList-Subscribe: <https://evil.example/s>\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 <alice@example.com>\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)
}
}