Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): validate the booleans whose typo silently inverts them

Yudhi Armyndharis1eff667af8f5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8b480edc..54522abb2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- **Fourteen more boolean environment variables are now validated at boot** — they are read with a bare `=== 'true'` / `!== 'false'` comparison, so a spelling like `DATABASE_SSL=require` silently configured the opposite of what was asked for; `DATABASE_SSL` in particular read as OFF and sent credentials in plaintext to a server the operator believed was TLS-protected. Only `true`/`false` (or blank) are accepted now, so a deployment using another spelling will fail startup until it is corrected. `MCP_READONLY` and `PUPPETEER_HEADLESS` stay tolerant deliberately — both fail toward the safe state.
- **The API description now documents the two statuses middleware returns before routing** — `415` for a compressed request body and `503` with `Retry-After` when too much body data is already in flight, neither of which appeared anywhere in the OpenAPI document despite applying to every operation.
- **The Helm chart now states the reason `replicaCount` must stay 1 that actually applies today** — the warning described two pods corrupting shared session auth, which a session lease and per-pod volumes already prevent, so an operator acting on it would mitigate the wrong thing.
diff --git a/src/config/env.validation.spec.ts b/src/config/env.validation.spec.ts
index 2b72b931c..78a0e4b65 100644
--- a/src/config/env.validation.spec.ts
+++ b/src/config/env.validation.spec.ts
@@ -152,6 +152,37 @@ describe('validateEnv', () => {
expect(() => validateEnv({})).not.toThrow();
});
+ it('rejects a mistyped value for the datastore, webhook and engine booleans too', () => {
+ // Read with the same bare `=== 'true'` / `!== 'false'` comparison but absent from the strict list,
+ // so a typo configured the opposite of what the operator asked for, in silence. DATABASE_SSL is
+ // the one that fails OPEN: `require` is the natural Postgres spelling and reads as OFF, so a
+ // connection the operator believed was TLS-protected runs in plaintext.
+ expect(() => validateEnv({ DATABASE_SSL: 'require' })).toThrow(/DATABASE_SSL/);
+ expect(() => validateEnv({ DATABASE_SSL_REJECT_UNAUTHORIZED: '0' })).toThrow(/DATABASE_SSL_REJECT_UNAUTHORIZED/);
+ expect(() => validateEnv({ MAIN_DATABASE_SYNCHRONIZE: 'False' })).toThrow(/MAIN_DATABASE_SYNCHRONIZE/);
+ expect(() => validateEnv({ ALLOW_UNSIGNED_INGRESS: 'yes' })).toThrow(/ALLOW_UNSIGNED_INGRESS/);
+ expect(() => validateEnv({ ALLOW_DEV_API_KEY: '1' })).toThrow(/ALLOW_DEV_API_KEY/);
+ expect(() => validateEnv({ WEBHOOK_SSRF_PROTECT: 'off' })).toThrow(/WEBHOOK_SSRF_PROTECT/);
+ expect(() => validateEnv({ WEBHOOK_CONTACT_DETAILS: 'on' })).toThrow(/WEBHOOK_CONTACT_DETAILS/);
+ expect(() => validateEnv({ BAILEYS_SYNC_FULL_HISTORY: 'True' })).toThrow(/BAILEYS_SYNC_FULL_HISTORY/);
+ expect(() => validateEnv({ BAILEYS_MARK_ONLINE_ON_CONNECT: 'ture' })).toThrow(/BAILEYS_MARK_ONLINE_ON_CONNECT/);
+ expect(() => validateEnv({ POSTGRES_BUILTIN: 'yes' })).toThrow(/POSTGRES_BUILTIN/);
+ expect(() => validateEnv({ REDIS_BUILTIN: 'yes' })).toThrow(/REDIS_BUILTIN/);
+ expect(() => validateEnv({ MINIO_BUILTIN: 'yes' })).toThrow(/MINIO_BUILTIN/);
+ expect(() => validateEnv({ CACHE_ENABLED: '1' })).toThrow(/CACHE_ENABLED/);
+ expect(() => validateEnv({ DATABASE_LOGGING: '1' })).toThrow(/DATABASE_LOGGING/);
+
+ // Canonical values, and the blank a compose `${KEY:-}` forward renders, both stay legal.
+ expect(() => validateEnv({ DATABASE_SSL: 'true', MAIN_DATABASE_SYNCHRONIZE: 'false' })).not.toThrow();
+ expect(() => validateEnv({ DATABASE_SSL: '', WEBHOOK_SSRF_PROTECT: '' })).not.toThrow();
+
+ // Deliberately still tolerant, because both fail toward the SAFE state and the repo tests that
+ // tolerance: mcp.server.spec.ts asserts MCP_READONLY='yes' stays read-only, and
+ // PUPPETEER_HEADLESS='new' is a real Puppeteer value that works today.
+ expect(() => validateEnv({ MCP_READONLY: 'yes' })).not.toThrow();
+ expect(() => validateEnv({ PUPPETEER_HEADLESS: 'new' })).not.toThrow();
+ });
+
it('rejects a REDIS_ENABLED typo instead of silently downgrading throttler+cache to in-memory', () => {
// REDIS_ENABLED is read at boot with `=== 'true'` (throttler storage in app.module.ts,
// CacheService), so a typo flips rate limiting + caching to per-process in-memory with zero
diff --git a/src/config/env.validation.ts b/src/config/env.validation.ts
index 3a44961d0..fec1ff0cf 100644
--- a/src/config/env.validation.ts
+++ b/src/config/env.validation.ts
@@ -300,6 +300,45 @@ export function validateEnv(config: EnvConfig): EnvConfig {
// conversion/archive endpoints answer as if nothing was configured. Same class as the above.
'MEDIA_CONVERSION_ENABLED',
'CHAT_MEDIA_ARCHIVE_ENABLED',
+ // Read with `=== 'true'` in BOTH configuration.ts and data-source.ts, and this is the one whose
+ // typo fails OPEN: `DATABASE_SSL=require` is the natural Postgres spelling and reads as OFF, so
+ // credentials and message bodies cross the wire in plaintext to a server the operator believed
+ // was TLS-protected. Nothing logs it.
+ 'DATABASE_SSL',
+ // `!== 'false'`, so a typo keeps the SECURE value — but it is still not the flag the operator set,
+ // and it is only meaningful alongside DATABASE_SSL above.
+ 'DATABASE_SSL_REJECT_UNAUTHORIZED',
+ // `!== 'false'`, so a typo keeps synchronize ON — and app.module.ts derives `migrationsRun` from
+ // its negation, so the main connection's migration ledger silently never advances for an operator
+ // who deliberately opted into migration-managed api_keys/audit_logs.
+ 'MAIN_DATABASE_SYNCHRONIZE',
+ // Read with `=== 'true'` by the plugin ingress gate: a typo turns an intentional
+ // `ALLOW_UNSIGNED_INGRESS=true` back off, and a route the operator meant to open stops loading.
+ 'ALLOW_UNSIGNED_INGRESS',
+ // `=== 'true'`; already refused outright in production, but a typo in development silently
+ // withholds the dev key the operator asked for.
+ 'ALLOW_DEV_API_KEY',
+ // `!== 'false'`: a typo keeps SSRF protection on (safe) or contact enrichment off — either way
+ // the webhook payload an integrator receives is not the one the operator configured.
+ 'WEBHOOK_SSRF_PROTECT',
+ 'WEBHOOK_CONTACT_DETAILS',
+ // Engine behaviour flags: a typo leaves full-history sync off, or leaves the account marked
+ // online on connect (#871 — it suppresses notifications on the operator's own phone).
+ 'BAILEYS_SYNC_FULL_HISTORY',
+ 'BAILEYS_MARK_ONLINE_ON_CONNECT',
+ // Read with `=== 'true'` by DockerService. A typo does not fail silently here — it voids the
+ // built-in-datastore credential exemption and the production boot refuses with a confusing
+ // complaint about DATABASE_PASSWORD instead of naming the real cause.
+ 'POSTGRES_BUILTIN',
+ 'REDIS_BUILTIN',
+ 'MINIO_BUILTIN',
+ // Perf/observability only, but same silent-typo class.
+ 'CACHE_ENABLED',
+ 'DATABASE_LOGGING',
+ // DELIBERATELY NOT LISTED. `MCP_READONLY` is read `!== 'false'` and mcp.server.spec.ts asserts
+ // that `yes` keeps it read-only — a tolerance the repo tests on purpose. `PUPPETEER_HEADLESS` is
+ // read `!== 'false'` and `new` is a real Puppeteer value that works today. Both fail toward the
+ // safe state, so strictness here would refuse working deployments to no benefit.
]) {
checkBool(key);
}