Skip to content

Commit c86d726

Browse files
committed
Fix validation
1 parent f8bce45 commit c86d726

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package caddy_module_github_webhook
33
import (
44
"crypto/hmac"
55
"crypto/sha256"
6-
"crypto/subtle"
6+
"encoding/hex"
77
"fmt"
88
"github.com/caddyserver/caddy/v2"
99
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -55,10 +55,9 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
5555

5656
mac := hmac.New(sha256.New, []byte(m.Secret))
5757
mac.Write(payloadBytes)
58-
expected := mac.Sum(nil)
58+
expected := []byte(hex.EncodeToString(mac.Sum(nil)))
5959

60-
valid := subtle.ConstantTimeCompare(expected, actual)
61-
if valid == 0 {
60+
if !hmac.Equal(actual, expected) {
6261
// unauthorized in case of invalid signature
6362
w.WriteHeader(401)
6463
_, err = w.Write(nil)

0 commit comments

Comments
 (0)