( payload: string, signature: string, timestamp: string )
| 464 | * See: https://developers.zoom.us/docs/api/rest/webhook-reference/#verify-webhook-events |
| 465 | */ |
| 466 | export function verifyWebhookSignature( |
| 467 | payload: string, |
| 468 | signature: string, |
| 469 | timestamp: string |
| 470 | ): boolean { |
| 471 | const webhookSecret = process.env.ZOOM_WEBHOOK_SECRET; |
| 472 | if (!webhookSecret) { |
| 473 | logger.error('ZOOM_WEBHOOK_SECRET not configured - rejecting webhook'); |
| 474 | return false; |
| 475 | } |
| 476 | |
| 477 | const message = `v0:${timestamp}:${payload}`; |
| 478 | const expectedSignature = 'v0=' + crypto |
| 479 | .createHmac('sha256', webhookSecret) |
| 480 | .update(message) |
| 481 | .digest('hex'); |
| 482 | |
| 483 | try { |
| 484 | return crypto.timingSafeEqual( |
| 485 | Buffer.from(signature), |
| 486 | Buffer.from(expectedSignature) |
| 487 | ); |
| 488 | } catch { |
| 489 | // timingSafeEqual throws if buffers have different lengths |
| 490 | return false; |
| 491 | } |
| 492 | } |
no test coverage detected