# Webhooks

A webhook tells your server when zkao confirms a finding, so you do not have to poll. Project admins add one on the project’s **Integrations** page. The page gives you its signing secret, which starts with `whsec_`, and can send a test event.

## Events

| Event               | When it is sent                                                                                                   |
| ------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `finding.confirmed` | A few minutes after a finding is confirmed, whether zkao or a project member confirmed it. Sent once per finding. |
| `webhook.test`      | When an admin sends a test event from the Integrations page.                                                      |

Each event is a `POST` with a JSON body. `type` names the event, and `id` identifies it.

```json
{
  "id": "cm4qa1b2c0002efgh3456mnop",
  "type": "finding.confirmed",
  "createdAt": "2026-11-29T14:03:11.000Z",
  "data": {
    "projectId": "cm4p1x2y30000abcd1234efgh",
    "finding": {
      "id": "cm4q9a8b70001wxyz5678ijkl",
      "displayId": 42,
      "title": "Verifier skips the final pairing check",
      "location": "src/verifier.rs:118",
      "severity": "HIGH",
      "category": "Soundness",
      "triageStatus": "CONFIRMED",
      "resolutionStatus": "NOT_STARTED",
      "confirmationEvidence": "POC",
      "confirmedAt": "2026-11-29T13:58:40.000Z",
      "confirmedBy": "zkao",
      "origin": "scan",
      "scanId": "cm4q8z7y60000mnop9012qrst",
      "repository": { "owner": "acme", "name": "verifier" },
      "webUrl": "https://zkao.io/..."
    }
  }
}
```

`confirmedBy` is `member` when a project member overrode or reopened the verdict. `origin` is `report` for a finding that came from a [vulnerability report](https://docs.staging.zkao.io/guides/reports/). The event carries a summary. Fetch the full finding with `zkao findings get <id>` or `GET /projects/{projectId}/findings/{findingId}`.

The SDK exports the payload types as `FindingConfirmedEvent`, `WebhookTestEvent`, and their union `WebhookEvent`.

## Headers

| Header            | Value                                                                                                    |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `zkao-signature`  | `t=<unix seconds>,v1=<hex>`. `v1` is the HMAC-SHA256 of `<t>.<raw body>`, keyed with the signing secret. |
| `zkao-event-id`   | The event’s id. Retries reuse it.                                                                        |
| `zkao-event-type` | The event’s `type`.                                                                                      |

## Verify each request

Compute the signature over the raw body, exactly as received. Parsing the JSON and serializing it again changes the bytes and breaks the check. Reject a request whose signature does not match, or whose `t` is more than five minutes old.

```ts
import { createHmac, timingSafeEqual } from "node:crypto";
import type { WebhookEvent } from "@zksecurity/zkao-sdk";


const TOLERANCE_SECONDS = 5 * 60;


export function verifyZkaoWebhook(
  rawBody: string,
  signatureHeader: string,
  secret: string
): WebhookEvent | null {
  const fields = new Map(
    signatureHeader.split(",").map((part) => {
      const index = part.indexOf("=");
      return [part.slice(0, index).trim(), part.slice(index + 1).trim()];
    })
  );
  const t = Number(fields.get("t"));
  const given = fields.get("v1") ?? "";
  if (!Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > TOLERANCE_SECONDS) {
    return null;
  }
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  const a = Buffer.from(given, "hex");
  const b = Buffer.from(expected, "hex");
  if (a.length !== b.length || !timingSafeEqual(a, b)) {
    return null;
  }
  return JSON.parse(rawBody) as WebhookEvent;
}
```

Use the whole secret, including its `whsec_` prefix, as the key.

## Respond and deduplicate

Answer with any 2xx status within 10 seconds. Do slow work after you answer, not before. Any other answer, or no answer in time, is retried with backoff for about a day. A retry has the same event id, so record the ids you have handled and skip repeats.

Note

The URL must use `https` and be reachable from the public internet. Redirects are not followed, so register the final URL.
