Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(integration): redact the shared-secret ingress credential header
Yudhi Armyndharis8eaf88c3fe84
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3ce9b6e97..ac7b71079 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Security++- An integration ingress route verified with `shared-secret` no longer stores the instance secret from its declared header; the value is redacted in the persisted event, the queued job, the dead-letter row and the `ingress:error` hook payload.+### Added- `GET /api/sessions` accepts a `name` query parameter that returns only the session with that exact name, also on the MCP `SessionFindAll` tool and the JavaScript, Python, Go, Java and PHP SDKs ([#1594](https://github.com/rmyndharis/OpenWA/issues/1594)). Thanks @rivenash.diff --git a/src/modules/integration/ingress.service.spec.ts b/src/modules/integration/ingress.service.spec.tsindex d7e7a4e3e..b7e6158e4 100644--- a/src/modules/integration/ingress.service.spec.ts+++ b/src/modules/integration/ingress.service.spec.ts@@ -67,6 +67,36 @@ describe('redactSensitiveHeaders (persisted ingress payloads)', () => {expect(recorded.payload.headers.authorization).toBe('[redacted]');expect(recorded.payload.headers['x-delivery']).toBe('d1');});++ it("redacts a shared-secret route's declared credential header in the persisted and enqueued payload", async () => {+ const d = deps({+ manifestRoute: jest.fn().mockReturnValue({+ route: 'chatwoot',+ mode: 'async',+ verify: 'core',+ maxBodyBytes: 1024,+ signature: { scheme: 'shared-secret', header: 'X-Provider-Token' },+ dedupHeader: 'x-delivery',+ }),+ });+ const res = await new IngressService(d).handle({+ pluginId: 'chatwoot',+ instanceId: 'acct1',+ route: 'chatwoot',+ method: 'POST',+ headers: { 'x-delivery': 'd1', 'x-provider-token': 's' },+ query: {},+ rawBody: '{}',+ });+ expect(res.status).toBe(202);+ const recorded = (+ d.events.recordOrSkip.mock.calls as unknown as [[{ payload: { headers: Record<string, string> } }]]+ )[0][0];+ expect(recorded.payload.headers['x-provider-token']).toBe('[redacted]');+ expect(recorded.payload.headers['x-delivery']).toBe('d1');+ const job = (d.enqueue.mock.calls as unknown as [[{ payload: { headers: Record<string, string> } }]])[0][0];+ expect(job.payload.headers['x-provider-token']).toBe('[redacted]');+ });});describe('IngressService.handle', () => {diff --git a/src/modules/integration/ingress.service.ts b/src/modules/integration/ingress.service.tsindex 8a0fd2bff..a048f3257 100644--- a/src/modules/integration/ingress.service.ts+++ b/src/modules/integration/ingress.service.ts@@ -165,8 +165,12 @@ export class IngressService {const deliveryId = req.headers[dedupHeader] ?? deriveDeliveryId(req);// 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.const payload = {- headers: redactSensitiveHeaders(req.headers),+ headers: redactSensitiveHeaders(+ req.headers,+ route.signature.scheme === 'shared-secret' ? route.signature.header : undefined,+ ),query: req.query,body: req.rawBody,rawBody: req.rawBody,@@ -283,10 +287,15 @@ const SENSITIVE_INGRESS_HEADERS = new Set(['x-webhook-signature',]);-export function redactSensitiveHeaders(headers: Record<string, string>): Record<string, string> {+export function redactSensitiveHeaders(+ headers: Record<string, string>,+ credentialHeader?: string,+): Record<string, string> {+ const extra = credentialHeader?.toLowerCase();const out: Record<string, string> = {};for (const [name, value] of Object.entries(headers)) {- out[name] = SENSITIVE_INGRESS_HEADERS.has(name.toLowerCase()) ? '[redacted]' : value;+ const lower = name.toLowerCase();+ out[name] = SENSITIVE_INGRESS_HEADERS.has(lower) || lower === extra ? '[redacted]' : value;}return out;}