Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(webhook): treat a non-array events column as undeliverable

Yudhi Armyndharisea1ec3fed13f
diff --git a/src/modules/webhook/utils/deliver-once.spec.ts b/src/modules/webhook/utils/deliver-once.spec.ts
index 32efa5a44..a3d253383 100644
--- a/src/modules/webhook/utils/deliver-once.spec.ts
+++ b/src/modules/webhook/utils/deliver-once.spec.ts
@@ -116,6 +116,14 @@ describe('isDeliverableWebhook', () => {
expect(isDeliverableWebhook({ ...row, active: false }, 'message.received')).toBe(false);
expect(isDeliverableWebhook(row, 'message.ack')).toBe(false);
});
+
+ it('refuses a row whose events column is not an array instead of throwing', () => {
+ for (const events of [null, '*', { 0: 'message.received' }]) {
+ expect(isDeliverableWebhook({ active: true, events: events as unknown as string[] }, 'message.received')).toBe(
+ false,
+ );
+ }
+ });
});
describe('generateSignature', () => {
diff --git a/src/modules/webhook/utils/deliver-once.ts b/src/modules/webhook/utils/deliver-once.ts
index 23ffdfe38..ebf796c6a 100644
--- a/src/modules/webhook/utils/deliver-once.ts
+++ b/src/modules/webhook/utils/deliver-once.ts
@@ -28,15 +28,16 @@ export function sanitizeCustomHeaders(custom: Record<string, string> | null | un
/**
* Whether a webhook row as read now may still receive `event`: it exists, is active and subscribes to
- * the event or to '*'. Its filters are not re-applied here, since they need the event data. Every
- * path that delivers after the dispatch moment (a queued job, a direct retry, an outbox replay) runs
- * this against a fresh row, so a removed, disabled or unsubscribed webhook stops receiving the event.
+ * the event or to '*' (an events column that is not an array subscribes to nothing). Its filters are
+ * not re-applied here, since they need the event data. Every path that delivers after the dispatch
+ * moment (a queued job, a direct retry, an outbox replay) runs this against a fresh row, so a removed,
+ * disabled or unsubscribed webhook stops receiving the event.
*/
export function isDeliverableWebhook<T extends { active: boolean; events: string[] }>(
row: T | null | undefined,
event: string,
): row is T {
- return !!row && row.active && (row.events.includes(event) || row.events.includes('*'));
+ return !!row && row.active && Array.isArray(row.events) && (row.events.includes(event) || row.events.includes('*'));
}
/** HMAC-SHA256 over the exact pre-serialized body, prefixed for receiver-side verification. */