Skip to content

Commit

Permalink
Fix webhooks signature
Browse files Browse the repository at this point in the history
This commit fixes the way webhooks signatures are created. Before this
change, the signature of an empty body was prepended by the body itself.
  • Loading branch information
maraino committed Sep 22, 2023
1 parent 68a1c85 commit 31da66c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion authority/provisioner/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ retry:
if err != nil {
return nil, err
}
sig := hmac.New(sha256.New, secret).Sum(reqBytes)
h := hmac.New(sha256.New, secret)
h.Write(reqBytes)
sig := h.Sum(nil)
req.Header.Set("X-Smallstep-Signature", hex.EncodeToString(sig))
req.Header.Set("X-Smallstep-Webhook-ID", w.ID)

Expand Down
4 changes: 3 additions & 1 deletion authority/provisioner/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ func TestWebhook_Do(t *testing.T) {

secret, err := base64.StdEncoding.DecodeString(tc.webhook.Secret)
assert.FatalError(t, err)
mac := hmac.New(sha256.New, secret).Sum(body)
h := hmac.New(sha256.New, secret)
h.Write(body)
mac := h.Sum(nil)
assert.True(t, hmac.Equal(sig, mac))

switch {
Expand Down

0 comments on commit 31da66c

Please sign in to comment.