Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): reject unit-suffixed plugin, storage and retention knobs

Yudhi Armyndharisf7b42c5e9a66
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.ts
index b874b16c1..2625ea096 100644
--- a/src/config/env.validation.spec.ts
+++ b/src/config/env.validation.spec.ts
@@ -591,6 +591,39 @@ describe('validateEnv', () => {
expect(() => validateEnv({ CHAT_MEDIA_ARCHIVE_TTL_DAYS: '0' })).not.toThrow();
});
+ // parseInt reads a unit-suffixed value as its leading digits: `5mb` became a 5-byte plugin download cap.
+ it.each([
+ ['PLUGIN_DOWNLOAD_MAX_BYTES', '5mb'],
+ ['PLUGIN_STORAGE_MAX_BYTES', '50mb'],
+ ['PLUGIN_CAP_TIMEOUT_MS', '30s'],
+ ['TEMPLATE_RENDER_MAX_CHARS', '64k'],
+ ['STORAGE_IMPORT_MAX_BYTES', '200mb'],
+ ['STORAGE_IMPORT_MAX_ENTRIES', '1e5'],
+ ['STORAGE_LIST_MAX_FILES', '100k'],
+ ['BAILEYS_MESSAGE_STORE_LIMIT', '5k'],
+ ])('rejects a unit-suffixed or zero %s', (key, bad) => {
+ expect(() => validateEnv({ [key]: bad })).toThrow(new RegExp(`${key} must be a positive integer`));
+ expect(() => validateEnv({ [key]: '0' })).toThrow(new RegExp(`${key} must be a positive integer`));
+ expect(() => validateEnv({ [key]: '1000' })).not.toThrow();
+ });
+
+ it('rejects a unit-suffixed SHUTDOWN_DELAY_MS but keeps 0 (no drain)', () => {
+ expect(() => validateEnv({ SHUTDOWN_DELAY_MS: '3s' })).toThrow(/SHUTDOWN_DELAY_MS must be a non-negative integer/);
+ expect(() => validateEnv({ SHUTDOWN_DELAY_MS: '0' })).not.toThrow();
+ });
+
+ it.each([
+ 'WEBHOOK_FAILURE_RETENTION_DAYS',
+ 'WEBHOOK_OUTBOX_RETENTION_DAYS',
+ 'INGRESS_RETENTION_DAYS',
+ 'INGRESS_DEDUP_RETENTION_DAYS',
+ ])('rejects a non-integer %s and keeps 0 and negatives', key => {
+ expect(() => validateEnv({ [key]: 'ninety' })).toThrow(new RegExp(`${key} must be an integer`));
+ expect(() => validateEnv({ [key]: '30d' })).toThrow(new RegExp(`${key} must be an integer`));
+ expect(() => validateEnv({ [key]: '0' })).not.toThrow();
+ expect(() => validateEnv({ [key]: '-1' })).not.toThrow();
+ });
+
// Node fires a timer delay above 2^31-1 ms after 1 ms, so these would spin instead of waiting.
it.each([
'MEDIA_CONVERSION_TIMEOUT_MS',
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 26f2423b0..dea027df9 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -233,6 +233,7 @@ export function validateEnv(config: EnvConfig): EnvConfig {
'INGRESS_RETRY_DELAY_MS', // 0 = retry without backoff
'REDIS_CACHE_DB',
'INBOUND_MEDIA_GLOBAL_CONCURRENCY', // 0 = no process-wide ceiling, only the per-session one
+ 'SHUTDOWN_DELAY_MS', // 0 = no drain; parseInt read `3s` as a 3 ms drain
]) {
checkNonNegativeInt(key);
}
@@ -257,6 +258,11 @@ export function validateEnv(config: EnvConfig): EnvConfig {
for (const key of [
'AUDIT_RETENTION_DAYS', // <= 0 disables retention
'MESSAGE_RETENTION_DAYS', // unset or <= 0 keeps messages forever
+ 'WEBHOOK_FAILURE_RETENTION_DAYS', // <= 0 disables retention
+ 'INGRESS_RETENTION_DAYS', // <= 0 disables retention
+ // <= 0 cannot disable these two: the read site warns and keeps its default.
+ 'WEBHOOK_OUTBOX_RETENTION_DAYS',
+ 'INGRESS_DEDUP_RETENTION_DAYS',
]) {
checkInt(key);
}
@@ -358,6 +364,16 @@ export function validateEnv(config: EnvConfig): EnvConfig {
// the boot sweep delete every archive older than 24 ms, breaking export, restart, import.
'STORAGE_EXPORT_TTL_MS',
'STORAGE_EXPORT_SWEEP_MAX_AGE_MS',
+ // Same parseInt read: `5mb` became a 5-byte plugin download cap, `30s` a 30 ms capability timeout
+ // and `64k` a 64-character template render cap.
+ 'PLUGIN_DOWNLOAD_MAX_BYTES',
+ 'PLUGIN_STORAGE_MAX_BYTES',
+ 'PLUGIN_CAP_TIMEOUT_MS',
+ 'TEMPLATE_RENDER_MAX_CHARS',
+ 'STORAGE_IMPORT_MAX_BYTES',
+ 'STORAGE_IMPORT_MAX_ENTRIES',
+ 'STORAGE_LIST_MAX_FILES',
+ 'BAILEYS_MESSAGE_STORE_LIMIT',
// Each read fell back to its default on 0 or garbage, or passed a negative or fractional value on
// (SEARCH_LIMIT_MAX reached plugin search providers as-is).
'SEARCH_LIMIT_MAX',