Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): warn when VITE_WS_URL is a remote ws:// URL
Yudhi Armyndharis123f0c6fe044
diff --git a/dashboard/src/utils/urlSecurity.test.ts b/dashboard/src/utils/urlSecurity.test.tsindex 396f414b9..7e7f36430 100644--- a/dashboard/src/utils/urlSecurity.test.ts+++ b/dashboard/src/utils/urlSecurity.test.ts@@ -53,6 +53,23 @@ test('warnIfInsecureHttpUrl is silent on https', () => {assert.equal(warns.length, 0);});+// VITE_WS_URL naturally takes a ws:// value, and the socket sends the same API key over it.+test('warnIfInsecureHttpUrl warns on non-localhost ws and names the scheme', () => {+ const warns: string[] = [];+ const original = console.warn;+ console.warn = (msg: string) => warns.push(msg);+ try {+ warnIfInsecureHttpUrl('ws://gateway.example.com:2785', 'VITE_WS_URL');+ warnIfInsecureHttpUrl('ws://localhost:2785', 'VITE_WS_URL');+ warnIfInsecureHttpUrl('wss://gateway.example.com:2785', 'VITE_WS_URL');+ } finally {+ console.warn = original;+ }+ assert.equal(warns.length, 1);+ assert.match(warns[0]!, /insecure ws:\/\//);+ assert.match(warns[0]!, /gateway\.example\.com/);+});+test('warnIfInsecureHttpUrl returns the URL unchanged (does not throw)', () => {assert.equal(warnIfInsecureHttpUrl('http://gateway.example.com', 'x'), 'http://gateway.example.com');});diff --git a/dashboard/src/utils/urlSecurity.ts b/dashboard/src/utils/urlSecurity.tsindex 137620abd..d342205c2 100644--- a/dashboard/src/utils/urlSecurity.ts+++ b/dashboard/src/utils/urlSecurity.ts@@ -6,18 +6,19 @@ export function isLocalhostHost(hostname: string): boolean {}/**- * Warn (NOT throw) when a URL is `http://` and the host is not localhost. Sending API keys over- * plaintext http to a non-local host exposes credentials on the wire; warning instead of refusing+ * Warn (NOT throw) when a URL is `http://` or `ws://` and the host is not localhost. Sending API keys+ * over plaintext to a non-local host exposes credentials on the wire; warning instead of refusing* keeps local dev and TLS-terminating-proxy setups working. Returns the original URL unchanged so* the caller can chain.*/export function warnIfInsecureHttpUrl(url: string, label: string): string {try {const parsed = new URL(url);- if (parsed.protocol === 'http:' && !isLocalhostHost(parsed.hostname)) {+ if ((parsed.protocol === 'http:' || parsed.protocol === 'ws:') && !isLocalhostHost(parsed.hostname)) {+ const scheme = parsed.protocol.slice(0, -1);console.warn(- `[OpenWA] ${label} uses an insecure http:// URL (host: ${parsed.hostname}). ` +- 'API keys are sent in cleartext over http. Use https:// in production.',+ `[OpenWA] ${label} uses an insecure ${scheme}:// URL (host: ${parsed.hostname}). ` ++ `API keys are sent in cleartext over ${scheme}. Use https:// or wss:// in production.`,);}} catch {