Webhook icon
Script icon
Process icon
Set icon
If icon
SlackIncomingWebhook icon
Fail icon
Write icon

Verify Webhook HMAC Signatures Before Processing

Authenticate inbound webhooks with constant-time HMAC-SHA256 checks, audit every attempt in KV, alert on forgeries, and persist verified payloads.

Categories
CoreInfrastructure

A webhook URL is an open door: anyone who learns the key can start executions, and an unverified payload is trusted data wearing a costume. This blueprint closes the door with the same mechanism GitHub, Stripe, and every serious sender use — an HMAC-SHA256 signature over the raw body, verified with hmac.compare_digest so even the comparison cannot leak through timing. Every attempt (valid or not) is recorded in the namespace KV store, forgeries trigger a Slack alert and a failed execution so they show up in monitoring, and verified payloads are persisted to internal storage with a URI output that downstream flows consume.

How it works

  1. The inbound_webhook trigger (io.kestra.plugin.core.trigger.Webhook) exposes a keyed URL and hands the raw payload to {{ trigger.body }} and the request headers to {{ trigger.headers }}.
  2. verify_signature (io.kestra.plugin.scripts.python.Script on the io.kestra.plugin.core.runner.Process runner) receives the headers map (lowercased for a case-insensitive lookup), the configured header name, the body, and the signing secret through the environment. It strips an optional sha256= prefix, recomputes HMAC-SHA256(secret, body) as lowercase hex, and compares with hmac.compare_digest — constant-time, never ==. It emits valid and a human-readable reason through Kestra's outputs protocol.
  3. record_attempt (io.kestra.plugin.core.kv.Set) writes the execution ID, timestamp, verdict, and reason to WEBHOOK_GATE_LAST_ATTEMPT, giving dashboards and other flows a single key to read.
  4. enforce_signature (io.kestra.plugin.core.flow.If) branches on the verdict. Rejected: alert_intrusion_attempt posts the reason to Slack and reject_request (io.kestra.plugin.core.execution.Fail) turns the execution red. Verified: persist_event (io.kestra.plugin.core.storage.Write) lands the payload as JSON in internal storage and exposes its URI.
  5. The errors block alerts Slack only on genuine infrastructure failures, worded explicitly so an errored gate is never mistaken for a rejected request.

What you get

  • Cryptographic proof that an inbound payload really came from the sender who shares your signing secret.
  • A constant-time comparison — timing side channels closed by construction.
  • An audit trail of the latest attempt in KV, plus full attempt history in Kestra executions.
  • Unauthorized calls that are loud (Slack) and visible (failed execution), not silent drops.
  • Verified payloads landing in internal storage with a payload_uri output ready for a downstream flow or subflow.

Who it's for

  • Teams exposing Kestra webhook endpoints to GitHub, Stripe, or any HMAC-signing sender.
  • Security engineers who need forged-request rejection with alerting, not just a keyed URL.
  • Builders replacing "trust the URL key alone" with real payload authentication.

Why orchestrate this with Kestra

The Kestra webhook trigger guards the URL; nothing in a bare receiver guards the payload. Kestra makes the check a versioned, testable flow step: the verification logic is plain Python in the execution logs, the accept/reject decision is a declarative If, rejections become failed executions your alerting already watches, and the KV audit plus storage hand-off wire the result into the rest of your orchestration. In a custom server this same logic hides in framework middleware with no history, no alerts, and no downstream lineage.

Prerequisites

  • A sender that signs payloads with HMAC-SHA256 and a shared secret (GitHub: secret token; Stripe-style: signing secret). The secret must match exactly what the sender uses.
  • Text payloads (JSON or plain text) — Kestra exposes the body as a string, so binary bodies are out of scope.
  • Python 3 on the Kestra worker (Process runner), or switch verify_signature to a Docker task runner.
  • A Slack incoming webhook for rejection and infrastructure alerts.

Secrets

  • WEBHOOK_SIGNING_SECRET: shared signing secret; must match the sender's configuration byte for byte.
  • SIGNED_WEBHOOK_KEY: key segment of the webhook URL — treat it as a secret, but do not rely on it alone.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL.

Quick start

  1. Add the three secrets to your Kestra namespace and make WEBHOOK_SIGNING_SECRET identical to the sender's secret.

  2. Point the sender at /api/v1/{tenant}/executions/webhook/{namespace}/webhook-hmac-signature-validation-gate/{SIGNED_WEBHOOK_KEY}.

  3. Test locally before wiring the sender — sign a body with OpenSSL and curl the endpoint:

    BODY='{"event":"demo"}'
    SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "your-signing-secret" | awk '{print $NF}')
    curl -X POST "$WEBHOOK_URL" \
      -H "Content-Type: application/json" \
      -H "X-Hub-Signature-256: sha256=$SIG" \
      -d "$BODY"
    

    Expect a successful execution with verified: true and a payload_uri; send the same body with a wrong signature and expect the Slack rejection alert and a failed execution with reason: signature mismatch.

  4. Read the verdict any time with {{ kv('WEBHOOK_GATE_LAST_ATTEMPT') }}.

How to extend

  • Stripe-style headers: sign "<timestamp>.<body>" instead of the raw body and parse t=...,v1=... — the script change is three lines, and the timestamp then enables a replay window.
  • Replay protection: compare the signature's embedded timestamp against now() and reject anything older than a tolerance input.
  • Real processing: replace persist_event with an io.kestra.plugin.core.http.Request forward, a Subflow call, or a queue publish — the verification half stays untouched.
  • Multiple senders: give each tenant its own secret and select it with a Switch task keyed on a path or header.
  • Noise control: downgrade repeated rejections from Slack to a daily digest while keeping every attempt in KV.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.