Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(security): enforce the webhook secret floor on update

Yudhi Armyndharis1b61acc176f1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 79a5e7ec1..d7333222a 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
+
+- `PUT /sessions/{sessionId}/webhooks/{id}` now enforces the same 16-character webhook-secret floor as create; an empty string still clears signing.
+
## [0.20.0] - 2026-08-16
### Fixed
diff --git a/src/modules/webhook/dto/webhook-secret-entropy.spec.ts b/src/modules/webhook/dto/webhook-secret-entropy.spec.ts
index f977fe4d5..2ede02b32 100644
--- a/src/modules/webhook/dto/webhook-secret-entropy.spec.ts
+++ b/src/modules/webhook/dto/webhook-secret-entropy.spec.ts
@@ -1,5 +1,5 @@
import { validate } from 'class-validator';
-import { CreateWebhookDto } from './webhook.dto';
+import { CreateWebhookDto, UpdateWebhookDto } from './webhook.dto';
/**
* The HMAC secret signs every delivery this webhook fires. A short secret is recoverable
@@ -35,3 +35,36 @@ describe('CreateWebhookDto secret entropy', () => {
}
});
});
+
+describe('UpdateWebhookDto secret entropy', () => {
+ const dtoWithSecret = (secret: unknown) => {
+ const dto = new UpdateWebhookDto();
+ dto.secret = secret as string | undefined;
+ return dto;
+ };
+
+ it('rejects rotating to a secret shorter than 16 characters', async () => {
+ const errors = await validate(dtoWithSecret('short'));
+ expect(errors.some(e => e.property === 'secret')).toBe(true);
+ });
+
+ it('accepts rotating to a 16+ character secret', async () => {
+ const errors = await validate(dtoWithSecret('a-fully-entropic-secret'));
+ expect(errors.some(e => e.property === 'secret')).toBe(false);
+ });
+
+ it('still accepts an empty string, which this route treats as clearing the secret', async () => {
+ const errors = await validate(dtoWithSecret(''));
+ expect(errors.some(e => e.property === 'secret')).toBe(false);
+ });
+
+ it('still allows leaving the secret out of the patch entirely', async () => {
+ const errors = await validate(new UpdateWebhookDto());
+ expect(errors.some(e => e.property === 'secret')).toBe(false);
+ });
+
+ it('still rejects a non-string value', async () => {
+ const errors = await validate(dtoWithSecret(42));
+ expect(errors.some(e => e.property === 'secret')).toBe(true);
+ });
+});
diff --git a/src/modules/webhook/dto/webhook.dto.ts b/src/modules/webhook/dto/webhook.dto.ts
index ec8bf7fbf..da34fed7b 100644
--- a/src/modules/webhook/dto/webhook.dto.ts
+++ b/src/modules/webhook/dto/webhook.dto.ts
@@ -12,6 +12,7 @@ import {
MaxLength,
Min,
MinLength,
+ ValidateIf,
} from 'class-validator';
import { Expose, plainToInstance } from 'class-transformer';
import { Webhook } from '../entities/webhook.entity';
@@ -192,6 +193,11 @@ export class UpdateWebhookDto {
@ApiPropertyOptional({ description: 'Secret key for HMAC signature' })
@IsOptional()
@IsString()
+ // Same floor as create: a short secret is brute-forcible from one observed signature. The
+ // floor is skipped only for the empty string, which this route treats as "clear the secret"
+ // (the service stores null for it); a non-string value is still rejected by @IsString.
+ @ValidateIf((o: UpdateWebhookDto) => o.secret !== '')
+ @MinLength(16)
@MaxLength(255)
secret?: string;