Skip to content

Webhook extension

The webhook extension turns each accepted POST to a signed URL into Work of its own. It is first-party, runs out of process as a package bundled with the release (open-conduit extension-run webhook), and is written only on protocol/sdk, as a third party would write it. It uses only public hooks: an ingress type with one one-shot family, webhook paths, a route handler (which asks for successors), a Work kind, an Event renderer, one toolbelt operation and two doctor checks.

A job webhook is a different kind of POST. It triggers the job’s one standing Work, so POSTs that arrive while a run is active or waiting join one batch, and the batch sees only the newest body. That is right for a job, which is one recurring task. Use a webhook entry when each delivery is a task of its own, such as one alert for each failed deploy or one form submission for each request. Each delivery then has its own history, retries and outcome, and deliveries run in parallel up to the binding’s capacity.

{"name": "inbox", "type": "webhook", "secret_names": ["hook"], "config": {
"scope": "ops", "webhook_secret": "hook",
"hooks": [
{"name": "tickets", "delivery_key": "header:Idempotency-Key", "correlation_key": "body:/ticket/id"},
{"name": "forms"}
]}}
Field Meaning
scope The scope the entry is in.
webhook_secret A selected secret name. Each hook’s URL token is derived from it, so rotating it revokes every URL of the entry. To revoke one hook’s URL, bump that hook’s version.
hooks[].name Lower case letters, digits, _ and -, at most 64. It is in the URL and in the Work’s title.
hooks[].delivery_key Optional. Where a delivery’s identity is read: header:<name> or body:<JSON pointer>.
hooks[].correlation_key Optional. Where a delivery’s thread is read, in the same form. Best a value that names something that ends and may start again, such as a ticket or an incident (see Routing and Work).
hooks[].version Optional, an integer, 0 by default. It is signed into the hook’s URL token, so bumping it revokes that hook’s URL alone, keeping its name, its Work IDs and its threads. After applying the bump, doctor --check-secrets prints the new URL to hand to the sender.
hooks[].fan_out Optional. Up to 4 targets, named like hooks, that each delivery goes to (see Fan-out).
hooks[].signature Optional. The sender’s own signature of each delivery, checked as well as the URL token (see Sender signatures).

A key is header:<name> (the header’s value) or body:<pointer> (an RFC 6901 pointer into a JSON body, naming a string, number or boolean). A value is at most 256 bytes.

The route is {"handler": "webhook", "config": {"hooks": ["deploys"], "targets": ["triage"]}}. hooks limits the route to those hooks; empty takes every hook of the scope’s webhook entries. targets limits it to those fan-out targets; empty takes every delivery of its hooks, whatever the target. One route per binding gives each hook, or each target, its own command or agent.

The webhook listener serves POST /webhook/<scope>/<entry>/<hook>/<token>. The token is an HMAC of the entry’s secret over the namespace (webhook/<scope>/<entry>), the hook and the hook’s version, so it is stable across restarts and distinct for each hook. Version 0 signs only the namespace and the hook, so a hook that never sets a version keeps the URL it had before versions existed. The handler:

  1. Answers 404 for an unknown hook or a wrong token, compared in constant time before the body is read.
  2. Answers 413 for a body over 1 MiB, or for one the hook’s fan-out Events couldn’t carry (see Fan-out).
  3. For a hook with a signature, answers 401 for a delivery whose signature doesn’t verify or whose signed timestamp is outside the hook’s tolerance, and 503 when the signature’s secret is unavailable (see Sender signatures).
  4. Reads the hook’s keys. A hook with a delivery key refuses a POST without it, or with a value over 256 bytes, with 400. A missing correlation value is not an error: that delivery is a thread of its own.
  5. Hands the delivery to the host and answers 202 only after durable acceptance, or 503 when it wasn’t accepted (or the secret is unavailable). When the host authored the failure, the 503’s body names its protocol code (not accepted: overloaded), so the sender’s delivery log says why; an unauthored failure’s text stays in the host’s log. The 202’s body is the delivery’s receipt (application/json), which names its Events.

Hooks and entries follow the configuration: one added by config apply serves its URL as soon as the apply is done, and one removed answers 404, with no restart.

