Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(ingress): treat a blank delivery-id header as no id at all
Yudhi Armyndharis8cc9afffc076
diff --git a/src/modules/integration/ingress.service.spec.ts b/src/modules/integration/ingress.service.spec.tsindex fec11df96..ac74b2787 100644--- a/src/modules/integration/ingress.service.spec.ts+++ b/src/modules/integration/ingress.service.spec.ts@@ -540,6 +540,21 @@ describe('dedupOn: body (a provider that rotates its delivery id on retry)', ()await new IngressService(d).handle({ ...req, headers: { 'x-delivery': 'd-1' } });expect((d.enqueue.mock.calls[0] as [unknown, string])[1]).toBe('d-1');});++ // A header that is present but blank is no id at all. Taking it as one gave every delivery the+ // same empty key, so the dedup row admitted the first and dropped the rest while still answering+ // each provider with the route's success ack.+ it('falls back to the body hash when the dedup header is present but blank', async () => {+ const first = deps();+ await new IngressService(first).handle({ ...req, headers: { 'x-delivery': '' }, rawBody: '{"n":1}' });+ const firstId = (first.enqueue.mock.calls[0] as [unknown, string])[1];+ expect(firstId).not.toBe('');++ const second = deps();+ await new IngressService(second).handle({ ...req, headers: { 'x-delivery': '' }, rawBody: '{"n":2}' });+ expect(second.enqueue).toHaveBeenCalledTimes(1);+ expect((second.enqueue.mock.calls[0] as [unknown, string])[1]).not.toBe(firstId);+ });});describe('extractConversationId', () => {diff --git a/src/modules/integration/ingress.service.ts b/src/modules/integration/ingress.service.tsindex 4ce1d8ce5..02555aa95 100644--- a/src/modules/integration/ingress.service.ts+++ b/src/modules/integration/ingress.service.ts@@ -166,8 +166,14 @@ export class IngressService {const dedupHeader = (route.dedupHeader ?? route.signature.dedupHeader ?? defaultDedupHeader).toLowerCase();// A route that declares dedupOn: 'body' keys retries on the raw body: its provider mints a fresh// delivery id per attempt, so trusting the header would let every retry through as new.- const deliveryId =- route.dedupOn === 'body' ? deriveDeliveryId(req) : (req.headers[dedupHeader] ?? deriveDeliveryId(req));+ //+ // A header that is present but blank is no id at all, and it used to be taken as one: every+ // delivery then shared the empty key, so the dedup row admitted the first and dropped the rest+ // while answering each provider with the route's success ack. Nothing was enqueued, nothing was+ // dead-lettered, and the deliveries were simply gone. Fall through to the body hash, which is+ // exactly the "provider supplied no id" case it already exists for.+ const headerId = req.headers[dedupHeader]?.trim();+ const deliveryId = route.dedupOn === 'body' || !headerId ? deriveDeliveryId(req) : headerId;// Provider request headers persist with the event (redrive/debugging); credentials must not.// Signature headers are re-derivable, auth material is not — redact before the first write.// A shared-secret route carries the instance secret itself in its declared header.