You can verify that webhook events by checking the signature header of the event payload.The signature header is a X-Ghost-Signature header that is signed with the secret key. The signature is an HMAC-SHA256 hash of the event payload.
Copy
Ask AI
import crypto from 'crypto'/** * Verify the signature of a Ghost webhook event. * @param key - The webhook signing key. * @param payload - The raw request body of the webhook event. * @param headerSignature - The signature header, in the format "sha256=<signature>". * @returns True if the signature is valid, false otherwise. */function verifySignature(key: string, payload: string, headerSignature: string): boolean { const [algo, sentSignature] = headerSignature.split('=') if (algo !== 'sha256') { return false } const computed = crypto.createHmac('sha256', key).update(payload).digest('hex') return crypto.timingSafeEqual(Buffer.from(computed), Buffer.from(sentSignature))}
Ghost webhook events are retried up to 5 times if the destination URL returns a status code of 400 or above within 10 seconds. The retry interval is as follows (after the initial attempt):
All Ghost webhook events are sent from a static source IP address. You may need to allowlist this IP address to ensure that webhook events are not blocked by a firewall.