Skip to content

Commit

Permalink
Use custom mime-type to avoid overeager JSON parsing. (#210)
Browse files Browse the repository at this point in the history
Middlewares/server frameworks have a tendency of replacing req.body with
parsed JSON object. We do not want this behavior as our Webhook receiver
needs to validate the raw string body against the `Authorization` header
  • Loading branch information
davidzhao authored Sep 20, 2022
1 parent 5814661 commit 782f517
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion webhook/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func (n *notifier) Notify(_ context.Context, payload interface{}) error {
continue
}
r.Header.Set(authHeader, token)
r.Header.Set("content-type", "application/json")
// use a custom mime type to ensure signature is checked prior to parsing
r.Header.Set("content-type", "application/webhook+json")
_, err = n.client.Do(r)
if err != nil {
n.logger.Error(err, "could not post to webhook", "url", url)
Expand Down

0 comments on commit 782f517

Please sign in to comment.