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

# Signature Verification

> Verify incoming Posttu webhook payloads using Svix signatures.

# Webhook Signature Verification

Posttu uses **Svix** for webhook delivery and security. Every webhook HTTP request sent to your endpoint includes cryptographic signature headers.

Verifying these signatures ensures that incoming requests genuinely originated from Posttu and have not been altered or forged in transit.

***

## Svix Webhook Headers

Each incoming HTTP POST request from Posttu contains the following headers:

| Header | Description |
| :- | :- |
| `svix-id` | Unique identifier for the webhook message. Useful for deduplication. |
| `svix-timestamp` | Unix timestamp (seconds) when the payload was sent. Used to guard against replay attacks. |
| `svix-signature` | Space-separated list of signature schemes and values (e.g. `v1,g0hM9SS...`). |

***

## How to Verify Signatures

You can verify signatures using the official Svix library for your preferred language or framework.

### TypeScript / Node.js

Install the `svix` package:

```bash theme={null}
npm install svix
# or
pnpm add svix
```

Verify the signature in your HTTP handler:

```typescript theme={null}
import { Webhook } from "svix";

export async function handlePosttuWebhook(req: Request) {
  const webhookSecret = process.env.POSTTU_WEBHOOK_SECRET;
  if (!webhookSecret) {
    throw new Error("Missing POSTTU_WEBHOOK_SECRET environment variable");
  }

  // Retrieve raw request body and Svix headers
  const payload = await req.text();
  const headers = {
    "svix-id": req.headers.get("svix-id")!,
    "svix-timestamp": req.headers.get("svix-timestamp")!,
    "svix-signature": req.headers.get("svix-signature")!,
  };

  const wh = new Webhook(webhookSecret);

  try {
    // Verify payload integrity & signature
    const event = wh.verify(payload, headers) as any;
    console.log("Verified event received:", event.type);
    
    // Process event...
    return new Response("OK", { status: 200 });
  } catch (err) {
    console.error("Invalid webhook signature:", err);
    return new Response("Invalid signature", { status: 400 });
  }
}
```

### Python

Install `svix`:

```bash theme={null}
pip install svix
```

Verify in Python:

```python theme={null}
from svix.webhooks import Webhook, WebhookVerificationError

webhook_secret = "whsec_..."
wh = Webhook(webhook_secret)

try:
    payload = request.get_data(as_text=True)
    headers = request.headers
    
    event = wh.verify(payload, headers)
    print(f"Verified event: {event['type']}")
except WebhookVerificationError as e:
    print(f"Invalid signature: {e}")
    return "Invalid signature", 400
```

***

## Security Best Practices

1. **Replay Protection**: The `svix` SDK automatically rejects messages sent older than 5 minutes to prevent replay attacks.
2. **Keep Secrets Secure**: Store your webhook signing secret (starting with `whsec_`) securely in environment variables.
3. **Use Raw Request Body**: Always pass the exact raw byte string or raw text payload to `wh.verify()`. Parsing JSON prior to verification alters white spaces and invalidates signatures.


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