Malla-Signature: t=1760281445,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bdHow it works
tis when the event was signed (unix seconds).v1is the hex HMAC-SHA256 of"<t>.<raw body>", keyed with your endpoint's whole secret (includingwhsec_).
To verify: recompute the HMAC over the exact bytes you received, compare it in constant time with every v1 in the header, and reject timestamps more than 5 minutes from now.
With the SDK
constructWebhookEvent verifies and returns a typed event, or throws MallaSignatureError. It uses WebCrypto, so the same code runs on Node, Bun, Deno, Workers and edge runtimes.
// app/api/webhooks/malla/route.ts
import { constructWebhookEvent } from '@malla/business/webhooks'
export async function POST(request: Request) {
const body = await request.text()
let event
try {
event = await constructWebhookEvent(body, request.headers.get('Malla-Signature'), process.env.MALLA_WEBHOOK_SECRET!)
}
catch {
return new Response('Invalid signature', { status: 400 })
}
if (event.type === 'order.paid')
await queue.send({ orderId: event.data.object.id, eventId: event.id })
return new Response(null, { status: 200 })
}import { constructWebhookEvent } from '@malla/business/webhooks'
import express from 'express'
const app = express()
// express.raw keeps the body as a Buffer: don't use express.json() on this route.
app.post('/webhooks/malla', express.raw({ type: 'application/json' }), async (req, res) => {
try {
const event = await constructWebhookEvent(req.body, req.get('Malla-Signature'), process.env.MALLA_WEBHOOK_SECRET!)
await handle(event) // dedupe on event.id
res.sendStatus(200)
}
catch {
res.sendStatus(400)
}
})import { constructWebhookEvent } from '@malla/business/webhooks'
import { Hono } from 'hono'
const app = new Hono()
app.post('/webhooks/malla', async (c) => {
const event = await constructWebhookEvent(await c.req.text(), c.req.header('Malla-Signature'), c.env.MALLA_WEBHOOK_SECRET)
.catch(() => null)
if (!event)
return c.text('Invalid signature', 400)
c.executionCtx.waitUntil(handle(event))
return c.body(null, 200)
})To only check a signature, verifyWebhookSignature(body, header, secret) returns a boolean.
Without the SDK
Node.js, no dependencies:
import { Buffer } from 'node:buffer'
import { createHmac, timingSafeEqual } from 'node:crypto'
/** Returns true if `rawBody` was signed by Malla with `secret` within the last `tolerance` seconds. */
export function verifyMallaSignature(rawBody, header, secret, tolerance = 300) {
const parts = (header ?? '').split(',').map(part => part.trim().split('='))
const t = Number(parts.find(([key]) => key === 't')?.[1])
const signatures = parts.filter(([key]) => key === 'v1').map(([, value]) => value)
if (!t || signatures.length === 0 || Math.abs(Date.now() / 1000 - t) > tolerance)
return false
const expected = Buffer.from(createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex'))
return signatures.some(sig => sig.length === expected.length && timingSafeEqual(Buffer.from(sig), expected))
}The same steps work in any language with HMAC-SHA256.
Testing your handler
Sign your own fixtures with generateTestHeader:
import { generateTestHeader } from '@malla/business/webhooks'
const body = JSON.stringify({ id: 'evt_test', type: 'order.paid', data: { object: { id: 'o_1' } } })
const response = await app.request('/webhooks/malla', {
method: 'POST',
body,
headers: { 'Malla-Signature': await generateTestHeader(body, 'whsec_test') },
})Or click Send test event in the dashboard to receive a real, signed webhook.test event.
Rotating the secret
Regenerating the secret (dashboard or POST /webhook-endpoints/:id/roll-secret) invalidates the old one immediately. Roll it, update your environment, and resend any deliveries that failed in between.