From 733e51839269242231c4af8ae53c4ce48d885916 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sun, 29 Jan 2023 12:29:01 +0100 Subject: [PATCH] Accept requests where the URL has a FQDN hostname with a trailing dot. Closes #20. --- handler.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/handler.go b/handler.go index 40e1c65..8f339bf 100644 --- a/handler.go +++ b/handler.go @@ -49,7 +49,12 @@ func handleGeminiRequest(conn net.Conn, config Config, accessLogEntries chan Log } // Reject requests for content from other servers - if strings.ToLower(URL.Hostname()) != config.Hostname || (URL.Port() != "" && URL.Port() != strconv.Itoa(config.Port)) { + requestedHost := strings.ToLower(URL.Hostname()) + // Trim trailing . from FQDNs + if strings.HasSuffix(requestedHost, ".") { + requestedHost = requestedHost[:len(requestedHost)-1] + } + if requestedHost != config.Hostname || (URL.Port() != "" && URL.Port() != strconv.Itoa(config.Port)) { conn.Write([]byte("53 No proxying to other hosts or ports!\r\n")) log.Status = 53 return