> How Vaartix signs webhooks (Standard Webhooks), copy-paste verification code for Node, Python and PHP, and the mistakes that break it.

Source: https://vaartix.com/blog/verify-webhook-signatures

[Blog](https://vaartix.com/blog)

# Verify webhook signatures in Node, Python and PHP

28 November 2026 · 3 min read · Vaartix team

-   [Developers](https://vaartix.com/blog/tag/developers)

Your webhook URL is public. Anyone who finds it can send it a request that looks like "this email bounced" or "this email was delivered". If your app trusts those requests blindly, someone could mark good addresses as bad, or fake events in your logs. Every webhook from Vaartix is signed, so checking the signature first is how you know a request is real.

## How the signature works

Vaartix follows the open [Standard Webhooks](https://www.standardwebhooks.com) specification. Each request carries three headers: `webhook-id`, `webhook-timestamp` and `webhook-signature`. To check one:

1.  Join the id, the timestamp and the **raw** request body with dots: `{id}.{timestamp}.{body}`.
2.  Compute an HMAC-SHA256 of that string. The key is your endpoint's secret without its `whsec_` prefix, base64-decoded.
3.  Base64-encode the result and compare it, in constant time, with each `v1,` entry in the signature header.
4.  Reject requests whose timestamp is more than 5 minutes from your clock, so an intercepted request can't be replayed later.

![Diagram: Vaartix joins id, timestamp and body, signs them with HMAC-SHA256 using your endpoint secret, and sends the webhook-id, webhook-timestamp and webhook-signature headers. Your server takes the raw body, computes the same HMAC with the same secret, compares it with each v1 signature in constant time and checks the timestamp is within 5 minutes. If it matches and is on time, reply 2xx; otherwise reply 400 and ignore it.](https://vaartix.com/blog/img/verify-webhook-signatures/signature-flow.png)

Both sides compute the same signature from the same secret. Only a matching, recent request is real.

You rarely need to write that yourself: the SDKs do it in one call.

## Node.js (Express)

```
import express from 'express';
import { verifyWebhook, WebhookVerificationError } from 'vaartix';

const app = express();

app.post('/webhooks/vaartix', express.raw({ type: 'application/json' }), (req, res) => {
  let event;
  try {
    event = verifyWebhook({
      payload: req.body, // a Buffer, thanks to express.raw()
      headers: req.headers,
      secret: process.env.VAARTIX_WEBHOOK_SECRET,
    });
  } catch (err) {
    if (err instanceof WebhookVerificationError) return res.status(400).send('Invalid signature');
    throw err;
  }
  res.sendStatus(200);
  // Handle the event after responding, e.g. queue it.
});
```

## Python (Flask)

```
import os
from flask import Flask, request
from vaartix import WebhookVerificationError, verify_webhook

app = Flask(__name__)

@app.post("/webhooks/vaartix")
def vaartix_webhook():
    try:
        event = verify_webhook(request.get_data(), request.headers, os.environ["VAARTIX_WEBHOOK_SECRET"])
    except WebhookVerificationError:
        return "Invalid signature", 400
    # handle event["type"] and event["data"]
    return "", 200
```

On Django, the same call works with `request.body`; see [Send email from Django](https://vaartix.com/docs/guides/django/).

## PHP

```
<?php
use Vaartix\Exceptions\WebhookVerificationException;
use Vaartix\Webhook;

try {
    $event = Webhook::verify(
        file_get_contents('php://input'),
        getallheaders(),
        getenv('VAARTIX_WEBHOOK_SECRET'),
    );
} catch (WebhookVerificationException $e) {
    http_response_code(400);
    exit;
}
// handle $event['type'] and $event['data']
http_response_code(200);
```

On Laravel, pass `$request->getContent()` and `$request->headers->all()`; see [Send email from Laravel](https://vaartix.com/docs/guides/laravel/).

## The mistakes that break verification

-   **Parsing the body first.** The signature covers the exact bytes Vaartix sent. If your framework parses the JSON and you re-serialise it, spacing can change and the check fails. Always verify the raw body: `express.raw()`, `request.get_data()`, `php://input`.
-   **Using the wrong secret.** Each endpoint has its own `whsec_...` secret, shown once when you create it. Store it in an environment variable.
-   **A wrong server clock.** Requests older than 5 minutes are rejected, so a server whose clock is far off rejects real ones too. Keep your clock synced.
-   **CSRF protection** in Laravel or Django blocking the route. Exempt it: the signature check is what keeps it safe.
-   **Slow handlers.** Answer with a `2xx` within 10 seconds, and do slow work afterwards or in a background job.

Test your endpoint without real email by sending to `bounced@test.vaartix.com`: it produces a real, signed `email.bounced` webhook. The full reference is [Verify signatures](https://vaartix.com/docs/webhooks/verify/).

## Related posts

-   [Sending OTPs: delays, retries and what users actually see](https://vaartix.com/blog/otp-email-delays) 30 November 2026
-   [Send email from your AI assistant with the Vaartix MCP server](https://vaartix.com/blog/connect-ai-assistant-mcp) 29 November 2026
-   [Give each tool its own API key: recipient limits, From limits and daily caps](https://vaartix.com/blog/scoped-api-keys-ai-agents) 26 November 2026

**Vaartix is a transactional email API built in India.** It sends through Amazon SES in Mumbai, keeps your data in India and is priced in rupees. Anyone can sign up free, and the Free plan has every feature.

[Sign up free](https://app.vaartix.com/?signup)
