Skip to content

Commit

Permalink
add security logs to webhook verification failures
Browse files Browse the repository at this point in the history
Signed-off-by: notfromstatefarm <86763948+notfromstatefarm@users.noreply.github.com>
  • Loading branch information
notfromstatefarm committed Aug 17, 2022
1 parent 68d0ef0 commit 4052f56
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions util/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"context"
"errors"
"fmt"
"html"
"net/http"
Expand All @@ -19,6 +20,7 @@ import (
"gopkg.in/go-playground/webhooks.v5/gogs"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/common"
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
appclientset "github.com/argoproj/argo-cd/v2/pkg/client/clientset/versioned"
"github.com/argoproj/argo-cd/v2/reposerver/cache"
Expand Down Expand Up @@ -395,14 +397,29 @@ func (a *ArgoCDWebhookHandler) Handler(w http.ResponseWriter, r *http.Request) {
//Gogs needs to be checked before GitHub since it carries both Gogs and (incompatible) GitHub headers
case r.Header.Get("X-Gogs-Event") != "":
payload, err = a.gogs.Parse(r, gogs.PushEvent)
if errors.Is(err, gogs.ErrHMACVerificationFailed) {
log.WithField(common.SecurityField, common.SecurityHigh).Infof("Gogs webhook HMAC verification failed")
}
case r.Header.Get("X-GitHub-Event") != "":
payload, err = a.github.Parse(r, github.PushEvent, github.PingEvent)
if errors.Is(err, github.ErrHMACVerificationFailed) {
log.WithField(common.SecurityField, common.SecurityHigh).Infof("GitHub webhook HMAC verification failed")
}
case r.Header.Get("X-Gitlab-Event") != "":
payload, err = a.gitlab.Parse(r, gitlab.PushEvents, gitlab.TagEvents)
if errors.Is(err, gitlab.ErrGitLabTokenVerificationFailed) {
log.WithField(common.SecurityField, common.SecurityHigh).Infof("GitLab webhook token verification failed")
}
case r.Header.Get("X-Hook-UUID") != "":
payload, err = a.bitbucket.Parse(r, bitbucket.RepoPushEvent)
if errors.Is(err, bitbucket.ErrUUIDVerificationFailed) {
log.WithField(common.SecurityField, common.SecurityHigh).Infof("BitBucket webhook UUID verification failed")
}
case r.Header.Get("X-Event-Key") != "":
payload, err = a.bitbucketserver.Parse(r, bitbucketserver.RepositoryReferenceChangedEvent, bitbucketserver.DiagnosticsPingEvent)
if errors.Is(err, bitbucketserver.ErrHMACVerificationFailed) {
log.WithField(common.SecurityField, common.SecurityHigh).Infof("BitBucket webhook HMAC verification failed")
}
default:
log.Debug("Ignoring unknown webhook event")
http.Error(w, "Unknown webhook event", http.StatusBadRequest)
Expand Down

0 comments on commit 4052f56

Please sign in to comment.