Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(webhook): stop copying delivery headers into queued jobs

Yudhi Armyndharis1a10bae3b76e
diff --git a/src/modules/queue/processors/webhook.processor.spec.ts b/src/modules/queue/processors/webhook.processor.spec.ts
index 8d8a0eede..277845803 100644
--- a/src/modules/queue/processors/webhook.processor.spec.ts
+++ b/src/modules/queue/processors/webhook.processor.spec.ts
@@ -46,7 +46,6 @@ describe('WebhookProcessor', () => {
deliveryId: 'd',
data: {},
},
- headers: { 'Content-Type': 'application/json' },
attempt: 1,
maxRetries: 3,
...overrides,
@@ -262,13 +261,15 @@ describe('WebhookProcessor', () => {
secret: 'rotated',
});
mockFetch.mockResolvedValue({ ok: true, status: 200 });
+ // Jobs no longer carry headers, but one enqueued by an earlier release still holds a snapshot
+ // in Redis; it must be ignored in favour of the current row.
const job = makeJob({
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer old',
'X-OpenWA-Signature': 'sha256=old',
},
- });
+ } as Partial<WebhookJobData>);
const result = await processor.process(job);
diff --git a/src/modules/webhook/webhook-delivery.service.spec.ts b/src/modules/webhook/webhook-delivery.service.spec.ts
index 7476fca06..1f1c6bf2a 100644
--- a/src/modules/webhook/webhook-delivery.service.spec.ts
+++ b/src/modules/webhook/webhook-delivery.service.spec.ts
@@ -1447,8 +1447,10 @@ describe('WebhookDeliveryService', () => {
];
// BullMQ's dedupe boundary and the receiver's must key off the SAME identifier, or a job
// that BullMQ accepts twice still looks like one delivery to the receiver (and vice versa).
- expect(opts.jobId).toBe(jobData.headers['X-OpenWA-Delivery-Id']);
expect(opts.jobId).toBe(jobData.payload.deliveryId);
+ // Custom headers may carry receiver credentials and the processor rebuilds every header from
+ // the current row, so the job must not copy them into Redis.
+ expect(jobData).not.toHaveProperty('headers');
});
it('gives sibling webhooks distinct job ids, so one event fanning out is not collapsed into one job', async () => {
diff --git a/src/modules/webhook/webhook-delivery.service.ts b/src/modules/webhook/webhook-delivery.service.ts
index f93ea4620..1f762e3e1 100644
--- a/src/modules/webhook/webhook-delivery.service.ts
+++ b/src/modules/webhook/webhook-delivery.service.ts
@@ -42,7 +42,6 @@ export interface WebhookJobData {
url: string;
event: string;
payload: WebhookPayload;
- headers: Record<string, string>;
attempt: number;
maxRetries: number;
}
@@ -473,15 +472,13 @@ export class WebhookDeliveryService implements OnModuleInit, OnModuleDestroy {
): Promise<WebhookDeliveryOutcome> {
const { sessionId, event } = ctx;
try {
- // The job's headers are the enqueue-time snapshot. The processor rebuilds them (and the
- // signature) from the current webhook row on every attempt, so a secret or header rotated
- // while the job waits is honoured.
+ // No headers are stored: the processor builds them and the signature from the current row on
+ // every attempt, so custom headers (which may carry receiver credentials) never reach Redis.
const jobData: WebhookJobData = {
webhookId: webhook.id,
url: webhook.url,
event,
payload: finalPayload,
- headers,
attempt: 1,
maxRetries: webhook.retryCount,
};