Skip to content

Commit 63e2afd

Browse files
committed
fix(integrations): validate fathom, grain, obsidian and fireflies
1 parent db05a26 commit 63e2afd

13 files changed

Lines changed: 143 additions & 5 deletions

File tree

‎apps/docs/content/docs/integrations/fathom.mdx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ Trigger workflow when new meeting content is ready in Fathom
265265
| --------- | ---- | ----------- |
266266
| `title` | string | Meeting title |
267267
| `meeting_title` | string | Calendar event title |
268+
| `meeting_type` | string | Meeting type name, or null when none is assigned |
268269
| `recording_id` | number | Unique recording ID |
270+
| `meeting_url` | string | Underlying video call URL \(Zoom, Meet, Teams\), or null |
269271
| `url` | string | URL to view the meeting in Fathom |
270272
| `share_url` | string | Shareable URL for the meeting |
271273
| `created_at` | string | ISO 8601 creation timestamp |
@@ -275,9 +277,12 @@ Trigger workflow when new meeting content is ready in Fathom
275277
| `recording_end_time` | string | Recording end time |
276278
| `transcript_language` | string | Language of the transcript |
277279
| `calendar_invitees_domains_type` | string | Domain type: only_internal or one_or_more_external |
280+
| `shared_with` | string | Sharing scope: no_teams, single_team, multiple_teams, or all_teams |
278281
| `recorded_by` | object | Recorder details |
279282
| ↳ `name` | string | Name of the recorder |
280283
| ↳ `email` | string | Email of the recorder |
284+
| ↳ `email_domain` | string | Email domain of the recorder |
285+
| ↳ `team` | string | Recorder team name, or null |
281286
| `calendar_invitees` | array | Array of calendar invitees with name and email |
282287
| `default_summary` | object | Meeting summary |
283288
| ↳ `template_name` | string | Summary template name |
@@ -311,7 +316,9 @@ Generic webhook trigger for all Fathom events
311316
| --------- | ---- | ----------- |
312317
| `title` | string | Meeting title |
313318
| `meeting_title` | string | Calendar event title |
319+
| `meeting_type` | string | Meeting type name, or null when none is assigned |
314320
| `recording_id` | number | Unique recording ID |
321+
| `meeting_url` | string | Underlying video call URL \(Zoom, Meet, Teams\), or null |
315322
| `url` | string | URL to view the meeting in Fathom |
316323
| `share_url` | string | Shareable URL for the meeting |
317324
| `created_at` | string | ISO 8601 creation timestamp |
@@ -321,9 +328,12 @@ Generic webhook trigger for all Fathom events
321328
| `recording_end_time` | string | Recording end time |
322329
| `transcript_language` | string | Language of the transcript |
323330
| `calendar_invitees_domains_type` | string | Domain type: only_internal or one_or_more_external |
331+
| `shared_with` | string | Sharing scope: no_teams, single_team, multiple_teams, or all_teams |
324332
| `recorded_by` | object | Recorder details |
325333
| ↳ `name` | string | Name of the recorder |
326334
| ↳ `email` | string | Email of the recorder |
335+
| ↳ `email_domain` | string | Email domain of the recorder |
336+
| ↳ `team` | string | Recorder team name, or null |
327337
| `calendar_invitees` | array | Array of calendar invitees with name and email |
328338
| `default_summary` | object | Meeting summary |
329339
| ↳ `template_name` | string | Summary template name |

