# Webhooks

Webhook operations require an enabled workspace. See [pricing](/pricing) for plans and [your account](/account) for subscription management. Keep workspace keys and signing secrets server-side.

## Register a receiver

Use an HTTPS endpoint that you control. Subscribe to `cve.published` for new CVE records. Each publication includes the CVE ID, state, publication time, and index time.

```sh
curl -fsS 'https://security.getomg.dev/api/v1/commercial/webhooks' \
  -H "Authorization: Bearer $OMG_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"target_url":"https://hooks.example.com/omg","events":["cve.published"]}'
```

Replace the example URL with your endpoint. Store the signing secret returned at creation in your receiver's secret store.

## Verify the original bytes

Read `X-OMG-Signature` as `t=<unix_seconds>,v1=<hex_digest>`. Compute HMAC-SHA256 with the signing secret over the timestamp, a literal period, and the request body bytes as received. Verify the timestamp against your receiver's freshness window and compare digests in constant time before parsing the body or applying any action.

```js
import { createHmac, timingSafeEqual } from 'node:crypto';

function verifyDelivery(rawBody, signature, secret, now = Date.now()) {
  const match = /^t=(\d+),v1=([a-fA-F0-9]{64})$/.exec(signature ?? '');
  if (!match) return false;

  const [, timestamp, digest] = match;
  const seconds = Number(timestamp);
  if (!Number.isSafeInteger(seconds) || Math.abs(now / 1000 - seconds) > 300) return false;

  const expected = createHmac('sha256', secret)
    .update(timestamp + '.')
    .update(rawBody)
    .digest();
  return timingSafeEqual(expected, Buffer.from(digest, 'hex'));
}
```

Pass a `Buffer` containing the raw request body. The example allows a five-minute clock window. Keep the receiver clock synchronized.

## Acknowledge and inspect delivery

Read `X-OMG-Event` to route a verified event. Store `X-OMG-Delivery` with the event before returning a success response. Use that identifier to suppress duplicate processing if you receive the delivery again.

Use `GET /api/v1/commercial/webhooks` to inspect delivery history. To put a delivery back into pending status, use its ID in a replay request.

```sh
curl -fsS 'https://security.getomg.dev/api/v1/commercial/webhooks/replay' \
  -H "Authorization: Bearer $OMG_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"delivery_id":"YOUR_DELIVERY_ID"}'
```

Check delivery history again for the result. See the [API reference](/docs/api-reference/#work-with-an-enabled-workspace) for inputs and statuses.

## Stop a receiver

Use the subscription ID returned during registration or shown in the subscriptions list.

```sh
curl -fsS -X DELETE 'https://security.getomg.dev/api/v1/commercial/webhooks' \
  -H "Authorization: Bearer $OMG_API_KEY" -H 'Content-Type: application/json' \
  -d '{"subscription_id":"YOUR_SUBSCRIPTION_ID"}'
```

The receiver returns `active: false` and releases its slot. Delivery history remains available. Attempts already in flight can finish. To use the endpoint again, register a new subscription and save its new signing secret.
