From fe2f418e359668448dbffaaf18c1999f78948591 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Thu, 11 Jan 2024 20:25:50 +0100 Subject: [PATCH] feat: Prevent weird situations if we have no username --- cmd/rio/main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/rio/main.go b/cmd/rio/main.go index 4e18dc3..aa6e170 100644 --- a/cmd/rio/main.go +++ b/cmd/rio/main.go @@ -67,6 +67,16 @@ func Handler(pagesDomain, giteaUrl, defaultCsp string, giteaClient *repo.GiteaCl return func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Server", "rio") + // Is the direct domain requested? + if req.Host == pagesDomain { + log.Debug("Direct pages domain is requested.") + + // TODO: Handle + w.WriteHeader(404) + return + } + + // Is a direct subdomain requested? if strings.HasSuffix(req.Host, pagesDomain) { log.Debug("Domain can be directly handled") handleSubdomain(req.Host, "", req.URL.Path, giteaUrl, defaultCsp, giteaClient, w) @@ -81,7 +91,10 @@ func Handler(pagesDomain, giteaUrl, defaultCsp string, giteaClient *repo.GiteaCl } log.Debugf("Got CNAME %s", cname) - if strings.HasSuffix(cname, pagesDomain) { + // Is a direct subdomain requested after CNAME lookup? + // NOTE: We now require the leading dot because a CNAME to the direct + // pages domain makes no sense. + if strings.HasSuffix(cname, "."+pagesDomain) { log.Debugf("%s is alias of %s and can be handled after a CNAME query", req.Host, cname) handleSubdomain(req.Host, cname, req.URL.Path, giteaUrl, defaultCsp, giteaClient, w) return