From 0039b9862ac5126bfc42aeaa1466406b2a7e7516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Sat, 25 Nov 2023 15:28:06 +0100 Subject: [PATCH] Harden code against potential nil panics Detected using go.uber.org/nilaway/cmd/nilaway --- function.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/function.go b/function.go index 9d644ee..98ef201 100644 --- a/function.go +++ b/function.go @@ -22,7 +22,8 @@ func Handle(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/plain; charset=utf-8") - if !isAuthorized(r.URL.Query().Get("token")) { + query := r.URL.Query() + if (query == nil) || !isAuthorized(query.Get("token")) { http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized) return @@ -51,9 +52,6 @@ func Handle(w http.ResponseWriter, r *http.Request) { } event, err := webhook.ParseEvent(payload) - - log.Printf("Processing DNSimple event with request ID %q", event.RequestID) - if err != nil { log.Printf("Could not parse webhook name: %s", err.Error()) notify.Send(fmt.Sprintf("Could not parse webhook name: %s", err.Error()), nil) @@ -61,6 +59,8 @@ func Handle(w http.ResponseWriter, r *http.Request) { return } + log.Printf("Processing DNSimple event with request ID %q", event.RequestID) + if event.Name != "dnssec.rotation_start" && event.Name != "dnssec.rotation_complete" { log.Printf("Not a rotation event: %s", event.Name) // It's OK if this is not a DNSSEC rotation event. We