Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(config): boot-validate AUDIT_RETENTION_DAYS
Yudhi Armyndharis1835856310bb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 75738dc60..35ba8adef 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added- Turkish (`tr`) dashboard translation. Thanks @codedByCan.+- `AUDIT_RETENTION_DAYS` is checked at boot, so a typo fails startup with a named error instead of silently reverting to the 90-day default. It is validated as non-negative rather than positive, because `0` is the documented switch that disables audit-log pruning entirely.### Fixeddiff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.tsindex 6ed7763f5..e4c4aa788 100644--- a/src/config/env.validation.spec.ts+++ b/src/config/env.validation.spec.ts@@ -107,6 +107,14 @@ describe('validateEnv', () => {expect(() => validateEnv({ WEBHOOK_MAX_PER_SESSION: '0', WEBHOOK_MEDIA_INLINE_MAX_BYTES: '0' })).not.toThrow();});+ it('rejects a non-integer audit retention (0 is the documented retention-off switch)', () => {+ expect(() => validateEnv({ AUDIT_RETENTION_DAYS: 'ninety' })).toThrow(/AUDIT_RETENTION_DAYS/);+ expect(() => validateEnv({ AUDIT_RETENTION_DAYS: '90.5' })).toThrow(/AUDIT_RETENTION_DAYS/);+ // 0 disables pruning in audit.service.ts, so this knob must never become positive-only.+ expect(() => validateEnv({ AUDIT_RETENTION_DAYS: '0' })).not.toThrow();+ expect(() => validateEnv({ AUDIT_RETENTION_DAYS: '90' })).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 7dfb3697d..0d9ca179b 100644--- a/src/config/env.validation.ts+++ b/src/config/env.validation.ts@@ -173,6 +173,7 @@ export function validateEnv(config: EnvConfig): EnvConfig {'AUTOMATION_MAX_PER_SESSION', // 0 = unlimited'WEBHOOK_MEDIA_INLINE_MAX_BYTES', // 0 = never inline media'EXPORT_INLINE_MEDIA_BUDGET_BYTES', // 0 = a data export carries no inline media at all+ 'AUDIT_RETENTION_DAYS', // 0 = retention disabled, so this cannot be positive-only]) {checkNonNegativeInt(key);}