Ingress turns it into one webhook.delivery Event, or one for each target of a hook that fans out, with payload webhook.delivery.v1: {hook, target?, delivery?, correlation?, content_type?, body | text}. A JSON body is kept as JSON, and any other body as text.

Deduplication. The Event’s delivery ID is the hook and a digest of the delivery key’s value, so the core’s (source, delivery_id) deduplication (event ingress) makes a sender’s retry the first delivery again, and the first envelope is kept even when a retry’s body differs. A hook without a delivery key gives each POST a fresh ID, so each POST is a new delivery, unless it came through the operator’s forwarder: then the forwarder’s delivery ID, the same on each of its retries, is the delivery’s identity, so a forwarder that retries after a timeout when the first attempt had in fact been accepted makes one Event, and the retry’s receipt says duplicate. A sender that retries by itself needs a delivery key.

Correlation. The Event’s correlation key is webhook/<scope>/<entry> with the external ID <hook>/c/<digest of the correlation value>, or <hook>/d/<delivery ID> when there is none. A delivery with a correlation value already seen therefore names the Work the first one opened.

The receipt. The 202’s body lists the delivery’s Events, one for each fan-out target or else one, in target order: {"events": [{"id": "<id>", "target": "triage", "duplicate": false}], "duplicate": false}. target is left out for a hook that doesn’t fan out. The host’s ingress.deliver reports whether the delivery added each Event. An Event’s duplicate is true when it was already accepted, and its id is then the first delivery’s. The top-level duplicate is true only when every Event was, as with a sender’s retry of the same delivery key, so a retrying sender can stop. A host that doesn’t report it is taken to have added each Event, so a delivery is never claimed as a duplicate wrongly. The receipt doesn’t name the Work: routing happens after the 202, and the route decides which Work an Event reaches, even when a correlation value has Work already. An operator follows each Event to its Work with GET /v1/events/{id}/route (or open-conduit events get). A sender without an operator token has no read of its own delivery’s route yet.

The URL token proves the sender was handed the URL. Senders such as GitHub, Slack, Stripe, Jira and Shopify also sign each body with a secret of their own, and a hook can check that signature too, so a leaked URL alone can’t send a delivery:

{"name": "github", "delivery_key": "header:X-GitHub-Delivery",
"signature": {"secret": "github_hook", "header": "X-Hub-Signature-256", "prefix": "sha256="}}
Field Meaning
secret Required. The secret the sender signs with, one of the entry’s secret_names.
header Required. The header the signature is in. Its value is split on commas and spaces, and each item that starts with prefix is a signature; one must verify, so a sender that sends several while it rolls its secret is taken.
algorithm hmac-sha256 (the default), hmac-sha1 or hmac-sha512.
encoding How the MAC is written: hex (the default, either case) or base64.
prefix What comes before each signature, such as sha256=, v0= or v1=.
signed What the sender signs: {body}, {timestamp}, {header:<name>} and literal text, {body} by default. It must hold {body} once.
timestamp For a sender that signs its time of sending: where it is read, header:<name>, body:<JSON pointer> or signature:<prefix> (an item of the signature header, such as Stripe’s t=). Unix seconds, or milliseconds when over 10^11. It must be signed: in signed as {timestamp}, or in the body.
tolerance_seconds How far the timestamp may be from the delivery’s receipt, either way: 300 by default, at most 86400. It needs timestamp.

The check runs after the token and the body’s size, and before the keys are read or the delivery is accepted, so a delivery that fails it leaves no Event. A 401 says only which check failed; the secret is never in it. Some senders written this way:

Sender signature
GitHub {"header": "X-Hub-Signature-256", "prefix": "sha256="}
Jira {"header": "X-Hub-Signature", "prefix": "sha256="}
Shopify {"header": "X-Shopify-Hmac-Sha256", "encoding": "base64"}
Slack {"header": "X-Slack-Signature", "prefix": "v0=", "signed": "v0:{timestamp}:{body}", "timestamp": "header:X-Slack-Request-Timestamp"}
Stripe {"header": "Stripe-Signature", "prefix": "v1=", "signed": "{timestamp}.{body}", "timestamp": "signature:t="}
Linear {"header": "Linear-Signature", "timestamp": "body:/webhookTimestamp", "tolerance_seconds": 600}

