Skip to content

Commit f27105e

Browse files
committed
fix(fathom): fail closed without a signing secret and nest trigger object outputs
1 parent 63e2afd commit f27105e

3 files changed

Lines changed: 87 additions & 10 deletions

File tree

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

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import crypto from 'node:crypto'
22
import { NextRequest } from 'next/server'
3-
import { describe, expect, it } from 'vitest'
3+
import { beforeEach, describe, expect, it, vi } from 'vitest'
44
import { fathomHandler } from '@/lib/webhooks/providers/fathom'
55

66
const SECRET_BYTES = Buffer.from('fathom-test-secret-key-padding!!!!!!')
@@ -68,3 +68,50 @@ describe('Fathom webhook provider verifyAuth', () => {
6868
expect(res ?? null).toBeNull()
6969
})
7070
})
71+
72+
describe('Fathom webhook provider createSubscription', () => {
73+
const fetchMock = vi.fn()
74+
75+
beforeEach(() => {
76+
fetchMock.mockReset()
77+
vi.stubGlobal('fetch', fetchMock)
78+
})
79+
80+
it('stores the signing secret Fathom returns', async () => {
81+
fetchMock.mockResolvedValueOnce({
82+
ok: true,
83+
status: 201,
84+
json: async () => ({ id: 'ikEoQ4bVoq4JYUmc', secret: SIGNING_SECRET }),
85+
})
86+
87+
const result = await fathomHandler.createSubscription?.({
88+
webhook: { id: 'wh_1', path: 'p1', providerConfig: { apiKey: 'fathom_key' } },
89+
requestId: 'fathom-sub1',
90+
} as never)
91+
92+
expect(result?.providerConfigUpdates).toEqual({
93+
externalId: 'ikEoQ4bVoq4JYUmc',
94+
signingSecret: SIGNING_SECRET,
95+
})
96+
})
97+
98+
it('deletes the webhook and fails when the response omits the signing secret', async () => {
99+
fetchMock.mockResolvedValueOnce({
100+
ok: true,
101+
status: 201,
102+
json: async () => ({ id: 'ikEoQ4bVoq4JYUmc' }),
103+
})
104+
fetchMock.mockResolvedValueOnce({ ok: true, status: 204 })
105+
106+
await expect(
107+
fathomHandler.createSubscription?.({
108+
webhook: { id: 'wh_2', path: 'p2', providerConfig: { apiKey: 'fathom_key' } },
109+
requestId: 'fathom-sub2',
110+
} as never)
111+
).rejects.toThrow(/signing secret/)
112+
113+
const [url, init] = fetchMock.mock.calls[1]
114+
expect(init.method).toBe('DELETE')
115+
expect(url).toBe('https://api.fathom.ai/external/v1/webhooks/ikEoQ4bVoq4JYUmc')
116+
})
117+
})

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@ import { verifyStandardWebhookRequest } from '@/lib/webhooks/providers/utils'
1515

1616
const logger = createLogger('WebhookProvider:Fathom')
1717

18+
/** Best-effort removal of a webhook Sim registered but cannot keep, so it does not keep firing. */
19+
async function deleteOrphanedFathomWebhook(
20+
apiKey: string,
21+
fathomWebhookId: string,
22+
requestId: string
23+
): Promise<void> {
24+
if (!validateAlphanumericId(fathomWebhookId, 'Fathom webhook ID', 100).isValid) return
25+
try {
26+
await outboundFetch(`https://api.fathom.ai/external/v1/webhooks/${fathomWebhookId}`, {
27+
method: 'DELETE',
28+
headers: { 'X-Api-Key': apiKey },
29+
})
30+
} catch (error) {
31+
logger.warn('Failed to remove orphaned Fathom webhook; it may still be active', error, {
32+
requestId,
33+
})
34+
}
35+
}
36+
1837
export const fathomHandler: WebhookProviderHandler = {
1938
/**
2039
* Fathom signs deliveries with the Standard Webhooks scheme using the secret
@@ -131,9 +150,16 @@ export const fathomHandler: WebhookProviderHandler = {
131150
})
132151

133152
const signingSecret =
134-
typeof responseBody.secret === 'string' && responseBody.secret.trim()
135-
? responseBody.secret
136-
: undefined
153+
typeof responseBody.secret === 'string' ? responseBody.secret.trim() : ''
154+
if (!signingSecret) {
155+
logger.error(`Fathom webhook creation returned no signing secret for ${webhook.id}.`, {
156+
requestId,
157+
})
158+
await deleteOrphanedFathomWebhook(apiKey, String(responseBody.id), requestId)
159+
throw new Error(
160+
'Fathom created the webhook but did not return a signing secret, so deliveries could not be verified. Please try again.'
161+
)
162+
}
137163

138164
return { providerConfigUpdates: { externalId: responseBody.id, signingSecret } }
139165
} catch (error: unknown) {

‎apps/sim/triggers/fathom/utils.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ export function buildMeetingOutputs(): Record<string, TriggerOutput> {
9797
recorded_by: {
9898
type: 'object',
9999
description: 'Recorder details',
100-
name: { type: 'string', description: 'Name of the recorder' },
101-
email: { type: 'string', description: 'Email of the recorder' },
102-
email_domain: { type: 'string', description: 'Email domain of the recorder' },
103-
team: { type: 'string', description: 'Recorder team name, or null' },
100+
properties: {
101+
name: { type: 'string', description: 'Name of the recorder' },
102+
email: { type: 'string', description: 'Email of the recorder' },
103+
email_domain: { type: 'string', description: 'Email domain of the recorder' },
104+
team: { type: 'string', description: 'Recorder team name, or null' },
105+
},
104106
},
105107
calendar_invitees: {
106108
type: 'array',
@@ -109,8 +111,10 @@ export function buildMeetingOutputs(): Record<string, TriggerOutput> {
109111
default_summary: {
110112
type: 'object',
111113
description: 'Meeting summary',
112-
template_name: { type: 'string', description: 'Summary template name' },
113-
markdown_formatted: { type: 'string', description: 'Markdown-formatted summary' },
114+
properties: {
115+
template_name: { type: 'string', description: 'Summary template name' },
116+
markdown_formatted: { type: 'string', description: 'Markdown-formatted summary' },
117+
},
114118
},
115119
transcript: {
116120
type: 'array',

0 commit comments

Comments
 (0)