Skip to content

Commit 69bcb97

Browse files
committed
fix(webhooks): guard against a non-string workspaceId when resolving env vars
workflow.workspaceId as string | undefined was an unchecked cast on a Record<string, unknown> — if a caller ever passed a workflow-like object where workspaceId isn't actually a string, workspace-scoped {{VAR}} references would silently stay unresolved and the provider would receive the literal template as the credential, reproducing the exact class of bug this change exists to fix. Replaced with a runtime typeof check that falls back to undefined (personal-env-only resolution) instead of forwarding an unvalidated value.
1 parent f58bc35 commit 69bcb97

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

apps/sim/lib/webhooks/provider-subscriptions.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ describe('createExternalWebhookSubscription', () => {
7474
expect(result.updatedProviderConfig.externalId).toBe('ext-1')
7575
})
7676

77+
it('falls back to personal-only env resolution when workspaceId is not a string', async () => {
78+
const createSubscription = vi.fn().mockResolvedValue({
79+
providerConfigUpdates: { externalId: 'ext-1' },
80+
})
81+
mockGetProviderHandler.mockReturnValue({ createSubscription })
82+
83+
const webhookData = {
84+
provider: 'ashby',
85+
providerConfig: { apiKey: '{{ASHBY_API_KEY}}', triggerId: 'ashby_application_submit' },
86+
}
87+
const workflow = { id: 'wf-1', workspaceId: null }
88+
89+
await createExternalWebhookSubscription(
90+
{} as NextRequest,
91+
webhookData,
92+
workflow,
93+
'user-1',
94+
'req-1'
95+
)
96+
97+
expect(mockGetEffectiveDecryptedEnv).toHaveBeenCalledWith('user-1', undefined)
98+
})
99+
77100
it('skips resolution and provider call entirely when the provider has no createSubscription', async () => {
78101
mockGetProviderHandler.mockReturnValue({})
79102

apps/sim/lib/webhooks/provider-subscriptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,12 @@ export async function createExternalWebhookSubscription(
115115
return { updatedProviderConfig: providerConfig, externalSubscriptionCreated: false }
116116
}
117117

118+
const workspaceId = typeof workflow.workspaceId === 'string' ? workflow.workspaceId : undefined
119+
118120
const resolvedProviderConfig = await resolveWebhookProviderConfig(
119121
providerConfig,
120122
userId,
121-
workflow.workspaceId as string | undefined
123+
workspaceId
122124
)
123125

124126
const result = await handler.createSubscription({

0 commit comments

Comments
 (0)