Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions apps/docs/integrations/webhooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ osforms sends a `POST` request with `Content-Type: application/json`:

## Verifying signatures

Every request includes an `X-osforms-Signature-256` header:
Every request includes an `X-osforms-Signature` header:

```
X-osforms-Signature-256: sha256=<hex>
X-osforms-Signature: <hex>
```

The signature is computed as `HMAC-SHA256(requestBody, signingSecret)` where `requestBody` is the raw JSON string.
Expand All @@ -51,16 +51,17 @@ function verifySignature(
signature: string,
secret: string
): boolean {
const expected =
'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
const expected = crypto
.createHmac('sha256', secret)
.update(rawBody)
.digest('hex');

return crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
return crypto.timingSafeEqual(signatureBuffer, expectedBuffer);
}

// Express example
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
const sig = req.headers['x-osforms-signature-256'] as string;
const sig = req.headers['x-osforms-signature'] as string;
if (!verifySignature(req.body.toString(), sig, process.env.WEBHOOK_SECRET!)) {
return res.status(401).json({ error: 'Invalid signature' });
}
Expand Down