Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(search): require integer limit and offset
Yudhi Armyndharisbef1e455d0b9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8269e0bdf..e65265280 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- `POST /messages/send-bulk` answers 400 for an item with an empty `chatId`, a text item without text, or a media item without a `url` or `base64` under its type; such items used to be accepted with 202 and fail later.- `POST /messages/send-bulk` answers 400, not 500, when a concurrent request already created the same `batchId`.- `PUT /templates/:id` answers 400, not 500, for a `null` `name` or `body`.+- `GET /api/search` answers 400, not 500, for a fractional `limit` or `offset`.- `POST /messages/send-template` without `templateId` or `templateName` answers 400 instead of 404.## [0.23.5] - 2026-09-14diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 995224742..2bf969dbf 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -6160,8 +6160,8 @@ Search messages across sessions (active search provider).| `from` | string | No | — | Filter by sender. || `dateFrom` | integer (epoch ms) | No | — | Inclusive lower bound on `timestamp`. A non-numeric value is rejected with `400`. || `dateTo` | integer (epoch ms) | No | — | Inclusive upper bound on `timestamp`. A non-numeric value is rejected with `400`. |-| `limit` | integer (≥ 1) | No | `50` | Max hits to return. Clamped to `SEARCH_LIMIT_MAX` (default `100`). A non-numeric value is rejected with `400`. |-| `offset` | integer (≥ 0) | No | `0` | Pagination offset. A non-numeric value is rejected with `400`. |+| `limit` | integer (≥ 1) | No | `50` | Max hits to return. Clamped to `SEARCH_LIMIT_MAX` (default `100`). A non-integer value is rejected with `400`. |+| `offset` | integer (≥ 0) | No | `0` | Pagination offset. A non-integer value is rejected with `400`. |**Response** `200` — `SearchResults`diff --git a/src/modules/search/dto/search-query.dto.spec.ts b/src/modules/search/dto/search-query.dto.spec.tsindex db03babf7..5e41a6148 100644--- a/src/modules/search/dto/search-query.dto.spec.ts+++ b/src/modules/search/dto/search-query.dto.spec.ts@@ -27,6 +27,13 @@ describe('SearchQueryDto', () => {expect(validateSync(dto).some(e => e.property === 'offset')).toBe(true);});+ // Both are bound straight into LIMIT ? OFFSET ?, where SQLite and PostgreSQL reject a fraction with a+ // 500; the DTO must stop it as a 400.+ it('rejects a fractional limit or offset', () => {+ expect(validateSync(fromQuery({ q: 'hello', limit: '1.5' })).some(e => e.property === 'limit')).toBe(true);+ expect(validateSync(fromQuery({ q: 'hello', offset: '0.5' })).some(e => e.property === 'offset')).toBe(true);+ });+it('rejects limit < 1 (@Min(1))', () => {const dto = fromQuery({ q: 'hello', limit: '0' });expect(validateSync(dto).some(e => e.property === 'limit')).toBe(true);diff --git a/src/modules/search/dto/search-query.dto.ts b/src/modules/search/dto/search-query.dto.tsindex 7af5e9839..a4cf7a4dd 100644--- a/src/modules/search/dto/search-query.dto.ts+++ b/src/modules/search/dto/search-query.dto.ts@@ -1,5 +1,5 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';-import { IsString, IsNotEmpty, IsOptional, IsEnum, IsNumber, Min } from 'class-validator';+import { IsString, IsNotEmpty, IsOptional, IsEnum, IsInt, IsNumber, Min } from 'class-validator';import { Type } from 'class-transformer';import { MessageDirection } from '../../message/entities/message.entity';import type { MessageType } from '../../../engine/interfaces/whatsapp-engine.interface';@@ -62,7 +62,7 @@ export class SearchQueryDto {@ApiPropertyOptional({ description: 'Max hits to return', type: Number })@IsOptional()@Type(() => Number)- @IsNumber()+ @IsInt()@Min(1)limit?: number;@@ -70,7 +70,7 @@ export class SearchQueryDto {@IsOptional()@ToStrictNumber()@Type(() => Number)- @IsNumber()+ @IsInt()@Min(0)offset?: number;}