Skip to content

Commit d921909

Browse files
committed
fix(slack): guard against NaN timestamp and align null/empty-string convention
1 parent ed326c8 commit d921909

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

apps/sim/lib/webhooks/providers/slack.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,12 @@ export const slackHandler: WebhookProviderHandler = {
246246
}
247247

248248
const now = Math.floor(Date.now() / 1000)
249-
const skew = Math.abs(now - Number(timestamp))
249+
const parsedTimestamp = Number(timestamp)
250+
if (Number.isNaN(parsedTimestamp)) {
251+
logger.warn(`[${requestId}] Slack webhook timestamp is not a valid number`, { timestamp })
252+
return new NextResponse('Unauthorized - Invalid timestamp', { status: 401 })
253+
}
254+
const skew = Math.abs(now - parsedTimestamp)
250255
if (skew > SLACK_TIMESTAMP_MAX_SKEW) {
251256
logger.warn(`[${requestId}] Slack webhook timestamp too old`, {
252257
timestamp,
@@ -336,13 +341,13 @@ export const slackHandler: WebhookProviderHandler = {
336341
input: {
337342
event: {
338343
event_type: eventType,
339-
subtype: (rawEvent?.subtype as string) || null,
344+
subtype: (rawEvent?.subtype as string) ?? '',
340345
channel,
341346
channel_name: '',
342-
channel_type: (rawEvent?.channel_type as string) || null,
347+
channel_type: (rawEvent?.channel_type as string) ?? '',
343348
user: (rawEvent?.user as string) || '',
344349
user_name: '',
345-
bot_id: (rawEvent?.bot_id as string) || null,
350+
bot_id: (rawEvent?.bot_id as string) ?? '',
346351
text,
347352
timestamp: messageTs,
348353
thread_ts: (rawEvent?.thread_ts as string) || '',

0 commit comments

Comments
 (0)