Skip to content

Webhooks

The platform signs the deliveries it sends to your endpoints, and the scheduled-job firings it sends to your application. The webhook package checks the signature before you trust a request. The algorithm and headers are in delivery and webhook signatures; the concepts are in delivery and the how-to is receive webhooks.

The signature is hex(HMAC-SHA256(secret, timestamp + rawBody)), sent as X-FlowCatalyst-Signature beside the X-FlowCatalyst-Timestamp it covers. The secret is the signing secret of the service account that signs: the subscription’s connection for a delivery, the owning application for a scheduled-job firing.

Use Verifier for new code.

import "github.com/flowcatalyst/go-sdk/webhook"
verifier := webhook.NewVerifier(os.Getenv("FLOWCATALYST_SIGNING_SECRET"))
func handle(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body) // the raw bytes, before any parsing
if err != nil {
http.Error(w, "read body", http.StatusBadRequest)
return
}
err = verifier.Verify(body,
r.Header.Get(webhook.SignatureHeader),
r.Header.Get(webhook.TimestampHeader))
if err != nil {
http.Error(w, "invalid signature", http.StatusUnauthorized)
return
}
// The body is now trusted: parse it.
}
  • webhook.SignatureHeader is X-FLOWCATALYST-SIGNATURE and webhook.TimestampHeader is X-FLOWCATALYST-TIMESTAMP. Header.Get is case-insensitive, so either spelling of the header works.
  • Pass the bytes you received. Do not decode and re-encode: key order and spacing would change the bytes and break the signature.
  • MaxClockSkew defaults to 5 minutes and is checked in both directions: a timestamp more than 5 minutes old, or more than 5 minutes ahead, is refused. Set verifier.MaxClockSkew to change it; a value of 0 disables the check.
  • The timestamp must be ISO 8601, either 2006-01-02T15:04:05.000Z or any RFC 3339 fractional precision. A bare Unix-seconds integer is not accepted by Verifier.
  • The comparison is constant time.
Sentinel Meaning Suggested status
ErrMissingSignature The signature header is empty. 400 or 401
ErrMissingTimestamp The timestamp header is empty. 400 or 401
ErrBadTimestamp The timestamp does not parse. 400 or 401
ErrStaleTimestamp Outside the skew, past or future. 401
ErrBadSignature The HMAC does not match. 401 or 403

Validator is an equivalent API with a different style: Validate(signature, timestamp, payload), and a constructor that reads the secret from the environment.

v, err := webhook.ValidatorFromEnv() // FLOWCATALYST_SIGNING_SECRET; ErrMissingSecret if unset or empty
// or: v := webhook.NewValidator(secret, webhook.WithTolerance(10*time.Minute))
err = v.Validate(
r.Header.Get(webhook.ValidatorSignatureHeader), // "X-FlowCatalyst-Signature"
r.Header.Get(webhook.ValidatorTimestampHeader), // "X-FlowCatalyst-Timestamp"
body)

It differs from Verifier in these ways:

  • It also accepts a bare Unix-seconds integer as the timestamp.
  • Tolerance is 300 seconds into the past by default (WithTolerance), and only 60 seconds into the future (webhook.FutureGraceSecs).
  • ComputeSignature(timestamp, payload) is exposed, so you can sign your own outbound callbacks the same way. WithClock injects a clock for tests.
  • Errors are separate sentinels, mapped to status codes in examples/webhook-receiver:
Sentinel Suggested status
ErrValidatorMissingSignature, ErrValidatorMissingTimestamp, ErrValidatorInvalidTimestamp 400
ErrTimestampExpired, ErrTimestampInFuture 401
ErrValidatorInvalidSignature 403
ErrMissingSecret 500 (your configuration is wrong)
  • The bearer token. A delivery also carries Authorization: Bearer <token> when the signing account has one. The Go package has no helper for it; compare it yourself if you want the second gate. The signature is the real proof, because it binds the secret to this body at this time.
  • Duplicates. The timestamp window limits replay but does not remove it. Key your handling on the delivery’s job id (X-Dispatch-Job-Id), because the platform delivers at least once.
  • Scheduled-job firings. scheduledjobs.Runner.Process takes the body and does not check a signature. Verify the request with Verifier first, then hand the bytes to the runner. See Scheduled jobs.

A verified delivery is acknowledged with a 2xx. To tell the platform “not yet, try again later” without spending an attempt, answer 2xx with {"ack": false} and optionally notBefore or delaySeconds. The Go SDK has no type for that response; the shapes and what each status does to the job are in delivery.