Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(api): refuse a non-string in a string field
Yudhi Armyndharisfc614a65f070
diff --git a/src/common/utils/dto-strict-coercion.spec.ts b/src/common/utils/dto-strict-coercion.spec.tsindex 67d6c32ab..2b34fa717 100644--- a/src/common/utils/dto-strict-coercion.spec.ts+++ b/src/common/utils/dto-strict-coercion.spec.ts@@ -10,31 +10,39 @@ import { join } from 'path';* The global ValidationPipe runs with `transformOptions.enableImplicitConversion: true`* (`src/config/app-validation.ts`). That is deliberate — it lets a client send `"5"` for a numeric* field, which form-encoded bodies and several HTTP clients do by default. But it also means- * class-transformer rewrites the value BEFORE any `@Is*` validator sees it, and two of its+ * class-transformer rewrites the value BEFORE any `@Is*` validator sees it, and three of its* conversions destroy information rather than preserving it:** Boolean — every non-empty string becomes `true`, so `"false"`, `"no"` and `"0"` all arrive as* `true` and `@IsBoolean()` can never reject them.* Number — `Number('')` and `Number(' ')` are `0`, so a blank field arrives as a real zero* and `@IsInt()`/`@IsNumber()` accept it.+ * String - a number, boolean or object becomes its string form (`5`, `true`, `[object Object]`), so+ * `@IsString()` accepts it and the route sends text the caller never wrote.*- * Both fail toward the more permissive value, which is how a `forEveryone=false` delete became a- * delete-for-everyone. `ToStrictBoolean`/`ToStrictNumber` (`./strict-boolean`) restore the- * rejection while keeping the useful half of the conversion.+ * The first two fail toward the more permissive value, which is how a `forEveryone=false` delete became+ * a delete-for-everyone. `ToStrictBoolean`/`ToStrictNumber`/`ToStrictString` (`./strict-boolean`)+ * restore the rejection while keeping the useful half of the conversion.** This spec asserts the BEHAVIOUR rather than the presence of a decorator, so any future mechanism* that produces the same guarantee also satisfies it. Every boolean and numeric property that* carries validation metadata is covered — including classes that are never exported, because- * discovery walks class-validator's own registry rather than module exports.+ * discovery walks class-validator's own registry rather than module exports. So is every string one.*/const PIPE_TRANSFORM_OPTS = { enableImplicitConversion: true };const PIPE_VALIDATOR_OPTS = { whitelist: true, forbidNonWhitelisted: true };-/** The value each type is probed with, and why it must be refused. */-const PROBES: Record<string, { value: string; reason: string }> = {- Boolean: { value: 'yes', reason: 'implicit conversion turns any non-empty string into true' },- Number: { value: '', reason: 'Number("") is 0, so a blank field becomes a real zero' },+/** The values each type is probed with, and why each must be refused. */+const PROBES: Record<string, { values: unknown[]; reason: string }> = {+ Boolean: { values: ['yes'], reason: 'implicit conversion turns any non-empty string into true' },+ Number: { values: [''], reason: 'Number("") is 0, so a blank field becomes a real zero' },+ // Three probes, because their string forms differ: "628123456789" and "true" pass a digit pattern or a+ // name rule that "[object Object]" fails, so one probe alone would let such a field skip the decorator.+ String: {+ values: [628123456789, true, { order: 42 }],+ reason: 'implicit conversion rewrites a number, boolean or object into its string form, which @IsString accepts',+ },};function dtoFiles(dir: string, out: string[] = []): string[] {@@ -92,16 +100,19 @@ describe('DTO input-coercion drift gate', () => {expect(names.length).toBeGreaterThanOrEqual(40);});- it('finds both a boolean and a numeric property to check', () => {+ it('finds a boolean, a numeric and a string property to check', () => {expect(targets.some(t => t.type === 'Boolean')).toBe(true);expect(targets.some(t => t.type === 'Number')).toBe(true);+ expect(targets.some(t => t.type === 'String')).toBe(true);expect(targets.length).toBeGreaterThanOrEqual(15);+ // Most request fields are text, so a scan that came up with none of them would report a clean result.+ expect(targets.filter(t => t.type === 'String').length).toBeGreaterThanOrEqual(100);});- it.each(targets.map(t => [`${t.cls.name}.${t.prop}`, t] as const))(- '%s refuses a value the pipe would otherwise coerce',- async (_label, target) => {- const { value, reason } = PROBES[target.type];+ it.each(targets.flatMap(t => PROBES[t.type].values.map(value => [`${t.cls.name}.${t.prop}`, value, t] as const)))(+ '%s refuses %j, which the pipe would otherwise coerce',+ async (_label, value, target) => {+ const { reason } = PROBES[target.type];const instance = plainToInstance(target.cls, { [target.prop]: value }, PIPE_TRANSFORM_OPTS);const errors = await validate(instance, PIPE_VALIDATOR_OPTS);diff --git a/src/common/utils/strict-boolean.spec.ts b/src/common/utils/strict-boolean.spec.tsindex 75e2c7ae9..37ca1886c 100644--- a/src/common/utils/strict-boolean.spec.ts+++ b/src/common/utils/strict-boolean.spec.ts@@ -2,8 +2,8 @@ import 'reflect-metadata';import { plainToInstance } from 'class-transformer';import { validate } from 'class-validator';import { IsBoolean, ValidateIf } from 'class-validator';-import { IsInt } from 'class-validator';-import { ToStrictBoolean, ToStrictNumber } from './strict-boolean';+import { IsInt, IsString } from 'class-validator';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from './strict-boolean';// Mirrors the real pipe: whitelist + forbidNonWhitelisted from src/main.ts, and the// enableImplicitConversion transform option from src/config/app-validation.ts. Leaving the@@ -121,3 +121,57 @@ describe('ToStrictNumber', () => {expect(errors).toHaveLength(0);});});++class StringSubject {+ @ToStrictString()+ @ValidateIf((o: StringSubject) => o.text !== undefined)+ @IsString()+ text?: string;+}++class UnguardedString {+ @ValidateIf((o: UnguardedString) => o.text !== undefined)+ @IsString()+ text?: string;+}++describe('ToStrictString', () => {+ it('keeps a string exactly as sent', async () => {+ for (const value of ['hello', '', ' padded ', '628123456789', 'true']) {+ const { instance, errors } = await run(StringSubject, { text: value });+ expect(instance.text).toBe(value);+ expect(errors).toHaveLength(0);+ }+ });++ it.each([[628123456789], [true], [false], [0], [{ order: 42 }], [['a']]])(+ 'rejects %j instead of reading it as text',+ async value => {+ const { instance, errors } = await run(StringSubject, { text: value });+ expect(instance.text).toEqual(value);+ expect(errors.map(e => e.property)).toEqual(['text']);+ },+ );++ it('leaves an absent property absent and a null one null', async () => {+ const absent = await run(StringSubject, {});+ expect(absent.instance.text).toBeUndefined();+ expect(absent.errors).toHaveLength(0);++ const nulled = await run(StringSubject, { text: null });+ expect(nulled.instance.text).toBeNull();+ });++ // The behaviour the decorator exists to prevent: the customer receiving the literal "[object Object]".+ it('documents the unguarded behaviour it replaces: a number, boolean or object becomes a string', async () => {+ for (const [value, expected] of [+ [628123456789, '628123456789'],+ [true, 'true'],+ [{ order: 42 }, '[object Object]'],+ ] as const) {+ const { instance, errors } = await run(UnguardedString, { text: value });+ expect(instance.text).toBe(expected);+ expect(errors).toHaveLength(0);+ }+ });+});diff --git a/src/common/utils/strict-boolean.ts b/src/common/utils/strict-boolean.tsindex e62b373ce..1b0b66790 100644--- a/src/common/utils/strict-boolean.ts+++ b/src/common/utils/strict-boolean.ts@@ -54,3 +54,22 @@ export function coerceStrictNumber({ obj, key }: Pick<TransformFnParams, 'obj' |/** Property decorator form of {@link coerceStrictNumber}. Pair it with `@IsInt()` / `@IsNumber()`. */export const ToStrictNumber = (): PropertyDecorator => Transform(coerceStrictNumber);++/**+ * The string counterpart, for the same reason and with the same `obj[key]` trick.+ *+ * Implicit conversion applies `String(value)` to a `string`-typed property, so a number, a boolean or+ * an object is rewritten into its string form (`5`, `true`, `[object Object]`) before `@IsString()` runs,+ * and the route accepts it. An integration whose expression yields an object then sent the customer+ * the literal text `[object Object]`. An array is the one value left alone, so the same field already+ * answered 400 for it.+ *+ * The caller's value is kept as it is, so `@IsString()` and the other string validators refuse anything+ * that is not already a string. A string is never altered, so a form-encoded body is unaffected.+ */+export function coerceStrictString({ obj, key }: Pick<TransformFnParams, 'obj' | 'key'>): unknown {+ return (obj as Record<string, unknown> | undefined)?.[key];+}++/** Property decorator form of {@link coerceStrictString}. Pair it with `@IsString()`. */+export const ToStrictString = (): PropertyDecorator => Transform(coerceStrictString);diff --git a/src/modules/auth/dto/api-key.dto.ts b/src/modules/auth/dto/api-key.dto.tsindex 394205f33..63fb3dd65 100644--- a/src/modules/auth/dto/api-key.dto.ts+++ b/src/modules/auth/dto/api-key.dto.ts@@ -10,6 +10,7 @@ import {Validate,} from 'class-validator';import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';+import { ToStrictString } from '../../../common/utils/strict-boolean';import { MaxCodePoints } from '../../../common/validation/max-code-points';import { ApiKeyRole } from '../entities/api-key.entity';import { IsIpOrCidrConstraint } from './is-ip-or-cidr.validator';@@ -31,6 +32,7 @@ export class CreateApiKeyDto {minLength: 3,maxLength: 100,})+ @ToStrictString()@IsString()@MinLength(3)@MaxCodePoints(100)@@ -169,6 +171,7 @@ export class ValidateApiKeyResponseDto {export class UpdateApiKeyDto {@ApiPropertyOptional({ minLength: 3, maxLength: 100 })@IsOptional()+ @ToStrictString()@IsString()@MinLength(3)@MaxCodePoints(100)diff --git a/src/modules/automation/dto/automation-rule.dto.ts b/src/modules/automation/dto/automation-rule.dto.tsindex 4d08a0a9d..dbba6060a 100644--- a/src/modules/automation/dto/automation-rule.dto.ts+++ b/src/modules/automation/dto/automation-rule.dto.ts@@ -1,7 +1,7 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { Expose, plainToInstance } from 'class-transformer';import { IsBoolean, IsInt, IsNotEmpty, IsOptional, IsString, Max, MaxLength, Min, ValidateIf } from 'class-validator';-import { ToStrictBoolean, ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';import { MaxCodePoints } from '../../../common/validation/max-code-points';import { NoNulCharacter } from '../../../common/validation/no-nul-character';import { MESSAGE_TEXT_MAX_LENGTH } from '../../message/dto/send-message.dto';@@ -27,6 +27,7 @@ const COOLDOWN_DESCRIPTION =export class CreateAutomationRuleDto {@ApiProperty({ description: 'Display name for the rule', example: 'Greet new enquiries', maxLength: 100 })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxCodePoints(100)@@ -38,6 +39,7 @@ export class CreateAutomationRuleDto {example: 'Thanks for reaching out — we reply within the hour.',maxLength: MESSAGE_TEXT_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)@@ -73,6 +75,7 @@ export class UpdateAutomationRuleDto {@ApiPropertyOptional({ description: 'Display name for the rule', maxLength: 100 })// Not @IsOptional on the NOT NULL columns: that also skips null, which then reaches save() as a 500.@ValidateIf((o: UpdateAutomationRuleDto) => o.name !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()@MaxCodePoints(100)@@ -84,6 +87,7 @@ export class UpdateAutomationRuleDto {maxLength: MESSAGE_TEXT_MAX_LENGTH,})@ValidateIf((o: UpdateAutomationRuleDto) => o.replyText !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)diff --git a/src/modules/call/dto/create-call-link.dto.ts b/src/modules/call/dto/create-call-link.dto.tsindex 22012908a..726bb89e1 100644--- a/src/modules/call/dto/create-call-link.dto.ts+++ b/src/modules/call/dto/create-call-link.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsIn, IsInt, IsString, Max, Min } from 'class-validator';+import { 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;@@ -10,6 +11,7 @@ export class CreateCallLinkDto {enum: ['audio', 'video'],example: 'video',})+ @ToStrictString()@IsString()@IsIn(['audio', 'video'])type!: 'audio' | 'video';diff --git a/src/modules/catalog/dto/send-product.dto.ts b/src/modules/catalog/dto/send-product.dto.tsindex 02720a131..a1e5db0a7 100644--- a/src/modules/catalog/dto/send-product.dto.ts+++ b/src/modules/catalog/dto/send-product.dto.ts@@ -3,6 +3,7 @@ import { Type } from 'class-transformer';import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { MESSAGE_TEXT_MAX_LENGTH } from '../../message/dto/send-message.dto';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';/** WhatsApp catalog product ids are numeric strings of about 16-20 digits; this leaves wide headroom. */export const PRODUCT_ID_MAX_LENGTH = 255;@@ -13,12 +14,14 @@ export class SendProductDto {description: 'Chat to send the product card to (@c.us or @g.us).',example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty({ description: 'Catalog product id to send.', example: 'product-42', maxLength: PRODUCT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(PRODUCT_ID_MAX_LENGTH)@@ -30,6 +33,7 @@ export class SendProductDto {maxLength: MESSAGE_TEXT_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)body?: string;diff --git a/src/modules/channel/dto/create-channel.dto.ts b/src/modules/channel/dto/create-channel.dto.tsindex 26adfea5b..00d8c11ab 100644--- a/src/modules/channel/dto/create-channel.dto.ts+++ b/src/modules/channel/dto/create-channel.dto.ts@@ -1,8 +1,10 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class CreateChannelDto {@ApiProperty({ description: 'Channel name', example: 'Product updates', maxLength: 100 })+ @ToStrictString()@IsString()@IsNotEmpty()// Bounds a runaway payload rather than mirroring a protocol limit; WhatsApp's own editor stops@@ -16,6 +18,7 @@ export class CreateChannelDto {maxLength: 2048,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(2048)description?: string;diff --git a/src/modules/channel/dto/demote-channel-admin.dto.ts b/src/modules/channel/dto/demote-channel-admin.dto.tsindex ee45d5173..f609563f0 100644--- a/src/modules/channel/dto/demote-channel-admin.dto.ts+++ b/src/modules/channel/dto/demote-channel-admin.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsNotEmpty, IsString } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class DemoteChannelAdminDto {@ApiProperty({@@ -9,6 +10,7 @@ export class DemoteChannelAdminDto {'individual is rejected with 400 rather than handed to WhatsApp.',example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()userId!: string;diff --git a/src/modules/channel/dto/subscribe-channel.dto.ts b/src/modules/channel/dto/subscribe-channel.dto.tsindex 2b3ec0eab..52cb25781 100644--- a/src/modules/channel/dto/subscribe-channel.dto.ts+++ b/src/modules/channel/dto/subscribe-channel.dto.ts@@ -1,9 +1,11 @@import { ApiProperty } from '@nestjs/swagger';import { IsString, IsNotEmpty } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';/** Validated body for subscribing to a channel (was an inline @Body literal). */export class SubscribeChannelDto {@ApiProperty({ description: 'Channel invite code' })+ @ToStrictString()@IsString()@IsNotEmpty()inviteCode!: string;diff --git a/src/modules/channel/dto/transfer-channel-ownership.dto.ts b/src/modules/channel/dto/transfer-channel-ownership.dto.tsindex 7be0aee48..d0552ce0b 100644--- a/src/modules/channel/dto/transfer-channel-ownership.dto.ts+++ b/src/modules/channel/dto/transfer-channel-ownership.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsNotEmpty, IsString } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class TransferChannelOwnershipDto {@ApiProperty({@@ -10,6 +11,7 @@ export class TransferChannelOwnershipDto {'transfer lands, this session can no longer take the channel back.',example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()newOwnerId!: string;diff --git a/src/modules/contact/dto/upsert-contact.dto.ts b/src/modules/contact/dto/upsert-contact.dto.tsindex 180d34f0d..1b905c468 100644--- a/src/modules/contact/dto/upsert-contact.dto.ts+++ b/src/modules/contact/dto/upsert-contact.dto.ts@@ -1,11 +1,13 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';/** Cap on each addressbook name part. Independent of CONTACT_NAME_MAX_LENGTH (255) on the send-contact DTO. */export const ADDRESSBOOK_NAME_MAX_LENGTH = 100;export class UpsertContactDto {@ApiProperty({ description: "The contact's first name.", minLength: 1, maxLength: ADDRESSBOOK_NAME_MAX_LENGTH })+ @ToStrictString()@IsString()@MinLength(1)@MaxLength(ADDRESSBOOK_NAME_MAX_LENGTH)@@ -16,6 +18,7 @@ export class UpsertContactDto {maxLength: ADDRESSBOOK_NAME_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(ADDRESSBOOK_NAME_MAX_LENGTH)lastName?: string;diff --git a/src/modules/group/dto/group.dto.ts b/src/modules/group/dto/group.dto.tsindex 813fa3e08..e2f263dc4 100644--- a/src/modules/group/dto/group.dto.ts+++ b/src/modules/group/dto/group.dto.ts@@ -14,7 +14,7 @@ import {Matches,ValidateIf,} from 'class-validator';-import { ToStrictBoolean, ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';import type { GroupMemberAddMode } from '../../../engine/interfaces/whatsapp-engine.interface';import { IsMediaUrl } from '../../../common/media/media-url';import { stripBase64DataUri } from '../../message/media-cap.util';@@ -35,6 +35,7 @@ export const GROUP_PARTICIPANTS_MAX = 256;export class CreateGroupDto {@ApiProperty({ description: 'Group subject/name', maxLength: GROUP_NAME_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(GROUP_NAME_MAX_LENGTH)@@ -87,6 +88,7 @@ export class MembershipRequestActionDto {export class GroupSubjectDto {@ApiProperty({ description: 'New group subject/name', maxLength: GROUP_NAME_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(GROUP_NAME_MAX_LENGTH)@@ -98,6 +100,7 @@ export class GroupDescriptionDto {description: 'New group description (may be empty to clear it)',maxLength: GROUP_DESCRIPTION_MAX_LENGTH,})+ @ToStrictString()@IsString()@MaxLength(GROUP_DESCRIPTION_MAX_LENGTH)description!: string;@@ -108,6 +111,7 @@ export class JoinGroupDto {description: 'Group invite code (the token from a https://chat.whatsapp.com/<code> link)',maxLength: 128,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(128)@@ -128,11 +132,13 @@ export class SetGroupPictureDto {@ApiPropertyOptional({ description: 'Base64 encoded image data' })@IsOptional()+ @ToStrictString()@IsString()base64?: string;@ApiPropertyOptional({ description: 'Image MIME type (required when using base64)', example: 'image/jpeg' })@IsOptional()+ @ToStrictString()@IsString()// A group picture is an image by definition — reject non-image mimetypes fast (400) rather than// letting the engine accept an arbitrary payload.diff --git a/src/modules/infra/dto/import-storage.dto.ts b/src/modules/infra/dto/import-storage.dto.tsindex 5f9a65b71..e0ec34950 100644--- a/src/modules/infra/dto/import-storage.dto.ts+++ b/src/modules/infra/dto/import-storage.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsString, IsNotEmpty } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';/*** Body for POST /infra/storage/import. A class (not an inline object literal) so the global@@ -8,6 +9,7 @@ import { IsString, IsNotEmpty } from 'class-validator';*/export class ImportStorageDto {@ApiProperty({ description: 'Path to the tar.gz file to import (must be inside the data directory)' })+ @ToStrictString()@IsString()@IsNotEmpty()filePath!: string;diff --git a/src/modules/infra/dto/save-config.dto.ts b/src/modules/infra/dto/save-config.dto.tsindex ae8e91734..95fe97b55 100644--- a/src/modules/infra/dto/save-config.dto.ts+++ b/src/modules/infra/dto/save-config.dto.ts@@ -1,7 +1,7 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { Type } from 'class-transformer';import { IsBoolean, IsIn, IsNumber, IsObject, IsOptional, IsString, ValidateNested } from 'class-validator';-import { ToStrictBoolean, ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';/*** Body for PUT /infra/config (saveConfig). Every section is optional: an absent section leaves the@@ -28,31 +28,37 @@ export class DatabaseConfigDto {@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()host?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()port?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()username?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()password?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()database?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()schema?: string;@@ -90,16 +96,19 @@ export class RedisConfigDto {@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()host?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()port?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()password?: string;}@@ -125,31 +134,37 @@ export class StorageConfigDto {@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()localPath?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()s3Bucket?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()s3Region?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()s3AccessKey?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()s3SecretKey?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()s3Endpoint?: string;}@@ -157,6 +172,7 @@ export class StorageConfigDto {export class EngineConfigDto {@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()type?: string;@@ -168,11 +184,13 @@ export class EngineConfigDto {@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()sessionDataPath?: string;@ApiPropertyOptional()@IsOptional()+ @ToStrictString()@IsString()browserArgs?: string;}diff --git a/src/modules/integration/dto/instance.dto.ts b/src/modules/integration/dto/instance.dto.tsindex a9a11d650..9066e8598 100644--- a/src/modules/integration/dto/instance.dto.ts+++ b/src/modules/integration/dto/instance.dto.ts@@ -11,7 +11,7 @@ import {} from 'class-validator';import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IngressUrl } from '../ingress-url';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';// Safe charset: the instanceId goes unencoded into the ingress URL path and the `<pluginId>:<instanceId>` row id.const INSTANCE_ID_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;@@ -23,6 +23,7 @@ export class CreateInstanceDto {pattern: INSTANCE_ID_PATTERN.source,example: 'chatwoot-prod-1',})+ @ToStrictString()@IsString()@Matches(INSTANCE_ID_PATTERN, { message: 'instanceId must match ^[a-zA-Z0-9_-]{1,64}$' })instanceId!: string;@@ -34,6 +35,7 @@ export class CreateInstanceDto {example: '8f3c2b1a-9d4e-4c7a-8b2f-1e6d5a4c3b2a',})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty({ message: 'sessionScope must not be empty (omit it for all sessions)' })@MaxLength(256)@@ -45,6 +47,7 @@ export class CreateInstanceDto {example: 'a1b2c3d4e5f6',})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(512)verifyToken?: string;@@ -61,6 +64,7 @@ export class CreateInstanceDto {example: 'super-secret-provider-webhook-key',})@IsOptional()+ @ToStrictString()@IsString()@MinLength(16, { message: 'secret must be at least 16 characters' })@MaxLength(512)diff --git a/src/modules/label/dto/add-label.dto.ts b/src/modules/label/dto/add-label.dto.tsindex acafd4eef..fa8340927 100644--- a/src/modules/label/dto/add-label.dto.ts+++ b/src/modules/label/dto/add-label.dto.ts@@ -1,9 +1,11 @@import { ApiProperty } from '@nestjs/swagger';import { IsString, IsNotEmpty } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';/** Validated body for adding a label to a chat (was an inline @Body literal). */export class AddLabelDto {@ApiProperty({ description: 'Label ID to add to the chat' })+ @ToStrictString()@IsString()@IsNotEmpty()labelId!: string;diff --git a/src/modules/label/dto/upsert-label.dto.ts b/src/modules/label/dto/upsert-label.dto.tsindex 23edc7a5a..b16bd41f9 100644--- a/src/modules/label/dto/upsert-label.dto.ts+++ b/src/modules/label/dto/upsert-label.dto.ts@@ -1,6 +1,6 @@import { ApiPropertyOptional } from '@nestjs/swagger';import { IsInt, IsOptional, IsString, Max, MaxLength, Min, MinLength } from 'class-validator';-import { ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';/*** The body of a label create-or-update. The id is the path parameter, not a field: WhatsApp keys the@@ -14,6 +14,7 @@ export class UpsertLabelDto {maxLength: 100,})@IsOptional()+ @ToStrictString()@IsString()@MinLength(1)// WhatsApp's own label editor caps names well below this; the bound exists so a runaway payloaddiff --git a/src/modules/media/dto/convert-media.dto.ts b/src/modules/media/dto/convert-media.dto.tsindex 283ae9864..a76f58ddc 100644--- a/src/modules/media/dto/convert-media.dto.ts+++ b/src/modules/media/dto/convert-media.dto.ts@@ -2,6 +2,7 @@ import { IsString, IsNotEmpty, ValidateIf } from 'class-validator';import { ApiPropertyOptional } from '@nestjs/swagger';import { IsMediaUrl } from '../../../common/media/media-url';import { stripBase64DataUri } from '../../message/media-cap.util';+import { ToStrictString } from '../../../common/utils/strict-boolean';/*** Media to convert, in the same url-or-base64 shape every other media endpoint accepts.@@ -16,6 +17,7 @@ export class ConvertMediaDto {example: 'https://example.com/note.m4a',})@ValidateIf((dto: ConvertMediaDto) => dto.base64 === undefined || dto.url !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()// Same rule as every send DTO: base64 wins when it holds data, so a url next to it is not fetched.@@ -27,6 +29,7 @@ export class ConvertMediaDto {example: 'SUQzBAAAAAAA...',})@ValidateIf((dto: ConvertMediaDto) => dto.url === undefined || dto.base64 !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()base64?: string;diff --git a/src/modules/message/dto/bulk-message.dto.spec.ts b/src/modules/message/dto/bulk-message.dto.spec.tsindex b2c8ca646..0b0173f73 100644--- a/src/modules/message/dto/bulk-message.dto.spec.ts+++ b/src/modules/message/dto/bulk-message.dto.spec.ts@@ -28,11 +28,10 @@ describe('SendBulkMessageDto nested media validation', () => {await rejects(imageItem({ base64: 'AAAA', evil: 'x' }));});- // Implicit conversion turns a number into its string form before @IsString runs, so the service- // receives a string either way.- it('converts a numeric base64 inside a media object to a string', async () => {- const dto = await validateBulk(imageItem({ base64: 12345 }));- expect(dto.messages[0].content.image?.base64).toBe('12345');+ // A number is not text: implicit conversion used to rewrite it into its string form before @IsString+ // ran, so the service decoded '12345' as base64 instead of the request being refused.+ it('refuses a numeric base64 inside a media object', async () => {+ await rejects(imageItem({ base64: 12345 }));});});@@ -68,10 +67,9 @@ describe('SendBulkMessageDto media url', () => {await accepts(imageItem({ url: 'https://{{host}}/a.jpg' }));});- // Converted like any string field; the per-item check then refuses '123' as not an http(s) URL.- it('converts a numeric url next to base64 to a string', async () => {- const dto = await validateBulk(imageItem({ base64: 'AAAA', url: 123 }));- expect(dto.messages[0].content.image?.url).toBe('123');+ // Refused like any other non-string field, even next to base64 (which wins when the item is sent).+ it('refuses a numeric url next to base64', async () => {+ await rejects(imageItem({ base64: 'AAAA', url: 123 }));});});diff --git a/src/modules/message/dto/bulk-message.dto.ts b/src/modules/message/dto/bulk-message.dto.tsindex ca06fa8e4..2bf78e2fd 100644--- a/src/modules/message/dto/bulk-message.dto.ts+++ b/src/modules/message/dto/bulk-message.dto.ts@@ -16,7 +16,7 @@ import {} from 'class-validator';import { Type } from 'class-transformer';import { Validate } from 'class-validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import {BATCH_ID_MAX_LENGTH,CHAT_ID_MAX_LENGTH,@@ -31,21 +31,25 @@ import { BatchMessageStatus, BatchStatus } from '../entities/message-batch.entitclass BulkMediaDto {@ApiPropertyOptional({ description: 'Media URL (http/https)' })@IsOptional()+ @ToStrictString()@IsString()url?: string;@ApiPropertyOptional({ description: 'Base64-encoded media data' })@IsOptional()+ @ToStrictString()@IsString()base64?: string;@ApiPropertyOptional({ description: 'Media MIME type' })@IsOptional()+ @ToStrictString()@IsString()mimetype?: string;@ApiPropertyOptional({ description: 'Filename (documents only)' })@IsOptional()+ @ToStrictString()@IsString()filename?: string;@@ -59,6 +63,7 @@ class BulkMediaDto {export class BulkMessageContentDto {@ApiPropertyOptional({ description: 'Text content for text messages', maxLength: MESSAGE_TEXT_MAX_LENGTH })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)text?: string;@@ -96,6 +101,7 @@ export class BulkMessageContentDto {@ApiPropertyOptional({ description: 'Caption for media messages', maxLength: 1024 })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(1024)caption?: string;@@ -121,6 +127,7 @@ export class BulkMessageContentDto {class BulkMessageItemDto {@ApiProperty({ description: 'Recipient chat ID', example: '[email protected]', maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)@@ -177,6 +184,7 @@ export class SendBulkMessageDto {maxLength: BATCH_ID_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(BATCH_ID_MAX_LENGTH)batchId?: string;diff --git a/src/modules/message/dto/message-actions.dto.ts b/src/modules/message/dto/message-actions.dto.tsindex a57b4f502..400aa4cb2 100644--- a/src/modules/message/dto/message-actions.dto.ts+++ b/src/modules/message/dto/message-actions.dto.ts@@ -13,7 +13,7 @@ import {IsIn,Validate,} from 'class-validator';-import { ToStrictBoolean, ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';import {CHAT_ID_MAX_LENGTH,MENTIONS_DESCRIPTION,@@ -41,6 +41,7 @@ export const REACTION_EMOJI_MAX_LENGTH = 32;export class SendLocationDto {@ApiProperty({ description: 'Chat ID (e.g. [email protected])', maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)@@ -58,18 +59,21 @@ export class SendLocationDto {@ApiPropertyOptional({ maxLength: LOCATION_TEXT_MAX_LENGTH })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(LOCATION_TEXT_MAX_LENGTH)description?: string;@ApiPropertyOptional({ maxLength: LOCATION_TEXT_MAX_LENGTH })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(LOCATION_TEXT_MAX_LENGTH)address?: string;@ApiPropertyOptional({ description: QUOTED_MESSAGE_ID_DESCRIPTION, example: QUOTED_MESSAGE_ID_EXAMPLE })@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId?: string;@@ -77,18 +81,21 @@ export class SendLocationDto {export class SendContactDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty({ maxLength: CONTACT_NAME_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CONTACT_NAME_MAX_LENGTH)contactName!: string;@ApiProperty({ maxLength: CONTACT_NUMBER_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CONTACT_NUMBER_MAX_LENGTH)@@ -96,6 +103,7 @@ export class SendContactDto {@ApiPropertyOptional({ description: QUOTED_MESSAGE_ID_DESCRIPTION, example: QUOTED_MESSAGE_ID_EXAMPLE })@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId?: string;@@ -103,12 +111,14 @@ export class SendContactDto {export class SendPollDto {@ApiProperty({ description: 'Chat ID (e.g. [email protected] or [email protected])', maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty({ description: 'Poll question / title', maxLength: 255, example: 'Where should we meet?' })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(255)@@ -143,6 +153,7 @@ export class SendPollDto {@ApiPropertyOptional({ description: QUOTED_MESSAGE_ID_DESCRIPTION, example: QUOTED_MESSAGE_ID_EXAMPLE })@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId?: string;@@ -150,18 +161,21 @@ export class SendPollDto {export class ReplyMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId!: string;// Same body cap as SendTextMessageDto.text — a reply cannot exceed what a send allows.@ApiProperty({ maxLength: MESSAGE_TEXT_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)@@ -185,18 +199,21 @@ export class ReplyMessageDto {export class ForwardMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)fromChatId!: string;@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)toChatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -204,12 +221,14 @@ export class ForwardMessageDto {export class ReactMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -219,6 +238,7 @@ export class ReactMessageDto {description: 'Emoji to react with. Send an empty string to remove the reaction.',maxLength: REACTION_EMOJI_MAX_LENGTH,})+ @ToStrictString()@IsString()@MaxLength(REACTION_EMOJI_MAX_LENGTH)emoji!: string;@@ -226,12 +246,14 @@ export class ReactMessageDto {export class DeleteMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -256,12 +278,14 @@ export const PIN_DURATIONS_SECONDS = [86400, 604800, 2592000] as const;export class PinMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -285,12 +309,14 @@ export const POLL_VOTE_MAX_OPTIONS = 12;export class VotePollDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty({ description: 'The poll creation message to vote on.' })+ @ToStrictString()@IsString()@IsNotEmpty()pollMessageId!: string;@@ -310,12 +336,14 @@ export class VotePollDto {export class ClickButtonDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty({ description: 'WhatsApp id of the business prompt message that offered the buttons.' })+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -325,6 +353,7 @@ export class ClickButtonDto {'Stable id of the choice to tap (inbound `buttons[].id`). URL/call CTA buttons cannot be clicked this way.',maxLength: BUTTON_ID_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()// Bounded by what a choice id can actually be, not by the text cap: the engine never offers a@@ -337,6 +366,7 @@ export class ClickButtonDto {maxLength: MESSAGE_TEXT_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)@@ -345,12 +375,14 @@ export class ClickButtonDto {export class StarMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -365,12 +397,14 @@ export class StarMessageDto {export class UnpinMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -378,12 +412,14 @@ export class UnpinMessageDto {export class EditMessageDto {@ApiProperty({ maxLength: CHAT_ID_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)chatId!: string;@ApiProperty()+ @ToStrictString()@IsString()@IsNotEmpty()messageId!: string;@@ -391,6 +427,7 @@ export class EditMessageDto {// Same body cap as SendTextMessageDto.text — an edit cannot exceed what a send allows. Bound to the// shared constant rather than restated, so the two cannot drift apart.@ApiProperty({ description: 'New text body for the message', maxLength: MESSAGE_TEXT_MAX_LENGTH })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)diff --git a/src/modules/message/dto/send-message.dto.spec.ts b/src/modules/message/dto/send-message.dto.spec.tsindex d27b801ba..02176aaf5 100644--- a/src/modules/message/dto/send-message.dto.spec.ts+++ b/src/modules/message/dto/send-message.dto.spec.ts@@ -315,6 +315,43 @@ describe('SendTextMessageDto customLinkPreview', () => {});});+// Implicit conversion rewrote a number, a boolean or an object into its string form before @IsString ran, so+// {"text":{"order":42}} was sent as the literal text "[object Object]". Every field below is documented as a+// string, in docs/06 and in the request types of all five SDKs.+describe('string fields refuse a value that is not a string', () => {+ const invalid: Array<[unknown]> = [[{ order: 42 }], [628123456789], [true]];++ it.each(invalid)('SendTextMessageDto refuses text %j', async text => {+ const errors = await validateDto(SendTextMessageDto, { chatId: '[email protected]', text });+ expect(errors.map(e => e.property)).toEqual(['text']);+ });++ it.each(invalid)('SendTextMessageDto refuses chatId %j', async chatId => {+ const errors = await validateDto(SendTextMessageDto, { chatId, text: 'hi' });+ expect(errors.map(e => e.property)).toEqual(['chatId']);+ });++ it.each(invalid)('SendMediaMessageDto refuses caption %j', async caption => {+ const errors = await validateDto(SendMediaMessageDto, {+ chatId: '[email protected]',+ url: 'https://example.com/a.jpg',+ caption,+ });+ expect(errors.map(e => e.property)).toEqual(['caption']);+ });++ it.each(invalid)('SendContactDto refuses contactNumber %j', async contactNumber => {+ const errors = await validateDto(SendContactDto, { chatId: '[email protected]', contactName: 'Alice', contactNumber });+ expect(errors.map(e => e.property)).toEqual(['contactNumber']);+ });++ it('still takes the same values spelled as strings', async () => {+ expect(await validateDto(SendTextMessageDto, { chatId: '[email protected]', text: '{"order":42}' })).toHaveLength(0);+ expect(await validateDto(SendTextMessageDto, { chatId: '[email protected]', text: '628123456789' })).toHaveLength(0);+ expect(await validateDto(SendTextMessageDto, { chatId: '[email protected]', text: 'true' })).toHaveLength(0);+ });+});+describe('published schema bounds', () => {const published = (cls: new () => object, key: string): Record<string, unknown> | undefined =>Reflect.getMetadata(DECORATORS.API_MODEL_PROPERTIES, cls.prototype as object, key) asdiff --git a/src/modules/message/dto/send-message.dto.ts b/src/modules/message/dto/send-message.dto.tsindex a7da51c9d..3e7d58049 100644--- a/src/modules/message/dto/send-message.dto.ts+++ b/src/modules/message/dto/send-message.dto.ts@@ -13,7 +13,7 @@ import {} from 'class-validator';import { Type } from 'class-transformer';import { IsMentionWidConstraint } from './is-mention-wid.validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import { IsMediaUrl } from '../../../common/media/media-url';import { stripBase64DataUri } from '../media-cap.util';@@ -84,6 +84,7 @@ export class CustomLinkPreviewDto {example: 'https://example.com/launch',maxLength: CUSTOM_PREVIEW_URL_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CUSTOM_PREVIEW_URL_MAX_LENGTH)@@ -94,6 +95,7 @@ export class CustomLinkPreviewDto {example: 'We just launched',maxLength: 256,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CUSTOM_PREVIEW_TITLE_MAX_LENGTH)@@ -101,6 +103,7 @@ export class CustomLinkPreviewDto {@ApiPropertyOptional({ description: 'Preview description', example: 'Read the announcement.', maxLength: 1024 })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(CUSTOM_PREVIEW_DESCRIPTION_MAX_LENGTH)description?: string;@@ -112,6 +115,7 @@ export class SendTextMessageDto {example: '[email protected]',maxLength: CHAT_ID_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)@@ -122,6 +126,7 @@ export class SendTextMessageDto {example: 'Hello from OpenWA!',maxLength: MESSAGE_TEXT_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(MESSAGE_TEXT_MAX_LENGTH)@@ -176,6 +181,7 @@ export class SendTextMessageDto {example: QUOTED_MESSAGE_ID_EXAMPLE,})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId?: string;@@ -214,6 +220,7 @@ export class SendMediaMessageDto {example: '[email protected]',maxLength: CHAT_ID_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)@@ -233,6 +240,7 @@ export class SendMediaMessageDto {description: 'Base64 encoded media data',})@IsOptional()+ @ToStrictString()@IsString()base64?: string;@@ -241,6 +249,7 @@ export class SendMediaMessageDto {example: 'image/jpeg',})@IsOptional()+ @ToStrictString()@IsString()mimetype?: string;@@ -251,6 +260,7 @@ export class SendMediaMessageDto {maxLength: 255,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(255)filename?: string;@@ -261,6 +271,7 @@ export class SendMediaMessageDto {maxLength: 1024,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(1024)caption?: string;@@ -285,6 +296,7 @@ export class SendMediaMessageDto {example: QUOTED_MESSAGE_ID_EXAMPLE,})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()quotedMessageId?: string;diff --git a/src/modules/message/dto/send-template.dto.ts b/src/modules/message/dto/send-template.dto.tsindex 0799dbfdc..96d8ab1a4 100644--- a/src/modules/message/dto/send-template.dto.ts+++ b/src/modules/message/dto/send-template.dto.ts@@ -10,7 +10,7 @@ import {IsBoolean,Validate,} from 'class-validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import { CHAT_ID_MAX_LENGTH, MENTIONS_DESCRIPTION, MENTIONS_MAX, MENTION_WID_MAX_LENGTH } from './send-message.dto';import { IsMentionWidConstraint } from './is-mention-wid.validator';@@ -20,6 +20,7 @@ export class SendTemplateMessageDto {example: '[email protected]',maxLength: CHAT_ID_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)@@ -30,6 +31,7 @@ export class SendTemplateMessageDto {example: 'b1c2d3e4-f5a6-7890-bcde-f01234567890',})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()templateId?: string;@@ -39,6 +41,7 @@ export class SendTemplateMessageDto {example: 'order-confirmation',})@IsOptional()+ @ToStrictString()@IsString()@IsNotEmpty()templateName?: string;diff --git a/src/modules/plugins/dto/plugin.dto.ts b/src/modules/plugins/dto/plugin.dto.tsindex 90af6d90b..92ee96b1e 100644--- a/src/modules/plugins/dto/plugin.dto.ts+++ b/src/modules/plugins/dto/plugin.dto.ts@@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsArray, IsObject, IsString, IsUrl } from 'class-validator';import type { PluginConfigSchema, PluginI18n } from '../../../core/plugins';import { PluginType, PluginStatus } from '../../../core/plugins';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class PluginDto {@ApiProperty({ description: 'Plugin ID' })@@ -94,6 +95,7 @@ export class InstallFromUrlDto {'params are ignored) — because the package is executable code and must be integrity-protected in ' +'transit. A pinned digest that does not match the downloaded archive fails the install.',})+ @ToStrictString()@IsString()// require_tld:false + allow_underscores:true so single-label hosts (a compose service, `localhost`) reach// the SSRF guard, which admits them only when SSRF_ALLOWED_HOSTS names them.diff --git a/src/modules/profile/dto/profile.dto.ts b/src/modules/profile/dto/profile.dto.tsindex 73bdff993..f753adf62 100644--- a/src/modules/profile/dto/profile.dto.ts+++ b/src/modules/profile/dto/profile.dto.ts@@ -2,9 +2,11 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsString, IsNotEmpty, MaxLength, IsOptional, Matches } from 'class-validator';import { IsMediaUrl } from '../../../common/media/media-url';import { stripBase64DataUri } from '../../message/media-cap.util';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class SetProfileNameDto {@ApiProperty({ description: 'New display name (WhatsApp limit: 25 characters)', maxLength: 25 })+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(25)@@ -16,6 +18,7 @@ export class SetProfileStatusDto {description: 'New about/status text (may be empty to clear it; WhatsApp limit: 139 characters)',maxLength: 139,})+ @ToStrictString()@IsString()@MaxLength(139)status!: string;@@ -40,6 +43,7 @@ export class SetProfilePictureDto {description: 'Base64 encoded image data',})@IsOptional()+ @ToStrictString()@IsString()base64?: string;@@ -48,6 +52,7 @@ export class SetProfilePictureDto {example: 'image/jpeg',})@IsOptional()+ @ToStrictString()@IsString()// A profile picture is an image by definition — fail non-image mimetypes fast (400) instead of// letting the engine reject (or worse, accept) an arbitrary payload.diff --git a/src/modules/search/dto/search-query.dto.ts b/src/modules/search/dto/search-query.dto.tsindex 02bd3b6ef..4c2bab7fc 100644--- a/src/modules/search/dto/search-query.dto.ts+++ b/src/modules/search/dto/search-query.dto.ts@@ -3,7 +3,7 @@ import { IsString, IsNotEmpty, IsOptional, IsEnum, IsInt, IsNumber, Max, MaxLengimport { Type } from 'class-transformer';import { MessageDirection } from '../../message/entities/message.entity';import type { MessageType } from '../../../engine/interfaces/whatsapp-engine.interface';-import { ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';import { SEARCH_OFFSET_MAX, SEARCH_QUERY_MAX_LENGTH, SEARCH_TERMS_MAX } from '../search.constants';/**@@ -23,6 +23,7 @@ export class SearchQueryDto {description: `Search term (required, non-empty, at most ${SEARCH_QUERY_MAX_LENGTH} characters and ${SEARCH_TERMS_MAX} words)`,maxLength: SEARCH_QUERY_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(SEARCH_QUERY_MAX_LENGTH)@@ -30,6 +31,7 @@ export class SearchQueryDto {@ApiPropertyOptional({ description: 'Restrict to a single session' })@IsOptional()+ @ToStrictString()@IsString()sessionId?: string;@@ -38,6 +40,7 @@ export class SearchQueryDto {"Restrict to a single chat id. A phone also matches the chat's other stored forms (the other user dialect and any lid that resolves to it).",})@IsOptional()+ @ToStrictString()@IsString()chatId?: string;@@ -46,6 +49,7 @@ export class SearchQueryDto {"Sender filter. Matches `from` or a group message's `author`; a phone also matches any lid that resolves to it.",})@IsOptional()+ @ToStrictString()@IsString()from?: string;diff --git a/src/modules/session/dto/archive-chat.dto.ts b/src/modules/session/dto/archive-chat.dto.tsindex f99acbba8..1b9c83cce 100644--- a/src/modules/session/dto/archive-chat.dto.ts+++ b/src/modules/session/dto/archive-chat.dto.ts@@ -1,6 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsBoolean, IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';export class ArchiveChatDto {@@ -9,6 +9,7 @@ export class ArchiveChatDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/create-session.dto.ts b/src/modules/session/dto/create-session.dto.tsindex 1a5670233..0db24ad20 100644--- a/src/modules/session/dto/create-session.dto.ts+++ b/src/modules/session/dto/create-session.dto.ts@@ -1,6 +1,7 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { Transform } from 'class-transformer';import { IsIn, IsObject, IsOptional, IsString, IsUrl, Matches, MaxLength, MinLength, Validate } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';import { MaxCodePoints } from '../../../common/validation/max-code-points';import { HasDecodableProxyCredentialsConstraint } from './has-decodable-proxy-credentials.validator';import { normaliseSessionConfig, RecognisedSessionConfigConstraint } from './recognised-session-config.validator';@@ -12,6 +13,7 @@ export class CreateSessionDto {minLength: 3,maxLength: 50,})+ @ToStrictString()@IsString()@MinLength(3)@MaxLength(50)@@ -52,6 +54,7 @@ export class CreateSessionDto {maxLength: 255,})@IsOptional()+ @ToStrictString()@IsString()@MaxCodePoints(255)// Reject a malformed/non-proxy URL at the boundary (credentialed http://user:pass@host anddiff --git a/src/modules/session/dto/delete-chat.dto.ts b/src/modules/session/dto/delete-chat.dto.tsindex 5f8ddb565..506163283 100644--- a/src/modules/session/dto/delete-chat.dto.ts+++ b/src/modules/session/dto/delete-chat.dto.ts@@ -1,6 +1,7 @@import { ApiProperty } from '@nestjs/swagger';import { IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class DeleteChatDto {@ApiProperty({@@ -8,6 +9,7 @@ export class DeleteChatDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/mark-chat-read.dto.ts b/src/modules/session/dto/mark-chat-read.dto.tsindex 694b9ba06..d7909ae87 100644--- a/src/modules/session/dto/mark-chat-read.dto.ts+++ b/src/modules/session/dto/mark-chat-read.dto.ts@@ -10,6 +10,7 @@ import {MaxLength,} from 'class-validator';import { CHAT_ID_MAX_LENGTH, CHAT_JID_MESSAGE, CHAT_JID_PATTERN } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';/*** Ceiling on one request's receipt batch, so a single call cannot hand the engine an unbounded key@@ -34,6 +35,7 @@ export class MarkChatReadDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/mark-chat-unread.dto.ts b/src/modules/session/dto/mark-chat-unread.dto.tsindex 193b29b5e..577533076 100644--- a/src/modules/session/dto/mark-chat-unread.dto.ts+++ b/src/modules/session/dto/mark-chat-unread.dto.ts@@ -1,6 +1,7 @@import { ApiProperty } from '@nestjs/swagger';import { IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';import { CHAT_ID_MAX_LENGTH, CHAT_JID_MESSAGE, CHAT_JID_PATTERN } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';/*** Deliberately separate from {@link MarkChatReadDto}, which the unread route used to share. The read@@ -13,6 +14,7 @@ export class MarkChatUnreadDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/mute-chat.dto.ts b/src/modules/session/dto/mute-chat.dto.tsindex fc4c58296..fcaa51bef 100644--- a/src/modules/session/dto/mute-chat.dto.ts+++ b/src/modules/session/dto/mute-chat.dto.ts@@ -1,6 +1,7 @@import { ApiProperty } from '@nestjs/swagger';import { IsInt, IsNotEmpty, IsString, Matches, Max, Min, ValidateIf, MaxLength } from 'class-validator';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';/*** The last instant a JavaScript Date can hold. whatsapp-web.js converts `muteUntil` through Date, which is@@ -15,6 +16,7 @@ export class MuteChatDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/pin-chat.dto.ts b/src/modules/session/dto/pin-chat.dto.tsindex 47e5b35dd..733c9e14c 100644--- a/src/modules/session/dto/pin-chat.dto.ts+++ b/src/modules/session/dto/pin-chat.dto.ts@@ -1,6 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsBoolean, IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';export class PinChatDto {@@ -9,6 +9,7 @@ export class PinChatDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/presence.dto.ts b/src/modules/session/dto/presence.dto.tsindex 13a6bac7b..c21d28dc1 100644--- a/src/modules/session/dto/presence.dto.ts+++ b/src/modules/session/dto/presence.dto.ts@@ -1,6 +1,6 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsBoolean, IsNotEmpty, IsString, Matches, MaxLength } from 'class-validator';-import { ToStrictBoolean } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictString } from '../../../common/utils/strict-boolean';import { CHAT_ID_MAX_LENGTH, CHAT_JID_MESSAGE, CHAT_JID_PATTERN } from '../../message/dto/send-message.dto';export class SetOwnPresenceDto {@@ -20,6 +20,7 @@ export class SubscribePresenceDto {description: "Chat ID in the active engine's native format (e.g. [email protected] on whatsapp-web.js)",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/session/dto/request-pairing-code.dto.ts b/src/modules/session/dto/request-pairing-code.dto.tsindex a45374cab..12b5bc1b4 100644--- a/src/modules/session/dto/request-pairing-code.dto.ts+++ b/src/modules/session/dto/request-pairing-code.dto.ts@@ -1,5 +1,6 @@import { ApiProperty } from '@nestjs/swagger';import { IsNotEmpty, IsString, Matches } from 'class-validator';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class RequestPairingCodeDto {@ApiProperty({@@ -7,6 +8,7 @@ export class RequestPairingCodeDto {example: '628123456789',pattern: '^[0-9]{6,15}$',})+ @ToStrictString()@IsString()@IsNotEmpty()// Digits only (no +, spaces, or dashes); 6–15 digits covers E.164.diff --git a/src/modules/session/dto/send-chat-state.dto.ts b/src/modules/session/dto/send-chat-state.dto.tsindex c86436a99..fffc742b0 100644--- a/src/modules/session/dto/send-chat-state.dto.ts+++ b/src/modules/session/dto/send-chat-state.dto.ts@@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger';import { IsIn, IsNotEmpty, IsString, MaxLength } from 'class-validator';import type { ChatState } from '../../../engine/interfaces/whatsapp-engine.interface';import { CHAT_ID_MAX_LENGTH } from '../../message/dto/send-message.dto';+import { ToStrictString } from '../../../common/utils/strict-boolean';export class SendChatStateDto {@ApiProperty({@@ -12,6 +13,7 @@ export class SendChatStateDto {description: "Chat ID, in the active engine's native format (e.g. [email protected])",example: '[email protected]',})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(CHAT_ID_MAX_LENGTH)diff --git a/src/modules/status/dto/send-media-status.dto.ts b/src/modules/status/dto/send-media-status.dto.tsindex cf0722f2b..c4d0df4fc 100644--- a/src/modules/status/dto/send-media-status.dto.ts+++ b/src/modules/status/dto/send-media-status.dto.ts@@ -15,6 +15,7 @@ import { Type } from 'class-transformer';import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsMediaUrl } from '../../../common/media/media-url';import { stripBase64DataUri } from '../../message/media-cap.util';+import { ToStrictString } from '../../../common/utils/strict-boolean';class StatusMediaInput {@ApiPropertyOptional({@@ -22,6 +23,7 @@ class StatusMediaInput {example: 'https://example.com/banner.jpg',})@ValidateIf((media: StatusMediaInput) => media.base64 === undefined || media.url !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()// base64 wins when both are sent, so a url next to it is not fetched and not checked; a base64 that is@@ -34,12 +36,14 @@ class StatusMediaInput {example: '/9j/4AAQSkZJRg...',})@ValidateIf((media: StatusMediaInput) => media.url === undefined || media.base64 !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()base64?: string;@ApiPropertyOptional({ description: 'MIME type. Required when sending base64.', example: 'image/jpeg' })@IsOptional()+ @ToStrictString()@IsString()mimetype?: string;}@@ -54,6 +58,7 @@ export class SendImageStatusDto {@ApiPropertyOptional({ description: 'Optional caption.', example: 'New drop!', maxLength: 1024 })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(1024)caption?: string;@@ -86,6 +91,7 @@ export class SendVideoStatusDto {@ApiPropertyOptional({ description: 'Optional caption.', example: 'Demo', maxLength: 1024 })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(1024)caption?: string;@@ -132,6 +138,7 @@ export class SendVoiceStatusDto {example: '#25D366',})@IsOptional()+ @ToStrictString()@IsString()@Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'backgroundColor must be a hex color (e.g., #25D366)' })backgroundColor?: string;diff --git a/src/modules/status/dto/send-text-status.dto.ts b/src/modules/status/dto/send-text-status.dto.tsindex 6a09825d4..f4a6aa68b 100644--- a/src/modules/status/dto/send-text-status.dto.ts+++ b/src/modules/status/dto/send-text-status.dto.ts@@ -1,6 +1,6 @@import { IsString, IsOptional, IsInt, IsIn, Matches, MaxLength, IsArray, ArrayMaxSize } from 'class-validator';import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';-import { ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';export class SendTextStatusDto {@ApiProperty({@@ -9,6 +9,7 @@ export class SendTextStatusDto {minLength: 1,maxLength: 4096,})+ @ToStrictString()@IsString()// A blank body would publish an empty story (Baileys) or fail inside the engine with a 500.@Matches(/\S/, { message: 'text must not be blank' })@@ -17,6 +18,7 @@ export class SendTextStatusDto {@ApiPropertyOptional({ description: 'Background color (hex).', example: '#25D366' })@IsOptional()+ @ToStrictString()@IsString()@Matches(/^#[0-9A-Fa-f]{6}$/, { message: 'backgroundColor must be a hex color (e.g., #25D366)' })backgroundColor?: string;diff --git a/src/modules/template/dto/template.dto.ts b/src/modules/template/dto/template.dto.tsindex 47f086ed1..86f06c2b5 100644--- a/src/modules/template/dto/template.dto.ts+++ b/src/modules/template/dto/template.dto.ts@@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';import { IsString, IsNotEmpty, IsOptional, MaxLength, ValidateIf } from 'class-validator';import { MaxCodePoints } from '../../../common/validation/max-code-points';import { NoNulCharacter } from '../../../common/validation/no-nul-character';+import { ToStrictString } from '../../../common/utils/strict-boolean';const NAME_MAX_LENGTH = 100;const BODY_MAX_LENGTH = 4096;@@ -13,6 +14,7 @@ export class CreateTemplateDto {example: 'order-confirmation',maxLength: NAME_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxCodePoints(NAME_MAX_LENGTH)@@ -24,6 +26,7 @@ export class CreateTemplateDto {example: 'Hi {{customer}}, your order {{orderId}} has shipped.',maxLength: BODY_MAX_LENGTH,})+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(BODY_MAX_LENGTH)@@ -36,6 +39,7 @@ export class CreateTemplateDto {maxLength: HEADER_FOOTER_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(HEADER_FOOTER_MAX_LENGTH)@NoNulCharacter()@@ -47,6 +51,7 @@ export class CreateTemplateDto {maxLength: HEADER_FOOTER_MAX_LENGTH,})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(HEADER_FOOTER_MAX_LENGTH)@NoNulCharacter()@@ -57,6 +62,7 @@ export class UpdateTemplateDto {@ApiPropertyOptional({ description: 'Template name', maxLength: NAME_MAX_LENGTH })// Not @IsOptional: that also skips null, which then reaches the NOT NULL column as a 500.@ValidateIf((o: UpdateTemplateDto) => o.name !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()@MaxCodePoints(NAME_MAX_LENGTH)@@ -65,6 +71,7 @@ export class UpdateTemplateDto {@ApiPropertyOptional({ description: 'Template body with {{variable}} placeholders', maxLength: BODY_MAX_LENGTH })@ValidateIf((o: UpdateTemplateDto) => o.body !== undefined)+ @ToStrictString()@IsString()@IsNotEmpty()@MaxLength(BODY_MAX_LENGTH)@@ -73,6 +80,7 @@ export class UpdateTemplateDto {@ApiPropertyOptional({ description: 'Optional header text', maxLength: HEADER_FOOTER_MAX_LENGTH })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(HEADER_FOOTER_MAX_LENGTH)@NoNulCharacter()@@ -80,6 +88,7 @@ export class UpdateTemplateDto {@ApiPropertyOptional({ description: 'Optional footer text', maxLength: HEADER_FOOTER_MAX_LENGTH })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(HEADER_FOOTER_MAX_LENGTH)@NoNulCharacter()diff --git a/src/modules/webhook/dto/webhook.dto.ts b/src/modules/webhook/dto/webhook.dto.tsindex fa5d7a3ae..852c834b7 100644--- a/src/modules/webhook/dto/webhook.dto.ts+++ b/src/modules/webhook/dto/webhook.dto.ts@@ -21,7 +21,7 @@ import { MAX_CONDITIONS } from '../filters/filter-types';import type { FilterOperator, WebhookFilters } from '../filters/filter-types';import { IsValidWebhookFilters } from '../filters/filter-validation';import { IsHeaderMap } from './is-header-map.validator';-import { ToStrictBoolean, ToStrictNumber } from '../../../common/utils/strict-boolean';+import { ToStrictBoolean, ToStrictNumber, ToStrictString } from '../../../common/utils/strict-boolean';import { MaxCodePoints } from '../../../common/validation/max-code-points';/**@@ -151,6 +151,7 @@ export class CreateWebhookDto {example: 'your-webhook-signing-secret',})@IsOptional()+ @ToStrictString()@IsString()// A short secret signs webhooks badly: HMAC-SHA256 over a 4-char key is brute-forcible from one// observed signature. 16 is the floor, not a recommendation.@@ -240,6 +241,7 @@ export class UpdateWebhookDto {// here, where it costs a `400` to ignore rather than a silent downgrade.})@IsOptional()+ @ToStrictString()@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"@@ -439,12 +441,14 @@ export class RedriveWebhookDeliveriesDto {example: 'my-session',})@IsOptional()+ @ToStrictString()@IsString()@MaxLength(128)sessionId?: string;@ApiPropertyOptional({ description: 'Only rows of this webhook.', example: '0a941dac-a965-45e7-b318-74ae8be134f0' })@IsOptional()+ @ToStrictString()@IsString()@MaxLength(128)webhookId?: string;diff --git a/test/message-send.e2e-spec.ts b/test/message-send.e2e-spec.tsindex 502332193..7aaedf0ca 100644--- a/test/message-send.e2e-spec.ts+++ b/test/message-send.e2e-spec.ts@@ -128,6 +128,15 @@ describe('Message send endpoints (e2e)', () => {expect(engine.sendTextMessage).toHaveBeenCalledWith('[email protected]', 'hello from e2e');});+ // Implicit conversion used to rewrite these into their string forms, so the engine was called with+ // '[object Object]', 'true' or '5' and the customer received that as the message.+ it.each([[{ order: 42 }], [true], [5]])('send-text refuses a text of %j and never reaches the engine', async text => {+ await post('send-text', { chatId: '[email protected]', text }).expect(400);+ await post('send-text', { chatId: text, text: 'hello' }).expect(400);++ expect(engine.sendTextMessage).not.toHaveBeenCalled();+ });+it('send-image returns 201 and hands the base64 payload to the engine', async () => {const base64 = Buffer.from('GIF89a').toString('base64');const res = await post('send-image', {