‎apps/docs/content/docs/integrations/fireflies.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ Trigger workflow when a Fireflies meeting transcription is complete
303303
| `eventType` | string | The type of event \(e.g. Transcription completed, meeting.transcribed\) |
304304
| `clientReferenceId` | string | Custom reference ID if set during upload |
305305
| `timestamp` | number | Unix timestamp in milliseconds when the event was fired \(V2 webhooks\) |
306+
| `reprocessedAt` | number | Unix timestamp in milliseconds of the transcript or summary change that caused a resend \(V2 webhooks; absent on a meeting's first delivery\) |
306307

307308
</ReferenceDetails>
308309

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import crypto from 'node:crypto'
2+
import { NextRequest } from 'next/server'
3+
import { describe, expect, it } from 'vitest'
4+
import { fathomHandler } from '@/lib/webhooks/providers/fathom'
5+
6+
const SECRET_BYTES = Buffer.from('fathom-test-secret-key-padding!!!!!!')
7+
const SIGNING_SECRET = `whsec_${SECRET_BYTES.toString('base64')}`
8+
9+
function sign(msgId: string, timestamp: string, rawBody: string): string {
10+
const sig = crypto
11+
.createHmac('sha256', SECRET_BYTES)
12+
.update(`${msgId}.${timestamp}.${rawBody}`, 'utf8')
13+
.digest('base64')
14+
return `v1,${sig}`
15+
}
16+
17+
function request(msgId: string, timestamp: string, signature: string): NextRequest {
18+
return new NextRequest('http://localhost/test', {
19+
headers: {
20+
'webhook-id': msgId,
21+
'webhook-timestamp': timestamp,
22+
'webhook-signature': signature,
23+
},
24+
})
25+
}
26+
27+
const nowSeconds = () => `${Math.floor(Date.now() / 1000)}`
28+
const rawBody = JSON.stringify({ title: 'QBR', recording_id: 123 })
29+
30+
describe('Fathom webhook provider verifyAuth', () => {
31+
it('rejects a forged delivery when the webhook has a signing secret', async () => {
32+
const res = await fathomHandler.verifyAuth?.({
33+
webhook: {},
34+
workflow: {},
35+
request: request('msg_1', nowSeconds(), 'v1,Zm9yZ2Vk'),
36+
rawBody,
37+
requestId: 'fathom-t1',
38+
providerConfig: { signingSecret: SIGNING_SECRET },
39+
})
40+
41+
expect(res?.status).toBe(401)
42+
})
43+
44+
it('accepts a correctly signed delivery', async () => {
45+
const ts = nowSeconds()
46+
const res = await fathomHandler.verifyAuth?.({
47+
webhook: {},
48+
workflow: {},
49+
request: request('msg_1', ts, sign('msg_1', ts, rawBody)),
50+
rawBody,
51+
requestId: 'fathom-t2',
52+
providerConfig: { signingSecret: SIGNING_SECRET },
53+
})
54+
55+
expect(res).toBeNull()
56+
})
57+
58+
it('keeps accepting webhooks registered before the secret was stored', async () => {
59+
const res = await fathomHandler.verifyAuth?.({
60+
webhook: {},
61+
workflow: {},
62+
request: request('msg_1', nowSeconds(), 'v1,Zm9yZ2Vk'),
63+
rawBody,
64+
requestId: 'fathom-t3',
65+
providerConfig: {},
66+
})
67+
68+
expect(res ?? null).toBeNull()
69+
})
70+
})

‎apps/sim/lib/webhooks/providers/fathom.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
import { createLogger } from '@sim/logger'
2+
import type { NextResponse } from 'next/server'
23
import { outboundFetch } from '@/lib/core/network/outbound-fetch.server'
34
import { validateAlphanumericId } from '@/lib/core/security/input-validation'
45
import { getNotificationUrl, getProviderConfig } from '@/lib/webhooks/provider-subscription-utils'
56
import { WebhookDeploymentConfigurationError } from '@/lib/webhooks/providers/errors'
67
import type {
8+
AuthContext,
79
DeleteSubscriptionContext,
810
SubscriptionContext,
911
SubscriptionResult,
1012
WebhookProviderHandler,
1113
} from '@/lib/webhooks/providers/types'
14+
import { verifyStandardWebhookRequest } from '@/lib/webhooks/providers/utils'
1215

1316
const logger = createLogger('WebhookProvider:Fathom')
1417

1518
export const fathomHandler: WebhookProviderHandler = {
19+
/**
20+
* Fathom signs deliveries with the Standard Webhooks scheme using the secret
21+
* returned when Sim registers the webhook. Rows registered before Sim stored
22+
* that secret have none and keep being accepted until they are redeployed.
23+
*/
24+
verifyAuth({ request, rawBody, requestId, providerConfig }: AuthContext): NextResponse | null {
25+
const signingSecret = providerConfig.signingSecret as string | undefined
26+
if (!signingSecret?.trim()) return null
27+
28+
return verifyStandardWebhookRequest({
29+
request,
30+
rawBody,
31+
requestId,
32+
secret: signingSecret,
33+
providerLabel: 'Fathom',
34+
})
35+
},
36+
1637
async createSubscription(ctx: SubscriptionContext): Promise<SubscriptionResult | undefined> {
1738
const { webhook, requestId } = ctx
1839
try {
@@ -109,7 +130,12 @@ export const fathomHandler: WebhookProviderHandler = {
109130
fathomWebhookId: responseBody.id,
110131
})
111132

112-
return { providerConfigUpdates: { externalId: responseBody.id } }
133+
const signingSecret =
134+
typeof responseBody.secret === 'string' && responseBody.secret.trim()
135+
? responseBody.secret
136+
: undefined
137+
138+
return { providerConfigUpdates: { externalId: responseBody.id, signingSecret } }
113139
} catch (error: unknown) {
114140
if (error instanceof WebhookDeploymentConfigurationError) throw error
115141
const err = error as Error

‎apps/sim/lib/webhooks/providers/fireflies.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ export const firefliesHandler: WebhookProviderHandler = {
5555
const clientReferenceId = ((isV2 ? b.client_reference_id : b.clientReferenceId) || '') as string
5656
const rawTimestamp = b.timestamp != null ? Number(b.timestamp) : null
5757
const timestamp = rawTimestamp !== null && Number.isFinite(rawTimestamp) ? rawTimestamp : null
58+
const rawReprocessedAt = isV2 && b.reprocessed_at != null ? Number(b.reprocessed_at) : null
59+
const reprocessedAt =
60+
rawReprocessedAt !== null && Number.isFinite(rawReprocessedAt) ? rawReprocessedAt : null
5861

5962
return {
6063
input: {
6164
meetingId,
6265
eventType,
6366
clientReferenceId,
6467
...(timestamp !== null ? { timestamp } : {}),
68+
...(reprocessedAt !== null ? { reprocessedAt } : {}),
6569
},
6670
}
6771
},

‎apps/sim/tools/grain/delete_hook.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { GrainDeleteHookParams, GrainDeleteHookResponse } from '@/tools/grain/types'
22
import type { ToolConfig } from '@/tools/types'
3+
import { safeUrlPathSegment } from '@/tools/url-path'
34

45
export const grainDeleteHookTool: ToolConfig<GrainDeleteHookParams, GrainDeleteHookResponse> = {
56
id: 'grain_delete_hook',
@@ -23,7 +24,8 @@ export const grainDeleteHookTool: ToolConfig<GrainDeleteHookParams, GrainDeleteH
2324
},
2425

2526
request: {
26-
url: (params) => `https://api.grain.com/_/public-api/hooks/${params.hookId}`,
27+
url: (params) =>
28+
`https://api.grain.com/_/public-api/hooks/${safeUrlPathSegment(params.hookId, 'hookId')}`,
2729
method: 'DELETE',
2830
headers: (params) => ({
2931
'Content-Type': 'application/json',

‎apps/sim/tools/grain/delete_hook_v2.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GrainDeleteHookV2Params, GrainDeleteHookV2Response } from '@/tools/grain/types'
22
import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
33
import type { ToolConfig } from '@/tools/types'
4+
import { safeUrlPathSegment } from '@/tools/url-path'
45

56
export const grainDeleteHookV2Tool: ToolConfig<GrainDeleteHookV2Params, GrainDeleteHookV2Response> =
67
{
@@ -26,7 +27,8 @@ export const grainDeleteHookV2Tool: ToolConfig<GrainDeleteHookV2Params, GrainDel
2627
},
2728

2829
request: {
29-
url: (params) => `https://api.grain.com/_/public-api/v2/hooks/${params.hookId.trim()}`,
30+
url: (params) =>
31+
`https://api.grain.com/_/public-api/v2/hooks/${safeUrlPathSegment(params.hookId, 'hookId')}`,
3032
method: 'DELETE',
3133
headers: (params) => ({
3234
'Content-Type': 'application/json',

‎apps/sim/tools/grain/get_recording.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GrainGetRecordingParams, GrainGetRecordingResponse } from '@/tools/grain/types'
22
import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
33
import type { ToolConfig } from '@/tools/types'
4+
import { safeUrlPathSegment } from '@/tools/url-path'
45

56
export const grainGetRecordingTool: ToolConfig<GrainGetRecordingParams, GrainGetRecordingResponse> =
67
{
@@ -63,7 +64,7 @@ export const grainGetRecordingTool: ToolConfig<GrainGetRecordingParams, GrainGet
6364

6465
request: {
6566
url: (params) =>
66-
`https://api.grain.com/_/public-api/v2/recordings/${params.recordingId.trim()}`,
67+
`https://api.grain.com/_/public-api/v2/recordings/${safeUrlPathSegment(params.recordingId, 'recordingId')}`,
6768
method: 'POST',
6869
headers: (params) => ({
6970
'Content-Type': 'application/json',

‎apps/sim/tools/grain/get_transcript.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GrainGetTranscriptParams, GrainGetTranscriptResponse } from '@/tools/grain/types'
22
import { GRAIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
33
import type { ToolConfig } from '@/tools/types'
4+
import { safeUrlPathSegment } from '@/tools/url-path'
45

56
export const grainGetTranscriptTool: ToolConfig<
67
GrainGetTranscriptParams,
@@ -29,7 +30,7 @@ export const grainGetTranscriptTool: ToolConfig<
2930

3031
request: {
3132
url: (params) =>
32-
`https://api.grain.com/_/public-api/v2/recordings/${params.recordingId.trim()}/transcript`,
33+
`https://api.grain.com/_/public-api/v2/recordings/${safeUrlPathSegment(params.recordingId, 'recordingId')}/transcript`,
3334
method: 'GET',
3435
headers: (params) => ({
3536
'Content-Type': 'application/json',

‎apps/sim/tools/obsidian/patch_active.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const patchActiveTool: ToolConfig<ObsidianPatchActiveParams, ObsidianPatc
7070
const headers: Record<string, string> = {
7171
Authorization: `Bearer ${params.apiKey}`,
7272
'Content-Type': 'text/markdown',
73+
'Markdown-Patch-Version': '1',
7374
Operation: params.operation,
7475
'Target-Type': params.targetType,
7576
Target: encodeURIComponent(params.target),

0 commit comments

Comments
 (0)