# Webhook Documentation Receive scan results as they finish, instead of polling the API. SIDEX sends an HTTP POST to your endpoint for each event. ## Events Add an endpoint under Settings, Webhooks, and choose which events it receives. | Event | Sent when | | --- | --- | | `scan.completed` | A scan finished with results | | `scan.failed` | A scan failed for good, after its automatic retries | ## Headers and Signature | Header | Value | | --- | --- | | `Content-Type` | application/json | | `X-Sidex-Event` | The event, scan.completed or scan.failed | | `X-Sidex-Signature` | Hex SHA-256 HMAC of the raw request body, keyed with your webhook secret | | `X-Sidex-Delivery-Id` | Unique id of this delivery | Compute the signature over the raw body rather than re-serialized JSON, and compare it in constant time. Use the whole secret as the key, including its `whsec_` prefix. These examples need only the standard library of each language. Node.js, node:crypto ```js import { createHmac, timingSafeEqual } from "node:crypto"; // rawBody is the untouched body, for example from express.raw({ type: "application/json" }) // signatureHeader is req.headers["x-sidex-signature"] export function isFromSidex(rawBody, signatureHeader, secret) { const expected = Buffer.from(createHmac("sha256", secret).update(rawBody).digest("hex")); const received = Buffer.from(signatureHeader ?? ""); return expected.length === received.length && timingSafeEqual(expected, received); } ``` Bun, Bun.CryptoHasher ```js import { timingSafeEqual } from "node:crypto"; // rawBody is await request.text(), read before any JSON parsing // signatureHeader is request.headers.get("X-Sidex-Signature") export function isFromSidex(rawBody, signatureHeader, secret) { const expected = Buffer.from(new Bun.CryptoHasher("sha256", secret).update(rawBody).digest("hex")); const received = Buffer.from(signatureHeader ?? ""); return expected.length === received.length && timingSafeEqual(expected, received); } ``` Go, crypto/hmac ```go package webhook import ( "crypto/hmac" "crypto/sha256" "encoding/hex" ) // rawBody is the result of io.ReadAll(r.Body), read before any JSON parsing. // signature is r.Header.Get("X-Sidex-Signature"). func IsFromSidex(rawBody []byte, signature, secret string) bool { mac := hmac.New(sha256.New, []byte(secret)) mac.Write(rawBody) expected := hex.EncodeToString(mac.Sum(nil)) return hmac.Equal([]byte(expected), []byte(signature)) } ``` Java 17 or newer, javax.crypto ```java import static java.nio.charset.StandardCharsets.UTF_8; import java.security.MessageDigest; import java.util.HexFormat; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public final class SidexWebhook { // rawBody is request.getInputStream().readAllBytes(), read before any JSON parsing // signatureHeader is request.getHeader("X-Sidex-Signature") public static boolean isFromSidex(byte[] rawBody, String signatureHeader, String secret) throws Exception { Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(secret.getBytes(UTF_8), "HmacSHA256")); byte[] expected = HexFormat.of().formatHex(mac.doFinal(rawBody)).getBytes(UTF_8); byte[] received = (signatureHeader == null ? "" : signatureHeader).getBytes(UTF_8); return MessageDigest.isEqual(expected, received); } } ``` PHP, hash\_hmac ```php