Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): warn when the production CSP upgrade blanks a plain-HTTP dashboard (#731) (#768)
Yudhi Armyndharis9365b339ccab
diff --git a/.env.example b/.env.exampleindex f90474988..2ca60ce9a 100644--- a/.env.example+++ b/.env.example@@ -332,10 +332,15 @@ API_MASTER_KEY=# so re-issue keys after enabling. Leave unset to keep the current (unpeppered) behaviour.# API_KEY_PEPPER=+# Browsers auto-upgrade http:// to https:// for the dashboard (CSP upgrade-insecure-requests).+# On by default in production, which is correct behind a TLS-terminating reverse proxy.+# Set false when serving the dashboard over plain HTTP (e.g. a trusted private network, or a+# direct host:port deployment) — otherwise the browser upgrades the UI's own scripts to https,+# the non-TLS server can't answer, and the dashboard renders a BLANK WHITE SCREEN. (#611, #731)+# CSP_UPGRADE_INSECURE_REQUESTS=false+# =============================================================================# DEVELOPER SETTINGS# =============================================================================ENABLE_SWAGGER=true # Enable API documentation at /api/docs (set false to disable on exposed deployments)BODY_SIZE_LIMIT=25mb # Max request body size (base64 media sends ride in the JSON body)-# CSP_UPGRADE_INSECURE_REQUESTS=false # Set false for an HTTP-only deployment on a trusted private network- # (default: on in production). Stops the browser upgrading the dashboard to https.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bbab349b3..c39fc45b6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -171,6 +171,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0Where no request was made, no code is shown rather than a fabricated one. This is what made a plain`500` get reported as a mystery `400` in #750. Fixes #750.+- **A production boot that serves the dashboard over plain HTTP now warns about the CSP upgrade that+ blanks it.** In production OpenWA emits `upgrade-insecure-requests`, which is correct behind a+ TLS-terminating reverse proxy — the shipped `docker-compose.yml` topology — but silently breaks a+ direct-HTTP deployment: the browser upgrades the dashboard's own script fetches to `https://`, the+ non-TLS server cannot answer them, no JavaScript runs, and the UI renders a blank white screen. The+ failure happens entirely in the browser, so the server log stayed clean and the operator had nothing+ to go on; the existing `CSP_UPGRADE_INSECURE_REQUESTS=false` opt-out was documented only under+ `.env.example`'s "Developer settings" heading, where a production operator had no reason to look.+ Boot now names the setting when the trap is possible, `.env.example` documents it under Security with+ the symptom spelled out, and `docs/12-troubleshooting-faq.md` gains a "Dashboard renders a blank white+ screen" entry. The warning cannot distinguish direct HTTP from a TLS proxy at boot (Express+ `trust proxy` is off), so it fires for both and tells a proxied operator to ignore it. The CSP default+ is unchanged. (#731)+- **The startup banner now advertises `BASE_URL` instead of a hardcoded `localhost`.** The+ `🚀 running on`, `📚 Swagger docs`, and `🖥️ Dashboard` lines printed `http://localhost:${PORT}` as a+ literal, regardless of where the instance was actually reachable — contradicting the `AuthService`+ banner directly above them, which already honoured `BASE_URL`. Two adjacent log lines could therefore+ report different URLs for the same server, which read as "the UI is pinned to localhost" and sent #731+ chasing `BASE_URL`/`BIND_HOST`/`API_PORT` rather than the actual cause. (#731)+- **The dashboard now clears a message deleted for everyone while the thread is open (whatsapp-web.js).**`message.revoked` carries `revokedId` — the id of the original deleted message, which whatsapp-web.jsresolves separately from the event's own `id` — but the dashboard's WebSocket projection dropped thediff --git a/docs/12-troubleshooting-faq.md b/docs/12-troubleshooting-faq.mdindex dabcc9c31..0318d59c8 100644--- a/docs/12-troubleshooting-faq.md+++ b/docs/12-troubleshooting-faq.md@@ -156,6 +156,39 @@ docker compose pull # Get latest imagedocker compose up -d```+### Issue: Dashboard Renders a Blank White Screen++**Symptoms:**+- The API is healthy (`curl http://<host>:2785/api/health` returns `200`) but the dashboard is blank+- The startup log says `🖥️ Dashboard: serving bundled UI at …` — the UI *is* being served+- The browser console shows script-loading errors; DevTools → Network shows the `/assets/*.js`+ requests going to `https://` even though you opened the page over `http://`+- You reach the instance directly over plain HTTP (a host:port allocation, a private network, a+ panel like Pterodactyl) rather than through a TLS-terminating reverse proxy++**Cause:** In production OpenWA sends the CSP `upgrade-insecure-requests` directive, which tells the+browser to upgrade every sub-resource fetch to HTTPS. That is correct behind a TLS proxy. Over plain+HTTP the browser upgrades the dashboard's own script requests to `https://`, the non-TLS server+cannot answer them, no JavaScript runs, and React never mounts — a blank page. The failure happens+in the browser, so the server log stays clean.++**Solution:**++```bash+# Opt out, then fully restart the container (not just reload)+CSP_UPGRADE_INSECURE_REQUESTS=false++# Confirm it actually reached the process+docker compose exec openwa printenv NODE_ENV CSP_UPGRADE_INSECURE_REQUESTS+```++A production boot that serves the dashboard with the opt-out unset prints a warning naming this+setting. If you are behind a TLS proxy, ignore that warning — the directive is doing its job.++> The alternative is to front OpenWA with a TLS-terminating reverse proxy (the shipped+> `docker-compose.yml` topology), which serves the dashboard over HTTPS and makes the upgrade a+> no-op.+### Issue: Session Won't Connect**Symptoms:**diff --git a/src/config/bootstrap-security.spec.ts b/src/config/bootstrap-security.spec.tsindex d70506c31..ce7540450 100644--- a/src/config/bootstrap-security.spec.ts+++ b/src/config/bootstrap-security.spec.ts@@ -3,6 +3,7 @@ import {isSwaggerEnabled,isValidationErrorDetailEnabled,isUpgradeInsecureRequestsEnabled,+ isDashboardCspUpgradeTrapLikely,resolveBodyLimit,assertNoDefaultSecretsInProduction,isApiKeyPepperMissingInProduction,@@ -64,6 +65,23 @@ describe('isUpgradeInsecureRequestsEnabled', () => {});});+describe('isDashboardCspUpgradeTrapLikely', () => {+ it('flags a production instance serving the dashboard with the opt-out unset (#731)', () => {+ expect(isDashboardCspUpgradeTrapLikely({ nodeEnv: 'production', dashboardServed: true })).toBe(true);+ });+ it('stays quiet once the operator opts out', () => {+ expect(isDashboardCspUpgradeTrapLikely({ nodeEnv: 'production', cspEnv: 'false', dashboardServed: true })).toBe(+ false,+ );+ });+ it('stays quiet when no dashboard is served (API-only: no UI to break)', () => {+ expect(isDashboardCspUpgradeTrapLikely({ nodeEnv: 'production', dashboardServed: false })).toBe(false);+ });+ it('stays quiet outside production, where the directive is already off', () => {+ expect(isDashboardCspUpgradeTrapLikely({ nodeEnv: 'development', dashboardServed: true })).toBe(false);+ });+});+describe('isSwaggerEnabled', () => {it('is on by default (unset)', () => {expect(isSwaggerEnabled(undefined)).toBe(true);diff --git a/src/config/bootstrap-security.ts b/src/config/bootstrap-security.tsindex 87daaa130..14b743be0 100644--- a/src/config/bootstrap-security.ts+++ b/src/config/bootstrap-security.ts@@ -70,6 +70,24 @@ export function isUpgradeInsecureRequestsEnabled(cspEnv?: string, nodeEnv?: strireturn nodeEnv === 'production';}+/**+ * Whether a boot is likely walking into the #731 blank-dashboard trap: production serves the bundled+ * UI with `upgrade-insecure-requests` on, so a browser reaching it over plain HTTP silently upgrades+ * the UI's own script fetches to https:// and renders a blank page. The server never sees the failed+ * request (it dies in the browser), so a boot warning is the only pointer we can give.+ *+ * This cannot distinguish direct-HTTP (broken) from behind-a-TLS-proxy (correct) — Express `trust+ * proxy` is off, so at boot there is no signal either way. It deliberately fires for both; the+ * warning text tells a proxied operator to ignore it.+ */+export function isDashboardCspUpgradeTrapLikely(env: {+ nodeEnv?: string;+ cspEnv?: string;+ dashboardServed: boolean;+}): boolean {+ return env.dashboardServed && isUpgradeInsecureRequestsEnabled(env.cspEnv, env.nodeEnv);+}+/*** Request body-size cap (DoS hardening). Default is media-aware (base64 sends ride in the JSON body).* A value the body-size parser can't understand (e.g. 'unlimited', 'none', a typo) resolves to a nulldiff --git a/src/main.ts b/src/main.tsindex 438a1da38..165477057 100644--- a/src/main.ts+++ b/src/main.ts@@ -19,6 +19,7 @@ import {isSwaggerEnabled,isValidationErrorDetailEnabled,isUpgradeInsecureRequestsEnabled,+ isDashboardCspUpgradeTrapLikely,resolveBodyLimit,assertNoDefaultSecretsInProduction,isApiKeyPepperMissingInProduction,@@ -259,9 +260,14 @@ async function bootstrap() {const port = process.env.PORT || 2785;await app.listen(port);- console.log(`🚀 OpenWA is running on: http://localhost:${port}`);+ // Advertise the configured public URL, matching the AuthService banner (auth.service.ts). A bare+ // `localhost` literal here contradicted that banner and read as "the UI is pinned to localhost",+ // sending #731 chasing BASE_URL/BIND_HOST/API_PORT instead of the real cause.+ const publicUrl = process.env.BASE_URL || `http://localhost:${port}`;++ console.log(`🚀 OpenWA is running on: ${publicUrl}`);if (swaggerEnabled) {- console.log(`📚 Swagger docs: http://localhost:${port}/api/docs`);+ console.log(`📚 Swagger docs: ${publicUrl}/api/docs`);}// Make the dashboard-serving outcome explicit so a missing build (no UI on `/`)@@ -269,13 +275,32 @@ async function bootstrap() {if (!dashboardServingEnabled) {console.log('🖥️ Dashboard: serving disabled (SERVE_DASHBOARD=false); API only');} else if (dashboardBuildPresent) {- console.log(`🖥️ Dashboard: serving bundled UI at http://localhost:${port}`);+ console.log(`🖥️ Dashboard: serving bundled UI at ${publicUrl}`);} else {console.warn(`⚠️ Dashboard: no build at ${DASHBOARD_DIST} - UI disabled (API still serves /api). ` +'Run `npm run build:all` to bundle it, or use the Vite dev server (`npm run dev`).',);}++ // The upgrade-insecure-requests trap (#731): the browser upgrades the UI's own script fetches to+ // https and a non-TLS server can't answer them, so the dashboard renders blank with nothing in the+ // server log. We can't tell a TLS proxy from direct HTTP at boot (`trust proxy` is off), so this+ // fires for both and the text says who should ignore it.+ if (+ isDashboardCspUpgradeTrapLikely({+ nodeEnv: process.env.NODE_ENV,+ cspEnv: process.env.CSP_UPGRADE_INSECURE_REQUESTS,+ dashboardServed: dashboardServingEnabled && dashboardBuildPresent,+ })+ ) {+ console.warn(+ '⚠️ Dashboard: CSP upgrade-insecure-requests is ON (production default). If this instance is ' ++ "reached over plain HTTP, the browser will upgrade the UI's scripts to https:// and the " ++ 'dashboard will render blank. Behind a TLS proxy? Ignore this. Serving direct HTTP? Set ' ++ 'CSP_UPGRADE_INSECURE_REQUESTS=false.',+ );+ }}void bootstrap();