each with its secret. The timestamp is judged against the receipt the listener attests (extension.WebhookReceivedAt): when it received the request, or, behind a forwarder, when the forwarder first received the delivery, so a delivery held while the daemon was down passes a tolerance it would fail on arrival now. The forwarder can’t sign as the sender, so the sender’s signature is checked as ever. A forwarder that does hold the sender’s secret can instead verify the sender and re-sign in the same scheme with a secret it shares with the daemon; the hook’s secret is then that one, the secret of whoever signs the request the listener receives. A sender that signs no timestamp (GitHub, Jira, Shopify) can have a captured delivery sent again under a fresh delivery ID; a hook threads it to the same Work by its correlation key, but nothing refuses it. A sender whose secret isn’t the raw HMAC key (Standard Webhooks’ base64 whsec_ secrets) isn’t covered yet.

A delivery goes to the first route that takes it, never to every route that would (runtime semantics, rule 3), so a second route for the same hook never sees it. A hook that should start Work for several bindings lists them as targets instead:

{"name": "tickets", "delivery_key": "header:Idempotency-Key", "correlation_key": "body:/ticket/id", "fan_out": ["triage", "audit"]}

with a route for each target:

{"name": "triage", "handler": "webhook", "binding": "triage", "config": {"hooks": ["tickets"], "targets": ["triage"]}},
{"name": "audit", "handler": "webhook", "binding": "audit", "config": {"hooks": ["tickets"], "targets": ["audit"]}}

Ingress accepts one Event for each target, all in one transaction, so the 202 covers every target. Each Event carries the whole body and its target, and has its own identity: the delivery ID <hook>/<target>/<delivery ID> and the thread <hook>/<target>/c/<digest> (or <hook>/<target>/d/<delivery ID>). Deduplication, threading and successors therefore work per target: a retry is every target’s first delivery again, and a later delivery of the ticket is each target’s own Work’s input. Each target’s Event is routed on its own, first match as ever. A route without targets takes every target, each as Work of its own, and an Event no route takes is unmatched like any other.

