From 994b5b9a0a0e67992bb5db03dfe5c13a3520f139 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Tue, 28 Feb 2023 20:40:52 +0100 Subject: [PATCH] fix serving mta-sts policy files i broke it 3 days ago when adding support for serving it through external reverse proxy. report by mteege, thanks! --- http/mtasts.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/http/mtasts.go b/http/mtasts.go index b5c5585..6f5963a 100644 --- a/http/mtasts.go +++ b/http/mtasts.go @@ -15,14 +15,16 @@ import ( func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) { log := xlog.WithCid(mox.Cid()) - if !strings.HasPrefix(r.Host, "mta-sts.") { + host := strings.ToLower(r.Host) + if !strings.HasPrefix(host, "mta-sts.") { http.NotFound(w, r) return } - host, _, err := net.SplitHostPort(strings.TrimPrefix(r.Host, "mta-sts.")) - if err != nil { - http.NotFound(w, r) - return + host = strings.TrimPrefix(host, "mta-sts.") + nhost, _, err := net.SplitHostPort(host) + if err == nil { + // Only relevant for when host has a port. + host = nhost } domain, err := dns.ParseDomain(host) if err != nil {