Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
docs(webhook): bound the write-only claim to the webhook routes
Yudhi Armyndharisadcaab73e8b2
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1ad376149..4ae955374 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- The chat-history response example advertised a `senderPhone` field that endpoint has never returned, and showed it on a plain `@c.us` sender that not even the inbound path would resolve; the example now matches what the route emits, and points at the contact-phone endpoint instead.- `WEBHOOK_CONTACT_DETAILS` was absent from `docs/`; the event catalog now names the twelve fields it adds to `contact` on `message.received`, notes that opting in costs no extra WhatsApp lookup, and records that only the whatsapp-web.js path reads the flag — which `.env.example` now says too.- The chat-history field list omitted `ephemeralDuration` and its `type` union omitted `poll`, both of which that route emits; `[Unreleased]` also carried two `### Fixed` headings after two branches added one each without conflicting.-- `docs/04-security-design.md` stated in two places that webhook secrets are never returned by any API response, contradicting `docs/06`, which documents `GET /api/infra/export-data` returning them in cleartext; both now name that route as the exception, the way the neighbouring proxy-credential row already scopes its claim to the session read DTOs.+- The webhook `secret` and `headers` were described as never returned by any API response in six places across `docs/04`, `docs/06`, `docs/07`, the response DTO and the webhook e2e suite, while `GET /api/infra/export-data` dumps the rows verbatim and returns both in cleartext — which `docs/06` also said, two sections further down. Every one of them now bounds the claim to the webhook routes and names the export route as the exception, the way the neighbouring proxy-credential row already scopes its claim to the session read DTOs.## [0.16.0] - 2026-08-11diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 538c1fecd..f1982b021 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -4245,7 +4245,7 @@ The service returns `void`; the controller returns a fixed success object. DELETWebhooks are configured per session and managed under `/api/sessions/:sessionId/webhooks` (handled by `WebhookController`). Two cross-session endpoints live on `WebhooksListController`: `GET /api/webhooks` (list, **OPERATOR**) and `GET /api/webhooks/delivery-failures` (dead-letter log, **ADMIN**). Every other route requires an API key with **OPERATOR** role or higher.-Two fields — `secret` and `headers` — are **write-only**: they are accepted on create/update but are **never** returned in any response (the response DTO has no `@Expose` for them, so `fromEntity` drops them). The `secret` is used to compute the `X-OpenWA-Signature: sha256=<hex>` HMAC-SHA256 header on deliveries.+Two fields — `secret` and `headers` — are **write-only**: they are accepted on create/update but are never returned by any webhook route (the response DTO has no `@Expose` for them, so `fromEntity` drops them). The one exception is `GET /api/infra/export-data`, which dumps the `webhooks` rows verbatim and so carries both in cleartext. The `secret` is used to compute the `X-OpenWA-Signature: sha256=<hex>` HMAC-SHA256 header on deliveries.The `events` array accepts these members plus the `*` wildcard: `message.received`, `message.sent`, `message.ack`, `message.failed`, `message.revoked`, `message.reaction`, `message.edited`, `session.status`, `session.qr`, `session.authenticated`, `session.disconnected`, `session.reconnect_loop`, `session.restriction`, `presence.update`, `call.accepted`, `call.rejected`, `call.missed`, `group.join`, `group.leave`, `group.update`, `group.join_request`, `call.received`, `status.received`. All of them are actively dispatched by at least one engine — none is a reserved placeholder. Four are **Baileys only**, because whatsapp-web.js produces no callback behind them: `presence.update` (its prerequisite `POST .../presence/subscribe` answers `501` there, so this one announces itself) and `call.accepted` / `call.rejected` / `call.missed` (whatsapp-web.js sees a call ring but never its outcome, so these three are accepted on subscribe and then simply never fire). See the per-event catalog below for engine scope.@@ -4408,8 +4408,8 @@ Create a webhook for the session.| ---------- | ---------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ || url | string | yes | `@IsUrl({ require_tld: false })` (allows hostnames without a dot, e.g. `http://localhost:3000`); also run through the SSRF guard, which can reject with `400`. Entity column max 2048 chars. | Webhook URL to receive events. || events | string[] | no | `@IsArray`, `@ArrayMinSize(1)`, `@IsIn([...WEBHOOK_EVENTS, '*'], { each: true })` | Event names to subscribe to (see allowed set above). Defaults to `["message.received"]` when omitted. |-| secret | string | no | `@IsString`, `@MaxLength(255)` | HMAC-SHA256 signing key. **Write-only** — never returned. Used for `X-OpenWA-Signature`. Defaults to `null`. |-| headers | Record<string,string> | no | `@IsHeaderMap()` — flat object (not array), ≤50 entries, names match `/^[A-Za-z0-9-]+$/`, values are strings ≤1024 chars with no C0 control/DEL (CR/LF injection guard). | Custom headers added to deliveries. **Write-only** — never returned. At delivery, `content-type` and `x-openwa-*` names are stripped. Defaults to `{}`. |+| secret | string | no | `@IsString`, `@MaxLength(255)` | HMAC-SHA256 signing key. **Write-only** — never returned by a webhook route (`GET /api/infra/export-data` does return it). Used for `X-OpenWA-Signature`. Defaults to `null`. |+| headers | Record<string,string> | no | `@IsHeaderMap()` — flat object (not array), ≤50 entries, names match `/^[A-Za-z0-9-]+$/`, values are strings ≤1024 chars with no C0 control/DEL (CR/LF injection guard). | Custom headers added to deliveries. **Write-only** — never returned by a webhook route (`GET /api/infra/export-data` does return it). At delivery, `content-type` and `x-openwa-*` names are stripped. Defaults to `{}`. || filters | WebhookFilters \| null | no | `@IsValidWebhookFilters()` — `{ conditions: [...] }`; each condition `{ field, operator('is'\|'isNot'\|'contains'\|'equals'), value(string\|string[]\|boolean), caseSensitive?:boolean }`; bounds: max 20 conditions, 100 values/condition, 1000-char text values. Message fields: `sender`, `recipient`, `body`, `type`, `isGroup`, `fromMe`, `hasMedia`, `mentions`. | Optional AND pre-filter; **all** conditions must match for the webhook to fire. Omit/null = fire on every subscribed event. Defaults to `null`. ⚠️ A condition whose field is DEFINED for the event family but absent from that event's payload cannot match, so it suppresses the event entirely (a field with no definition for the family is skipped instead, and does not suppress) — `message.ack`/`message.failed` carry `{ id, messageId, status, ack }` and `message.reaction` carries `{ messageId, chatId, reaction, senderId }`, none of which has a sender or body, so a `sender` filter silently drops all three. Scope the subscription with `events[]` rather than relying on a filter to be inert. Set `LOG_LEVEL=debug` to see each suppression and the payload fields that were available. || retryCount | number (int) | no | `@IsInt`, `@Min(0)`, `@Max(5)` | Delivery retry attempts on failure. Defaults to `3`. |diff --git a/docs/07-api-collection.md b/docs/07-api-collection.mdindex bf6471287..00f263179 100644--- a/docs/07-api-collection.md+++ b/docs/07-api-collection.md@@ -981,7 +981,7 @@ curl -X DELETE "$BASE/api/sessions/$SESSION_ID/status/false_status@broadcast_3A1### 07.10 Webhooks (management)-All routes require an API key with OPERATOR role or higher. `secret` and `headers` are write-only (never returned). The per-session routes live under `/api/sessions/:sessionId/webhooks`; the cross-session list is `/api/webhooks`.+All routes require an API key with OPERATOR role or higher. `secret` and `headers` are write-only (never returned by these routes; `GET /api/infra/export-data` does return them in cleartext). The per-session routes live under `/api/sessions/:sessionId/webhooks`; the cross-session list is `/api/webhooks`.#### GET /api/sessions/:sessionId/webhooksdiff --git a/src/modules/webhook/dto/webhook.dto.ts b/src/modules/webhook/dto/webhook.dto.tsindex f38e8fa36..a44977421 100644--- a/src/modules/webhook/dto/webhook.dto.ts+++ b/src/modules/webhook/dto/webhook.dto.ts@@ -190,7 +190,8 @@ export class UpdateWebhookDto {/*** Public response shape for a webhook. Deliberately omits `secret` (the HMAC* signing key) and `headers` (which may carry receiver credentials) — these are- * write-only and must never appear in any API response.+ * write-only and must never appear in a response built from this DTO. They are not secret from+ * every route: GET /api/infra/export-data dumps the webhooks rows verbatim, secret included.** `@Expose()` is required on every field: `fromEntity` maps with* `excludeExtraneousValues: true`, so only exposed fields are serialized and anydiff --git a/test/webhooks.e2e-spec.ts b/test/webhooks.e2e-spec.tsindex 236c98158..ecc850273 100644--- a/test/webhooks.e2e-spec.ts+++ b/test/webhooks.e2e-spec.ts@@ -142,7 +142,8 @@ describe('Webhooks (e2e)', () => {expect(dto.id).toBeDefined();expect(dto.sessionId).toBe(session);expect(dto.active).toBe(true);- // Write-only fields must never appear in any API response.+ // Write-only fields must never appear in a webhook-route response. (The infra export route+ // does return them — that is deliberate and covered by its own ADMIN + unscoped-key fence.)expect(dto.secret).toBeUndefined();expect(dto.headers).toBeUndefined();});