From d815f6d8d9dd67837fdcf8240c497a6bb617201f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Akko=C3=A7?= Date: Sun, 7 Nov 2021 20:37:12 +0100 Subject: [PATCH 1/3] Potential fix for Issue 230 --- webhooks.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webhooks.go b/webhooks.go index feccdb9..643c91a 100644 --- a/webhooks.go +++ b/webhooks.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io/ioutil" "net/http" @@ -89,7 +90,7 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque TransmissionSig string `json:"transmission_sig,omitempty"` TransmissionTime string `json:"transmission_time,omitempty"` WebhookID string `json:"webhook_id,omitempty"` - Event json.RawMessage `json:"webhook_event"` + Event json.RawMessage `json:"webhook_event,omitempty"` } // Read the content @@ -97,6 +98,9 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque if httpReq.Body != nil { bodyBytes, _ = ioutil.ReadAll(httpReq.Body) } + else{ + return nil, errors.New("Cannot verify webhook for HTTP Request with empty body.") + } // Restore the io.ReadCloser to its original state httpReq.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) From 28f2333770e9a9551f1b3f366e1ad4c65fd336d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Akko=C3=A7?= Date: Mon, 8 Nov 2021 10:21:28 +0100 Subject: [PATCH 2/3] Fixed else syntax --- webhooks.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webhooks.go b/webhooks.go index 643c91a..5c5ce1f 100644 --- a/webhooks.go +++ b/webhooks.go @@ -97,8 +97,7 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque var bodyBytes []byte if httpReq.Body != nil { bodyBytes, _ = ioutil.ReadAll(httpReq.Body) - } - else{ + }else{ return nil, errors.New("Cannot verify webhook for HTTP Request with empty body.") } // Restore the io.ReadCloser to its original state From bf0c207b52321cf6819a4ca5875057ae98830f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Akko=C3=A7?= Date: Wed, 10 Nov 2021 23:33:48 +0100 Subject: [PATCH 3/3] Added spaces `} else {` --- webhooks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webhooks.go b/webhooks.go index 5c5ce1f..a6aae5c 100644 --- a/webhooks.go +++ b/webhooks.go @@ -97,7 +97,7 @@ func (c *Client) VerifyWebhookSignature(ctx context.Context, httpReq *http.Reque var bodyBytes []byte if httpReq.Body != nil { bodyBytes, _ = ioutil.ReadAll(httpReq.Body) - }else{ + } else { return nil, errors.New("Cannot verify webhook for HTTP Request with empty body.") } // Restore the io.ReadCloser to its original state