Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Harden code against potential nil panics #161

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,16 +52,15 @@ 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)
http.Error(w, err.Error(), http.StatusInternalServerError)
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
Expand Down