Verify webhook signatures
SkyPay signs every delivery with your endpoint secret and sends:
X-SkyPay-Signature-V2: t=1794412918,v1=<hex HMAC>
X-SkyPay-Timestamp: 1794412918
X-SkyPay-Signature: sha256=<hex HMAC>
X-SkyPay-Event: payment.success
X-SkyPay-Delivery: <delivery id>
Verify X-SkyPay-Signature-V2. Its HMAC-SHA256 covers the timestamp and
the body together, as <timestamp>.<raw body>. Reject the delivery when the
timestamp is more than 5 minutes from your server's clock: a captured
delivery replayed later then fails, even though its signature is genuine.
X-SkyPay-Signature (body only) is still sent for older integrations, but it
does not protect against replay.
Signature verification must use the raw body bytes. Parsing and re-serializing JSON can change whitespace or key ordering and invalidate an otherwise legitimate signature.
const crypto = require('node:crypto')
const express = require('express')
const app = express()
const TOLERANCE_SECONDS = 5 * 60
function verifyWebhook(rawBody, header, secret) {
const parts = Object.fromEntries(
(header ?? '').split(',').map((part) => part.split('='))
)
const timestamp = Number(parts.t)
if (!Number.isInteger(timestamp) || typeof parts.v1 !== 'string') return false
if (Math.abs(Date.now() / 1000 - timestamp) > TOLERANCE_SECONDS) return false
const expected = Buffer.from(
crypto
.createHmac('sha256', secret)
.update(`${timestamp}.`)
.update(rawBody)
.digest('hex'),
'utf8'
)
const received = Buffer.from(parts.v1, 'utf8')
return (
expected.length === received.length &&
crypto.timingSafeEqual(expected, received)
)
}
app.post(
'/webhooks/skypay',
express.raw({ type: 'application/json' }),
async (req, res) => {
const signature = req.header('x-skypay-signature-v2')
if (
!verifyWebhook(req.body, signature, process.env.SKYPAY_WEBHOOK_SECRET)
) {
return res.status(400).send('Invalid signature')
}
const event = JSON.parse(req.body.toString('utf8'))
// Deliveries can repeat (retries); store each delivery id once.
await storeEventOnce(req.header('x-skypay-delivery'), event)
return res.status(204).send()
}
)
Do not use ordinary string equality for signatures. Timing-safe comparison reduces information leakage. Reject missing, malformed, or mismatched signatures before invoking any business logic.
Use a separate secret for each Sandbox and Live endpoint. Provider signatures are verified internally by SkyPay and are not the signature your merchant handler should validate.