Skip to content

Commit

Permalink
fix: actually fix updating webhooks with secrets and validation header
Browse files Browse the repository at this point in the history
If the user updates a webhook without providing a new secret, then we
include the existing secret if it exists, for validation.

Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Nov 21, 2024
1 parent 81c7919 commit af6f033
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/api/handlers/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func (a *WebhookHandler) Update(req api.Context) error {
return err
}

if err := validateManifest(req, webhookReq.WebhookManifest, false); err != nil {
if webhookReq.WebhookManifest.ValidationHeader != "" && webhookReq.WebhookManifest.Secret == "" {
webhookReq.WebhookManifest.Secret = wh.Spec.Secret
}

if err := validateManifest(req, webhookReq.WebhookManifest); err != nil {
return err
}

Expand Down Expand Up @@ -96,7 +100,7 @@ func (a *WebhookHandler) Create(req api.Context) error {
return err
}

if err := validateManifest(req, webhookReq.WebhookManifest, true); err != nil {
if err := validateManifest(req, webhookReq.WebhookManifest); err != nil {
return err
}

Expand Down Expand Up @@ -278,7 +282,7 @@ func validateSecretHeader(secret string, body []byte, values []string) error {
return fmt.Errorf("invalid secret header")
}

func validateManifest(req api.Context, manifest types.WebhookManifest, create bool) error {
func validateManifest(req api.Context, manifest types.WebhookManifest) error {
// Ensure that the WorkflowID is set and the workflow exists
if manifest.Workflow == "" {
return apierrors.NewBadRequest("webhook manifest must have a workflow name")
Expand All @@ -292,7 +296,7 @@ func validateManifest(req api.Context, manifest types.WebhookManifest, create bo
}

// On creation, the user must set both the validation header and secret or set neither.
if create && (manifest.ValidationHeader != "") != (manifest.Secret != "") {
if (manifest.ValidationHeader != "") != (manifest.Secret != "") {
return apierrors.NewBadRequest("webhook must have secret and header set together")
}

Expand Down

0 comments on commit af6f033

Please sign in to comment.