> ## Documentation Index
> Fetch the complete documentation index at: https://docs.postinger.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Verify signatures

> Check that a request comes from Postinger and wasn't changed.

Postinger signs every delivery following [Standard Webhooks](https://www.standardwebhooks.com), so any of its libraries (or Svix's) can verify it. Each request carries three headers:

| Header | Value |
| - | - |
| `webhook-id` | The event's ID. |
| `webhook-timestamp` | When it was sent, in Unix seconds. |
| `webhook-signature` | `v1,` and the base64 HMAC-SHA256 of `{id}.{timestamp}.{body}`. |

The key is your secret's base64 part, after `whsec_`.

## With a library

```ts Node.js theme={"system"}
import { Webhook } from "standardwebhooks";

const webhook = new Webhook(process.env.POSTINGER_WEBHOOK_SECRET);

app.post("/webhooks/postinger", express.raw({ type: "application/json" }), async (req, res) => {
  let event;
  try {
    event = webhook.verify(req.body.toString(), req.headers);
  } catch {
    return res.sendStatus(400);
  }

  await queue.add(event);
  res.sendStatus(200);
});
```

```python Python theme={"system"}
from standardwebhooks.webhooks import Webhook

webhook = Webhook(os.environ["POSTINGER_WEBHOOK_SECRET"])

@app.post("/webhooks/postinger")
def postinger(request):
    try:
        event = webhook.verify(request.body, request.headers)
    except Exception:
        return Response(status=400)

    queue.put(event)
    return Response(status=200)
```

Store the event (a queue, a database table) before you answer `200`, and do the work afterwards. Once you answer `2xx`, Postinger counts the delivery as done and won't send it again, so an event you only held in memory is lost if handling it fails. If storing it fails, answer `5xx` and Postinger retries.

## By hand

**1. Rebuild what was signed**

Join the `webhook-id` header, the `webhook-timestamp` header and the **raw** request body with dots: `{id}.{timestamp}.{body}`. Use the body exactly as it arrived, before any JSON parsing.

**2. Sign it**

Base64-decode the part of your secret after `whsec_`, and compute the HMAC-SHA256 of the string with it. Base64-encode the result.

**3. Compare**

`webhook-signature` holds one or more space-separated `v1,<signature>` entries. Accept the request if any of them matches yours, compared in constant time.

**4. Check the time**

Reject requests whose `webhook-timestamp` is more than a few minutes from your clock, so an old request can't be replayed.

## Rotating the secret

Rotate the secret under **Webhooks** if it may have leaked. The old secret keeps signing alongside the new one for **24 hours**, so `webhook-signature` carries both while you switch over.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.