-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(triggers): add Zoom webhook triggers #3992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0334c76
feat(triggers): add Zoom webhook triggers with challenge-response and…
waleedlatif1 2720425
fix(triggers): use webhook.isActive instead of non-existent deletedAt…
waleedlatif1 db37b6e
fix(triggers): address PR review feedback for Zoom webhooks
waleedlatif1 9901a77
lint
waleedlatif1 4fd970a
fix(triggers): harden Zoom webhook security per PR review
waleedlatif1 bd0a5aa
fix(triggers): rename type to meeting_type to avoid TriggerOutput typ…
waleedlatif1 78bec79
fix(triggers): make challenge signature verification mandatory, not o…
waleedlatif1 6e6aa21
fix(triggers): fail closed on unknown trigger IDs and update Zoom lan…
waleedlatif1 1c15918
fix(triggers): add missing id fields to Zoom trigger entries in integ…
waleedlatif1 3813931
fix(triggers): increase Zoom timestamp tolerance to 300s per Zoom docs
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| import crypto from 'crypto' | ||
| import { db, webhook } from '@sim/db' | ||
| import { createLogger } from '@sim/logger' | ||
| import { and, eq } from 'drizzle-orm' | ||
| import type { NextRequest } from 'next/server' | ||
| import { NextResponse } from 'next/server' | ||
| import { safeCompare } from '@/lib/core/security/encryption' | ||
| import type { | ||
| AuthContext, | ||
| EventMatchContext, | ||
| WebhookProviderHandler, | ||
| } from '@/lib/webhooks/providers/types' | ||
|
|
||
| const logger = createLogger('WebhookProvider:Zoom') | ||
|
|
||
| /** | ||
| * Validate Zoom webhook signature using HMAC-SHA256. | ||
| * Zoom sends `x-zm-signature` as `v0=<hex>` and `x-zm-request-timestamp`. | ||
| * The message to hash is `v0:{timestamp}:{rawBody}`. | ||
| */ | ||
| function validateZoomSignature( | ||
| secretToken: string, | ||
| signature: string, | ||
| timestamp: string, | ||
| body: string | ||
| ): boolean { | ||
| try { | ||
| if (!secretToken || !signature || !timestamp || !body) { | ||
| return false | ||
| } | ||
|
|
||
| const nowSeconds = Math.floor(Date.now() / 1000) | ||
| const requestSeconds = Number.parseInt(timestamp, 10) | ||
| if (Number.isNaN(requestSeconds) || Math.abs(nowSeconds - requestSeconds) > 300) { | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return false | ||
| } | ||
|
|
||
| const message = `v0:${timestamp}:${body}` | ||
| const computedHash = crypto.createHmac('sha256', secretToken).update(message).digest('hex') | ||
| const expectedSignature = `v0=${computedHash}` | ||
|
|
||
| return safeCompare(expectedSignature, signature) | ||
| } catch (err) { | ||
| logger.error('Zoom signature validation error', err) | ||
| return false | ||
| } | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const zoomHandler: WebhookProviderHandler = { | ||
| verifyAuth({ request, rawBody, requestId, providerConfig }: AuthContext) { | ||
| const secretToken = providerConfig.secretToken as string | undefined | ||
| if (!secretToken) { | ||
| logger.warn( | ||
| `[${requestId}] Zoom webhook missing secretToken in providerConfig — rejecting request` | ||
| ) | ||
| return new NextResponse('Unauthorized - Zoom secret token not configured', { status: 401 }) | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const signature = request.headers.get('x-zm-signature') | ||
| const timestamp = request.headers.get('x-zm-request-timestamp') | ||
|
|
||
| if (!signature || !timestamp) { | ||
| logger.warn(`[${requestId}] Zoom webhook missing signature or timestamp header`) | ||
| return new NextResponse('Unauthorized - Missing Zoom signature', { status: 401 }) | ||
| } | ||
|
|
||
| if (!validateZoomSignature(secretToken, signature, timestamp, rawBody)) { | ||
| logger.warn(`[${requestId}] Zoom webhook signature verification failed`) | ||
| return new NextResponse('Unauthorized - Invalid Zoom signature', { status: 401 }) | ||
| } | ||
|
|
||
| return null | ||
| }, | ||
|
|
||
| async matchEvent({ webhook: wh, workflow, body, requestId, providerConfig }: EventMatchContext) { | ||
| const triggerId = providerConfig.triggerId as string | undefined | ||
| const obj = body as Record<string, unknown> | ||
| const event = obj.event as string | undefined | ||
|
|
||
| if (triggerId) { | ||
| const { isZoomEventMatch } = await import('@/triggers/zoom/utils') | ||
| if (!isZoomEventMatch(triggerId, event || '')) { | ||
| logger.debug( | ||
| `[${requestId}] Zoom event mismatch for trigger ${triggerId}. Event: ${event}. Skipping execution.`, | ||
| { | ||
| webhookId: wh.id, | ||
| workflowId: workflow.id, | ||
| triggerId, | ||
| receivedEvent: event, | ||
| } | ||
| ) | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| return true | ||
| }, | ||
|
|
||
| /** | ||
| * Handle Zoom endpoint URL validation challenges. | ||
| * Zoom sends an `endpoint.url_validation` event with a `plainToken` that must | ||
| * be hashed with the app's secret token and returned alongside the original token. | ||
| */ | ||
| async handleChallenge(body: unknown, request: NextRequest, requestId: string, path: string) { | ||
| const obj = body as Record<string, unknown> | null | ||
| if (obj?.event !== 'endpoint.url_validation') { | ||
| return null | ||
| } | ||
|
|
||
| const payload = obj.payload as Record<string, unknown> | undefined | ||
| const plainToken = payload?.plainToken as string | undefined | ||
| if (!plainToken) { | ||
| return null | ||
| } | ||
|
|
||
| logger.info(`[${requestId}] Zoom URL validation request received for path: ${path}`) | ||
|
|
||
| // Look up the webhook record to get the secret token from providerConfig | ||
| let secretToken = '' | ||
| try { | ||
| const webhooks = await db | ||
| .select() | ||
| .from(webhook) | ||
| .where( | ||
| and(eq(webhook.path, path), eq(webhook.provider, 'zoom'), eq(webhook.isActive, true)) | ||
| ) | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (webhooks.length > 0) { | ||
| const config = webhooks[0].providerConfig as Record<string, unknown> | null | ||
| secretToken = (config?.secretToken as string) || '' | ||
| } | ||
| } catch (err) { | ||
| logger.warn(`[${requestId}] Failed to look up webhook secret for Zoom validation`, err) | ||
| return null | ||
| } | ||
|
|
||
| if (!secretToken) { | ||
| logger.warn( | ||
| `[${requestId}] No secret token configured for Zoom URL validation on path: ${path}` | ||
| ) | ||
| return null | ||
| } | ||
|
|
||
| // Verify the challenge request's signature to prevent HMAC oracle attacks | ||
| const signature = request.headers.get('x-zm-signature') | ||
| const timestamp = request.headers.get('x-zm-request-timestamp') | ||
| if (!signature || !timestamp) { | ||
| logger.warn(`[${requestId}] Zoom challenge request missing signature headers — rejecting`) | ||
| return null | ||
| } | ||
| const rawBody = JSON.stringify(body) | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (!validateZoomSignature(secretToken, signature, timestamp, rawBody)) { | ||
| logger.warn(`[${requestId}] Zoom challenge request failed signature verification`) | ||
| return null | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const hashForValidate = crypto | ||
| .createHmac('sha256', secretToken) | ||
| .update(plainToken) | ||
| .digest('hex') | ||
|
|
||
| return NextResponse.json({ | ||
| plainToken, | ||
| encryptedToken: hashForValidate, | ||
| }) | ||
| }, | ||
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
waleedlatif1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.