Skip to content

Commit

Permalink
Add length check to github signature
Browse files Browse the repository at this point in the history
Signed-off-by: AdamKorcz <[email protected]>
  • Loading branch information
AdamKorcz committed Nov 18, 2023
1 parent c3b1a44 commit 34f4b9b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (
ErrEventNotFound = errors.New("event not defined to be parsed")
ErrParsingPayload = errors.New("error parsing payload")
ErrHMACVerificationFailed = errors.New("HMAC verification failed")
ErrWrongHubSignatureHeader = errors.New("Invalid Github signature")
)

// Event defines a GitHub hook event type
Expand Down Expand Up @@ -163,6 +164,9 @@ func (hook Webhook) Parse(r *http.Request, events ...Event) (interface{}, error)
if len(signature) == 0 {
return nil, ErrMissingHubSignatureHeader
}
if len(signature) < 6 {
return nil, ErrWrongHubSignatureHeader
}
mac := hmac.New(sha1.New, []byte(hook.secret))
_, _ = mac.Write(payload)
expectedMAC := hex.EncodeToString(mac.Sum(nil))
Expand Down

0 comments on commit 34f4b9b

Please sign in to comment.