Functions

verify-request

fn (request: HttpRequest): Bool
fn (request: HttpRequest, signing-secret: Str): Bool
fn (request: HttpRequest, opts: Map): Bool
fn (request: HttpRequest, signing-secret: Str, tolerance-seconds: Int): Bool

Verify a Slack webhook request signature using HMAC-SHA256. Returns true if the request is authentic and its timestamp is within the replay window (default 300 seconds, per Slack's guidance; pass 0 as the third argument to disable). Uses the slack.signing.secret context variable by default, or accepts an explicit signing secret as a second argument for multi-app scenarios.

The function checks the x-slack-request-timestamp and x-slack-signature headers against the computed HMAC using constant-time comparison to prevent timing attacks.

Example

slack-webhook
meta {webhook: {service: "slack", path: "/slack/webhook"}}
fn (request) {
  // Using context variable (1-arity, most common)
  is-valid ::slack::webhooks/verify-request(request)

  // With explicit signing secret (2-arity, for multi-app)
  secret ::hot::ctx/get("tenant-b.slack.signing.secret")
  is-valid ::slack::webhooks/verify-request(request, secret)

  // With opts (2-arity): `signing-secret` decides the call when present,
  // and a blank one is rejected rather than replaced by the context secret
  is-valid ::slack::webhooks/verify-request(request, {signing-secret: secret})

  if(is-valid,
    send("slack:webhook", request.body),
    ::hot::http/HttpResponse({status: 401, body: "invalid signature"}))
}
Context Vars: slack.signing.secret