---
title: Verify webhook signatures (mandatory)
description: Verify GaaPay webhook signatures with HMAC-SHA256 over timestamp.body, constant-time comparison and a five-minute replay window. Working Node example.
url: https://gaapay.com/docs/verify
updated: 2026-12-04
language: en
---

The signed string is `timestamp + "." + body`, HMAC-SHA256. Headers:

```
x-gaapay-event: payment.succeeded
x-gaapay-event-id: evt_01m5f…
x-gaapay-timestamp: 1792596770
x-gaapay-signature: v1=9d1f…
x-gaapay-delivery: 1
```

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

export function verifyGaaPayWebhook({ secret, timestamp, body, signature }) {
  // Replay protection: reject anything older than 5 minutes
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > 300) return false;
  const expected = 'v1=' + createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex');
  const a = Buffer.from(expected);
  const b = Buffer.from(signature || '');
  return a.length === b.length && timingSafeEqual(a, b);
}
```

**Three rules:** ① verify the signature, or anyone can forge "payment succeeded" and get free goods; ② consume idempotently by `event_id`, because delivery is at-least-once; ③ trust `payment.succeeded`, never the redirect parameters in the browser.
