Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(docker): forward the inbound-media knobs through compose

Yudhi Armyndharis12a834e6ec0f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8c1283359..9e6ed745e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- Both compose files now forward the inbound-media knobs — `MEDIA_DOWNLOAD_ENABLED`, `MEDIA_DOWNLOAD_MAX_BYTES`, `MEDIA_DOWNLOAD_TIMEOUT_MS` and `INBOUND_MEDIA_CONCURRENCY`. None of the four reached the container, so an operator running the bundled stack who set `MEDIA_DOWNLOAD_ENABLED=false` in `.env` got no error and no log line while the gateway kept decrypting every inbound media blob and base64-inlining it into every message row at up to 50 MiB apiece. The cap and the timeout were equally unreachable. A gate now binds all four, in both files.
+
- `GET /api/metrics` no longer fails the whole scrape when the data database is unreachable. `render()` awaited a stats query unguarded, so a statement timeout, pool exhaustion, a `SQLITE_BUSY` under load or a genuine outage answered every scrape with a 500 once the 30-second stats memo lapsed — costing Prometheus the process, HTTP and webhook series too, and making `up` conflate a dead process with an unreachable database, during the exact incident the endpoint exists to describe. The database-derived series are now omitted rather than reported as zero (a zero would fire an alert claiming every session had dropped), and a new `openwa_stats_available` gauge says which of the two happened.
- An authorization denial now records WHICH credential was denied. Both post-authentication 403s — an insufficient role, and a session-scoped key on a route that forbids one — threw before the resolved key was stamped into the request context, so every such audit row carried `apiKeyId` and `apiKeyName` as null. Behind NAT or a reverse proxy without `TRUSTED_PROXIES` the recorded IP is common to every tenant, leaving an operator able to see that a key had been denied but not which one to revoke. The same stamp was added to the queue-dashboard mount, which has the same shape. A denial that happens before any key resolves is unchanged: the IP really is all there is.
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 0e2d1121c..42dcb7811 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -129,6 +129,10 @@ services:
- SEND_PACING_COLD_DAILY_CAP=${SEND_PACING_COLD_DAILY_CAP:-}
- SEND_PACING_BREAKER_THRESHOLD=${SEND_PACING_BREAKER_THRESHOLD:-}
- SEND_PACING_BREAKER_COOLDOWN_MS=${SEND_PACING_BREAKER_COOLDOWN_MS:-}
+ - MEDIA_DOWNLOAD_ENABLED=${MEDIA_DOWNLOAD_ENABLED:-}
+ - MEDIA_DOWNLOAD_MAX_BYTES=${MEDIA_DOWNLOAD_MAX_BYTES:-}
+ - MEDIA_DOWNLOAD_TIMEOUT_MS=${MEDIA_DOWNLOAD_TIMEOUT_MS:-}
+ - INBOUND_MEDIA_CONCURRENCY=${INBOUND_MEDIA_CONCURRENCY:-}
- MEDIA_CONVERSION_ENABLED=${MEDIA_CONVERSION_ENABLED:-}
- FFMPEG_PATH=${FFMPEG_PATH:-}
- MEDIA_CONVERSION_TIMEOUT_MS=${MEDIA_CONVERSION_TIMEOUT_MS:-}
diff --git a/docker-compose.yml b/docker-compose.yml
index 44ff79dc1..2bc200e07 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -205,6 +205,10 @@ services:
- SEND_PACING_BREAKER_COOLDOWN_MS=${SEND_PACING_BREAKER_COOLDOWN_MS:-}
# Server-side media conversion (opt-in). The image ships ffmpeg, but without these forwards
# the feature could not be switched on from .env at all.
+ - MEDIA_DOWNLOAD_ENABLED=${MEDIA_DOWNLOAD_ENABLED:-}
+ - MEDIA_DOWNLOAD_MAX_BYTES=${MEDIA_DOWNLOAD_MAX_BYTES:-}
+ - MEDIA_DOWNLOAD_TIMEOUT_MS=${MEDIA_DOWNLOAD_TIMEOUT_MS:-}
+ - INBOUND_MEDIA_CONCURRENCY=${INBOUND_MEDIA_CONCURRENCY:-}
- MEDIA_CONVERSION_ENABLED=${MEDIA_CONVERSION_ENABLED:-}
- FFMPEG_PATH=${FFMPEG_PATH:-}
- MEDIA_CONVERSION_TIMEOUT_MS=${MEDIA_CONVERSION_TIMEOUT_MS:-}
diff --git a/src/config/env-precedence.spec.ts b/src/config/env-precedence.spec.ts
index c27929857..885eb9e05 100644
--- a/src/config/env-precedence.spec.ts
+++ b/src/config/env-precedence.spec.ts
@@ -299,3 +299,34 @@ describe('every key the dashboard writes is commented out in .env.example', () =
expect(uncommented.filter(key => dashboardOwned().includes(key))).toEqual([]);
});
});
+
+/**
+ * The inbound-media knobs must reach the container.
+ *
+ * `MEDIA_DOWNLOAD_ENABLED` turns off what env.validation.ts itself calls "the most expensive
+ * behaviour the gateway has" — decrypting every inbound media blob and base64-inlining it into every
+ * message row at up to 50 MiB apiece. Neither compose file forwarded it, nor the cap, the timeout or
+ * the concurrency, so an operator running the bundled stack set the value in `.env`, saw no error and
+ * no log line, and kept paying for the behaviour. The only remaining path was hand-editing
+ * `data/.env.generated` inside the mounted volume, which `.env.example` does not mention for these
+ * keys. The sibling MEDIA_CONVERSION_* family was forwarded all along.
+ */
+describe.each(['docker-compose.yml', 'docker-compose.dev.yml'])('%s forwards the inbound-media knobs', file => {
+ const compose = (): string => fs.readFileSync(path.join(__dirname, '../..', file), 'utf8');
+
+ const forwards = (key: string): boolean => new RegExp(`^\\s*-\\s*${key}=`, 'm').test(compose());
+
+ // Guards the assertions below: a matcher that can never fire would pass them vacuously.
+ it('detects a key that IS forwarded', () => {
+ expect(forwards('MEDIA_CONVERSION_ENABLED')).toBe(true);
+ });
+
+ it.each([
+ 'MEDIA_DOWNLOAD_ENABLED',
+ 'MEDIA_DOWNLOAD_MAX_BYTES',
+ 'MEDIA_DOWNLOAD_TIMEOUT_MS',
+ 'INBOUND_MEDIA_CONCURRENCY',
+ ])('forwards %s', key => {
+ expect(forwards(key)).toBe(true);
+ });
+});
diff --git a/src/config/env-precedence.ts b/src/config/env-precedence.ts
index 84cc7aee7..6664d38e8 100644
--- a/src/config/env-precedence.ts
+++ b/src/config/env-precedence.ts
@@ -23,6 +23,13 @@
*/
export const BLANK_SHADOWED_ENV_KEYS: string[] = [
'ENGINE_TYPE',
+ // Inbound-media knobs. Not dashboard-managed, but every blank compose forward must be cleared or
+ // the empty value shadows .env / data/.env.generated — which is why the gate above requires an
+ // entry for each one.
+ 'MEDIA_DOWNLOAD_ENABLED',
+ 'MEDIA_DOWNLOAD_MAX_BYTES',
+ 'MEDIA_DOWNLOAD_TIMEOUT_MS',
+ 'INBOUND_MEDIA_CONCURRENCY',
// Database selection + connection details (#488)
'DATABASE_TYPE',
'DATABASE_HOST',