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

Commit

Permalink
Merge pull request #161 from reload/harden
Browse files Browse the repository at this point in the history
Harden code against potential nil panics
  • Loading branch information
arnested authored Nov 25, 2023
2 parents 4846ba4 + 0039b98 commit 78fda1c
Showing 1 changed file with 4 additions and 4 deletions.
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

0 comments on commit 78fda1c

Please sign in to comment.