The targets are config, so every delivery goes to all of them. When which agents should take a delivery depends on what it says, bind the hook to one agent that hands the rest on as child Work (issue #568). A hook has at most 4 targets. Each target’s Event carries the whole body, and a delivery’s Events are accepted in one ingress page (8 MiB by default), so the Events of one delivery may encode to at most 7 MiB together, and a delivery over that is refused with 413 rather than a 503 the sender would retry. JSON can encode a body byte as six (<, >, & and control characters become \u00XX), so the body a hook can take depends on its targets and on what the body holds: any 1 MiB body fits one Event, plain text or JSON of 1 MiB fits 4 targets, and a body that is all markup fits about 1.1 MiB ÷ the number of targets.

The family is one-shot, declared with its loss: a POST leaves no history to read back, so reconcile returns an empty complete snapshot, and a POST sent while the listener or tunnel is down is lost (the sender sees the failure and may retry).

For a delivery to one of the scope’s webhook entries, of a hook the route takes:

  • with no owner of its correlation key, it creates webhook.delivery Work with the ID <namespace>/<external ID>, titled A delivery to <hook>: <correlation or delivery value> (A delivery to <hook> for <target>: … for a fan-out target);
  • with a live webhook.delivery owner, it is that Work’s input, as a Slack reply is its thread’s;
  • with a finished webhook.delivery owner, it opens the thread’s next generation: a successor Work, <owner ID>/g2 (then /g3 and on), with the generation key <external ID>/g2. The delivery is its first input, and a core.work.created Event links it to the finished Work. Later deliveries of the thread route to it, and a type-only wait on it wakes on them. A ticket that is reopened, or an alert that fires again, therefore starts new Work rather than being dropped;
  • with any other owner, it is skipped.

The core does this (RouteDecision.Successor, runtime semantics, rule 9) in the transaction that routes the delivery, so no delivery to a finished thread is lost. Each generation is its own Work with its own history and outcome, and a correlation value may name a thread that ends and starts again. A value that names something long-lived, such as a service name, still gives a new generation each time the last one finishes, so a thread per incident or ticket keeps each generation’s Work about one thing.

An agent’s turn reads the delivery rendered by the package: a heading naming the hook, the delivery’s Event ID, its target, the delivery and correlation values, the content type, then the body. A body over 8 KiB is cut, with a note naming the operation that returns it whole.

webhook.delivery.read {event} returns the delivery the turn names in full: its Event ID, receive time and webhook.delivery.v1 payload, body included. It reads that one Event and returns it only when it is a delivery routed to the calling Work (bound from durable state), so a Work can’t read another’s. A binding needs the operation granted (in its operations and the scope’s authorization.operations). A shell binding has the whole Event, payload and body included, in OS_INPUT_FILE as well.

  • webhook lists each hook’s path, with <token>.
  • webhook-urls (doctor --check-secrets) prints each hook’s signed URL at its current version, and fails when an entry’s secret, or a hook’s signature secret, is unavailable. A missing signature secret would otherwise only show as 503s to the sender, with no Event to notice it by.
  • extensions/webhook over the SDK host: retries, threads, fan-out Events, routes selecting by target, a 413 for an escape-heavy body a 4-target hook’s Events couldn’t carry, a missing or long delivery key, a wrong token, a version bump revoking one hook’s URL while the entry’s other hook keeps its own, an unknown hook, an oversized body, POSTs without a delivery key, JSON pointer edge cases, config refusals, the route’s decisions, rendering, the doctor lines, and webhook.delivery.read returning a 9 KB body to its own Work while refusing another Work and Work the scope doesn’t hold.
  • TestForwardIDIsTheIdentityOfAHookWithoutADeliveryKey and TestSignedTimestampIsJudgedAtTheAttestedReceipt in the same suite: behind a forwarder, a hook with no delivery key makes one Event of a forwarded delivery and its retry, the retry’s receipt saying duplicate, while unforwarded POSTs stay distinct; and a Slack-signed delivery ten minutes old is refused at a receipt of now and accepted at the receipt the forwarder attests.
  • TestSignatureIsCheckedBeforeAcceptance in the same suite: hooks signed the way GitHub, Shopify, Slack, Stripe and Linear sign take a signed delivery and refuse, with 401 and no Event, one unsigned, signed with another secret, tampered with, missing its prefix, stale, ahead of the clock or replayed under a fresh timestamp; Stripe’s rolled secrets verify on either signature, and a wrong token is still 404. Mutating the verifier to pass a bad MAC or skip the tolerance fails it. TestSignatureSecretUnavailable answers 503 rather than taking the delivery unchecked and fails doctor --check-secrets, and TestSignatureSettings refuses unsigned timestamps, a signed without {body} and the other bad declarations.
  • TestWebhookDeliveriesThroughRuntime: the real runtime ingress and router over SQLite. A retry with another body is the first delivery, a delivery with the same correlation value is routed to the first one’s Work, and every other delivery has Work of its own.
  • TestWebhookFanOutThroughRuntime: a hook that fans out to two targets, with a route and binding for each. One POST, its retry and a later delivery of the same ticket give two Works, one on each binding, each with that target’s two deliveries. An escape-heavy delivery just under the encoded bound is accepted in one ingress page, and one just over it is refused with 413. TestNotAcceptedNamesTheHostsCode in the package’s suite answers a refused delivery 503 with the host’s protocol code, and without an unauthored error’s text.
  • TestDaemonWebhookThreadGenerations: a ticket’s Work finishes, its next delivery opens a linked successor that parks on a type-only wait, and the delivery after that wakes the successor rather than starting more Work.
  • TestDaemonWebhookDeliveries: the composed daemon. A hook and an entry added by config apply take deliveries with no restart. Two deliveries and a retry run as two Works, each with its body in OS_INPUT_FILE and read back whole through os call webhook.delivery.read; a wrong token is refused, and doctor --check-secrets prints the URL.
  • TestCertificationFirstPartyPackages/webhook: ingress conformance, the route’s decisions and the operation’s refusal of unbound Work.
  • Issue #566 added the extension, so that a POST can be Work of its own rather than a trigger merged into a job’s one run.
  • Issue #572 added fan-out, so that one delivery can start Work for more than one binding without the core broadcasting it.
  • Issue #569 added sender signatures, so that a hook can take GitHub, Slack, Stripe and similar senders directly, with the URL token kept as well and a signed timestamp’s tolerance declared on the hook.
  • Issue #739 judged a signed timestamp at the listener’s receipt, which a forwarder can attest, and made a forwarder’s delivery ID the identity of a delivery to a hook with no delivery key.