Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): cap every retention window at 36500 days
Yudhi Armyndharis083546a59678
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.tsindex 92b84e28c..67f555ebd 100644--- a/src/config/env.validation.spec.ts+++ b/src/config/env.validation.spec.ts@@ -226,6 +226,21 @@ describe('validateEnv', () => {expect(() => validateEnv({ MESSAGE_RETENTION_DAYS: '36501' })).toThrow(/MESSAGE_RETENTION_DAYS.*36500/);});+ // A "keep forever" row of nines binds on SQLite as a truncated year that sorts after today, so the+ // prune would delete every row. Each retention window shares the message-retention cap.+ it.each([+ 'AUDIT_RETENTION_DAYS',+ 'CHAT_MEDIA_ARCHIVE_TTL_DAYS',+ 'WEBHOOK_FAILURE_RETENTION_DAYS',+ 'WEBHOOK_OUTBOX_RETENTION_DAYS',+ 'INGRESS_RETENTION_DAYS',+ 'INGRESS_DEDUP_RETENTION_DAYS',+ ])('rejects a %s above 36500 days', key => {+ expect(() => validateEnv({ [key]: '9999999' })).toThrow(new RegExp(`${key} must be at most 36500`));+ expect(() => validateEnv({ [key]: '36501' })).toThrow(new RegExp(`${key} must be at most 36500`));+ expect(() => validateEnv({ [key]: '36500' })).not.toThrow();+ });+it('rejects a non-positive / non-integer WEBHOOK_MAX_PAYLOAD_BYTES (0 would reject every dispatch)', () => {expect(() => validateEnv({ WEBHOOK_MAX_PAYLOAD_BYTES: '0' })).toThrow(/WEBHOOK_MAX_PAYLOAD_BYTES/);expect(() => validateEnv({ WEBHOOK_MAX_PAYLOAD_BYTES: 'abc' })).toThrow(/WEBHOOK_MAX_PAYLOAD_BYTES/);diff --git a/src/config/env.validation.ts b/src/config/env.validation.tsindex 742a05a14..0a004d7c6 100644--- a/src/config/env.validation.ts+++ b/src/config/env.validation.ts@@ -262,11 +262,24 @@ export function validateEnv(config: EnvConfig): EnvConfig {]) {checkInt(key);}- // A window past about a century gives a cutoff SQLite compares as a later date, deleting every- // message. Keep in step with MAX_MESSAGE_RETENTION_DAYS in message-retention.service.ts.- const messageRetentionDays = str('MESSAGE_RETENTION_DAYS');- if (messageRetentionDays !== undefined && Number(messageRetentionDays) > 36500) {- errors.push(`MESSAGE_RETENTION_DAYS must be at most 36500 (got "${messageRetentionDays}")`);+ // TypeORM binds a Date on SQLite with its year cut to the last 4 digits, so a cutoff before about+ // year -2000 (roughly 1.48M days back) can bind as a year that sorts after today and the prune+ // deletes every row. A "keep forever" row of nines is such a value. 36500 is a conservative cap+ // well inside the safe range. Keep in step with MAX_MESSAGE_RETENTION_DAYS in+ // message-retention.service.ts.+ for (const key of [+ 'MESSAGE_RETENTION_DAYS',+ 'AUDIT_RETENTION_DAYS',+ 'CHAT_MEDIA_ARCHIVE_TTL_DAYS',+ 'WEBHOOK_FAILURE_RETENTION_DAYS',+ 'WEBHOOK_OUTBOX_RETENTION_DAYS',+ 'INGRESS_RETENTION_DAYS',+ 'INGRESS_DEDUP_RETENTION_DAYS',+ ]) {+ const days = str(key);+ if (days !== undefined && Number(days) > 36500) {+ errors.push(`${key} must be at most 36500 (got "${days}")`);+ }}// BAILEYS_WA_VERSION: optional version pin for the Baileys engine (e.g. 2.3000.1045340097 or 2,3000,1045340097)