Skip to content

Commit

Permalink
fix: enforce auth hook secrets conform to standard webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Dec 10, 2024
1 parent 8627a16 commit e930aa1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,8 @@ func (h *hook) validate() error {
return h.SendEmail.validate("send_email")
}

var hookSecretPattern = regexp.MustCompile(`^v1,whsec_[A-Za-z0-9+/=]{32,88}$`)

func (h *hookConfig) validate(hookType string) (err error) {
// If not enabled do nothing
if !h.Enabled {
Expand All @@ -984,12 +986,17 @@ func (h *hookConfig) validate(hookType string) (err error) {
} else if h.Secrets, err = maybeLoadEnv(h.Secrets); err != nil {
return err
}
for _, secret := range strings.Split(h.Secrets, "|") {
if !hookSecretPattern.MatchString(secret) {
return errors.Errorf(`Invalid hook config: auth.hook.%s.secrets must be formatted as "v1,whsec_<base64_encoded_secret>"`, hookType)
}
}
case "pg-functions":
if len(h.Secrets) > 0 {
return errors.Errorf("Invalid hook config: auth.hook.%s.secrets is unsupported for pg-functions URI", hookType)
}
default:
return errors.Errorf("Invalid hook config: auth.hook.%v should be a HTTP, HTTPS, or pg-functions URI", hookType)
return errors.Errorf("Invalid hook config: auth.hook.%s.uri should be a HTTP, HTTPS, or pg-functions URI", hookType)
}
return nil
}
Expand Down

0 comments on commit e930aa1

Please sign in to comment.