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!
This commit is contained in:
Mechiel Lukkien 2023-02-28 20:40:52 +01:00
parent c9190337e6
commit 994b5b9a0a
No known key found for this signature in database

View file

@ -15,14 +15,16 @@ import (
func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) { func mtastsPolicyHandle(w http.ResponseWriter, r *http.Request) {
log := xlog.WithCid(mox.Cid()) 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) http.NotFound(w, r)
return return
} }
host, _, err := net.SplitHostPort(strings.TrimPrefix(r.Host, "mta-sts.")) host = strings.TrimPrefix(host, "mta-sts.")
if err != nil { nhost, _, err := net.SplitHostPort(host)
http.NotFound(w, r) if err == nil {
return // Only relevant for when host has a port.
host = nhost
} }
domain, err := dns.ParseDomain(host) domain, err := dns.ParseDomain(host)
if err != nil { if err != nil {