Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(call): refuse a boolean call link start time
Yudhi Armyndharis446df146a003
diff --git a/src/modules/call/dto/create-call-link.dto.spec.ts b/src/modules/call/dto/create-call-link.dto.spec.tsindex 61b1934e7..e955e5b93 100644--- a/src/modules/call/dto/create-call-link.dto.spec.ts+++ b/src/modules/call/dto/create-call-link.dto.spec.ts@@ -13,6 +13,18 @@ describe('CreateCallLinkDto', () => {await expect(through({ type: 'video', startTime })).rejects.toBeInstanceOf(BadRequestException);});+ // The global pipe converts by declared type, so a boolean would otherwise read as the number 1.+ it.each([true, false, '', ' ', 'soon'])('rejects startTime %p with a 400', async startTime => {+ await expect(through({ type: 'video', startTime })).rejects.toBeInstanceOf(BadRequestException);+ });++ it('accepts a start time sent as a numeric string', async () => {+ await expect(through({ type: 'video', startTime: '1800000000000' })).resolves.toEqual({+ type: 'video',+ startTime: 1_800_000_000_000,+ });+ });+it('accepts the largest valid Date', async () => {await expect(through({ type: 'video', startTime: 8_640_000_000_000_000 })).resolves.toEqual({type: 'video',diff --git a/src/modules/call/dto/create-call-link.dto.ts b/src/modules/call/dto/create-call-link.dto.tsindex 726bb89e1..2448fb381 100644--- a/src/modules/call/dto/create-call-link.dto.ts+++ b/src/modules/call/dto/create-call-link.dto.ts@@ -1,6 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsIn, IsInt, IsString, Max, Min } from 'class-validator';-import { ToStrictString } from '../../../common/utils/strict-boolean';+import { ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';/** The largest epoch-ms value a JS Date can hold; anything above it is an Invalid Date. */const MAX_DATE_MS = 8_640_000_000_000_000;@@ -26,6 +26,8 @@ export class CreateCallLinkDto {minimum: 1,maximum: MAX_DATE_MS,})+ // A JSON `true` would otherwise convert to 1 (a start time in 1970) instead of failing @IsInt().+ @ToStrictNumber()@IsInt()@Min(1)@Max(MAX_DATE_MS)