Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(config): stop .env.example pinning the production Swagger opt-in

Yudhi Armyndharisbc836e942e4a
diff --git a/.env.example b/.env.example
index 7051d7c25..e291d9b7e 100644
--- a/.env.example
+++ b/.env.example
@@ -655,7 +655,12 @@ PLUGINS_DIR=./data/plugins # Plugin directory (default: ./data/plugins)
# =============================================================================
# DEVELOPER SETTINGS
# =============================================================================
-ENABLE_SWAGGER=true # Enable API documentation at /api/docs (set false to disable on exposed deployments)
+# ENABLE_SWAGGER=true # Serve the API docs + Swagger UI at /api/docs. Default: ON outside
+ # production, OFF under NODE_ENV=production. Left commented on purpose:
+ # this file ships NODE_ENV=production, so an uncommented value here would
+ # pin the opt-in the production default exists to withhold. The mount is
+ # not behind the API-key guard, so serving it exposes the schema and the
+ # exact running version to anyone who can reach the port.
# BODY_SIZE_LIMIT=25mb # Max request body size (base64 media sends ride in the JSON body)
# Aggregate cap on request-body bytes buffered across ALL connections. Once exceeded, new requests
# get 503 + Retry-After without their body being read (protects against slow-body memory pinning).
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6cec4930a..dd240fb60 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security
- An advisory usage-statistics write no longer persists the whole API-key row. A key deleted while a request that had already loaded it was in flight was re-inserted with its original hash and authenticated again; a revocation or a narrowing of role, allowlist, IP allowlist or expiry was likewise reverted to the values that request loaded. The write is now scoped to the two usage columns and affects nothing if the row is gone.
+- `.env.example` no longer ships `ENABLE_SWAGGER=true` uncommented: the template also declares `NODE_ENV=production`, so copying it pinned the opt-in that production withholds and served the schema and running version at `/api/docs`, which sits outside the API-key guard. Bare-metal operators who already copied it should check their own `.env`; Docker and Helm are unaffected.
## [0.15.0] - 2026-08-09
diff --git a/SECURITY.md b/SECURITY.md
index 0cb8d4d50..958b40b09 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -50,6 +50,13 @@ the README and `docs/` — in particular `CORS_ORIGINS`, `ALLOW_DEV_API_KEY`,
Never expose the dashboard/API to the public internet with the development API key
enabled.
+If you created your `.env` by copying `.env.example` before this advisory, check it for
+`ENABLE_SWAGGER=true`. Earlier templates shipped that line uncommented alongside
+`NODE_ENV=production`, so a copied file pinned the opt-in that production otherwise
+withholds, and `/api/docs` is served outside the API-key guard. Comment the line out or
+set it to `false` to restore the production default. Docker Compose and the Helm chart
+are unaffected — neither forwards `ENABLE_SWAGGER` and the container never reads `.env`.
+
### Docker socket proxy — scope and residual risk
The application container never mounts `/var/run/docker.sock`; it reaches the daemon
diff --git a/docs/08-development-guidelines.md b/docs/08-development-guidelines.md
index 2866ab083..348e7c481 100644
--- a/docs/08-development-guidelines.md
+++ b/docs/08-development-guidelines.md
@@ -698,7 +698,8 @@ SESSION_DATA_PATH=./data/sessions
ENGINE_TYPE=whatsapp-web.js
PUPPETEER_HEADLESS=true
-# Swagger is enabled by default. Set false to disable.
+# Swagger defaults ON outside production and OFF under NODE_ENV=production.
+# Set it explicitly to force either way.
ENABLE_SWAGGER=true
```
diff --git a/src/config/production-template-optin.spec.ts b/src/config/production-template-optin.spec.ts
new file mode 100644
index 000000000..ea170ba92
--- /dev/null
+++ b/src/config/production-template-optin.spec.ts
@@ -0,0 +1,75 @@
+import * as fs from 'fs';
+import * as path from 'path';
+import * as dotenv from 'dotenv';
+import { isSwaggerEnabled, isValidationErrorDetailEnabled } from './bootstrap-security';
+
+/**
+ * `.env.example` is both the "copy me" template and a self-described production config — it ships
+ * `NODE_ENV=production` uncommented. Anything else shipped uncommented becomes a PIN the moment an
+ * operator copies the file, so a setting that defaults OFF under production must not be pre-selected
+ * ON in the template: copying it would silently opt a production host into the very thing the
+ * default exists to withhold.
+ *
+ * This is deliberately BEHAVIOURAL rather than lexical. A lexical "KEY must not appear uncommented"
+ * rule mis-fires on settings shipped uncommented in the SAFE direction, and it cannot tell the two
+ * apart. Here the template is parsed and the REAL resolvers are run over it, so a key only counts
+ * when the template's own value resolves ON while the unset default would resolve OFF.
+ */
+
+/** Resolvers that default OFF under production and are forced ON by an explicit `true`. */
+const PRODUCTION_OFF_OPT_INS: ReadonlyArray<{
+ key: string;
+ resolve: (value: string | undefined, nodeEnv: string | undefined) => boolean;
+}> = [
+ { key: 'ENABLE_SWAGGER', resolve: isSwaggerEnabled },
+ { key: 'VALIDATION_ERROR_DETAIL', resolve: isValidationErrorDetailEnabled },
+];
+
+/**
+ * The production-off opt-ins a copied template would pre-select. Empty for a template that does not
+ * declare production — the rule is about what `cp .env.example .env` pins on a production host.
+ */
+function preSelectedOptIns(templateText: string): string[] {
+ const env = dotenv.parse(templateText);
+ if (env.NODE_ENV !== 'production') return [];
+ return PRODUCTION_OFF_OPT_INS.filter(
+ optIn => optIn.resolve(env[optIn.key], env.NODE_ENV) && !optIn.resolve(undefined, env.NODE_ENV),
+ ).map(optIn => optIn.key);
+}
+
+describe('.env.example does not pre-select a production-off opt-in', () => {
+ const templatePath = path.join(__dirname, '..', '..', '.env.example');
+ const template = fs.readFileSync(templatePath, 'utf8');
+
+ it('pre-selects nothing that production defaults off', () => {
+ expect(preSelectedOptIns(template)).toEqual([]);
+ });
+
+ it('still gives a developer the documented defaults when they set NODE_ENV=development', () => {
+ // The reason a bare removal is not the fix: shipping `ENABLE_SWAGGER=false` would also satisfy
+ // the assertion above while breaking the contributor workflow that copies this same file.
+ const env = dotenv.parse(template);
+ expect(isSwaggerEnabled(env.ENABLE_SWAGGER, 'development')).toBe(true);
+ expect(isValidationErrorDetailEnabled(env.VALIDATION_ERROR_DETAIL, 'development')).toBe(true);
+ });
+
+ it('leaves the documented production opt-in working when an operator sets it themselves', () => {
+ expect(isSwaggerEnabled('true', 'production')).toBe(true);
+ expect(isValidationErrorDetailEnabled('true', 'production')).toBe(true);
+ });
+
+ // Self-mutation controls: the check must be capable of firing, and must not fire on the safe cases.
+ it('fires when a production-off opt-in is shipped uncommented', () => {
+ expect(preSelectedOptIns(`${template}\nVALIDATION_ERROR_DETAIL=true\n`)).toEqual(['VALIDATION_ERROR_DETAIL']);
+ expect(preSelectedOptIns(`${template}\nENABLE_SWAGGER=true\n`)).toEqual(['ENABLE_SWAGGER']);
+ });
+
+ it('does not fire on a template that declares a non-production environment', () => {
+ const asDevelopment = `${template}\nNODE_ENV=development\nENABLE_SWAGGER=true\n`;
+ expect(preSelectedOptIns(asDevelopment)).toEqual([]);
+ });
+
+ it('does not fire on a setting shipped uncommented in the safe direction', () => {
+ expect(preSelectedOptIns(`${template}\nVALIDATION_ERROR_DETAIL=false\n`)).toEqual([]);
+ });
+});