Skip to content

Commit

Permalink
Merge pull request #1546 from smallstep/fix-webhook-signature
Browse files Browse the repository at this point in the history
Fix webhooks signature
  • Loading branch information
maraino authored Sep 22, 2023
2 parents 68a1c85 + 31da66c commit e766ca7
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 e766ca7

Please sign in to comment.