Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(webhook): publish no secret example on the update route
Yudhi Armyndharisa53b9ee16dd1
diff --git a/openapi.json b/openapi.jsonindex 0bd49771c..ab24c614b 100644--- a/openapi.json+++ b/openapi.json@@ -11010,8 +11010,7 @@"secret": {"type": "string","description": "Secret key for HMAC signature. At least 16 characters, or an empty string to clear it. Never returned by any webhook route.",- "maxLength": 255,- "example": "your-webhook-signing-secret"+ "maxLength": 255},"headers": {"type": "object",diff --git a/src/config/openapi-contract.spec.ts b/src/config/openapi-contract.spec.tsindex e8eb5e204..d0bd65d5b 100644--- a/src/config/openapi-contract.spec.ts+++ b/src/config/openapi-contract.spec.ts@@ -256,7 +256,9 @@ describe('every JSON request body publishes an object schema', () => {* ([#1491](https://github.com/rmyndharis/OpenWA/issues/1491)).** Only length is checked here. It is the constraint a hand-written example actually drifts past, and- * it needs no validator: the bound and the example sit in the same schema object.+ * it needs no validator: the bound and the example sit in the same schema object. The sweep covers+ * the top-level string properties of each component schema, which is where a hand-written+ * `@ApiProperty` example lives; nested and composed schemas are out of its reach.*/describe('every published string example fits its own schema', () => {type Example = { where: string; example: string; min?: number; max?: number };diff --git a/src/modules/webhook/dto/webhook-secret-entropy.spec.ts b/src/modules/webhook/dto/webhook-secret-entropy.spec.tsindex b87029f05..6ddeb5b66 100644--- a/src/modules/webhook/dto/webhook-secret-entropy.spec.ts+++ b/src/modules/webhook/dto/webhook-secret-entropy.spec.ts@@ -82,22 +82,25 @@ describe('the documented secret example', () => {const exampleOf = (target: object, property: string): unknown =>(Reflect.getMetadata('swagger/apiModelProperties', target, property) as { example?: unknown } | undefined)?.example;- it('is published on both routes', () => {+ it('is published on the create route', () => {expect(typeof exampleOf(CreateWebhookDto.prototype, 'secret')).toBe('string');- expect(typeof exampleOf(UpdateWebhookDto.prototype, 'secret')).toBe('string');});+ // Scoped to `secret` like the suites above: a required field added to this DTO later would fail a+ // whole-object assertion here for a reason that has nothing to do with the example under test.it('passes the validation the create route applies to it', async () => {const dto = new CreateWebhookDto();dto.url = 'https://receiver.example.com/hook';dto.events = ['message.received'];dto.secret = exampleOf(CreateWebhookDto.prototype, 'secret') as string;- expect(await validate(dto)).toEqual([]);+ const errors = await validate(dto);+ expect(errors.filter(e => e.property === 'secret')).toEqual([]);});- it('passes the validation the update route applies to it', async () => {- const dto = new UpdateWebhookDto();- dto.secret = exampleOf(UpdateWebhookDto.prototype, 'secret') as string;- expect(await validate(dto)).toEqual([]);+ // The update route publishes no example on purpose (see the DTO), so Swagger renders the generic+ // `"string"` there. That is a `400`, which is the safe way to be wrong on a route that patches a+ // key already in use.+ it('is deliberately absent from the update route', () => {+ expect(exampleOf(UpdateWebhookDto.prototype, 'secret')).toBeUndefined();});});diff --git a/src/modules/webhook/dto/webhook.dto.ts b/src/modules/webhook/dto/webhook.dto.tsindex c30f1ae77..651bcdeb1 100644--- a/src/modules/webhook/dto/webhook.dto.ts+++ b/src/modules/webhook/dto/webhook.dto.ts@@ -208,7 +208,11 @@ export class UpdateWebhookDto {'Secret key for HMAC signature. At least 16 characters, or an empty string to clear it. ' +'Never returned by any webhook route.',maxLength: 255,- example: 'your-webhook-signing-secret',+ // Deliberately no `example`, unlike create. This route patches a webhook that is already+ // signing deliveries, and a prefilled secret submitted whole would replace a working key with+ // a published one: every later delivery still verifies, so nothing looks broken while the+ // signature is forgeable by anyone reading these docs. The floor belongs in the description+ // here, where it costs a `400` to ignore rather than a silent downgrade.})@IsOptional()@IsString()