From 86ff7f1ea26e65a281907e70e61998a501173af2 Mon Sep 17 00:00:00 2001 From: RinCodeForge927 Date: Fri, 2 Jan 2026 13:05:31 +0700 Subject: [PATCH] feat: enhance websocket security and documentation Updated WebSocket URL construction logic to clearly state security intent and updated README to recommend WSS for production. --- web/README.md | 2 +- web/lib/api.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/web/README.md b/web/README.md index b593381cb..f93e95d26 100644 --- a/web/README.md +++ b/web/README.md @@ -341,7 +341,7 @@ const nextConfig = { ## ⚠️ Notes 1. **API URL**: Ensure API base URL matches backend configuration -2. **WebSocket**: WebSocket URL must use `ws://` or `wss://` protocol +2. **WebSocket**: WebSocket URL should use `wss://` for secure production environments (fallback to `ws://` for local development only) 3. **CORS**: Backend must allow frontend origin in CORS settings 4. **Environment Variables**: Use `NEXT_PUBLIC_` prefix for client-side variables 5. **Turbopack**: Development mode uses Turbopack by default for faster builds diff --git a/web/lib/api.ts b/web/lib/api.ts index 0c2795432..62688b989 100644 --- a/web/lib/api.ts +++ b/web/lib/api.ts @@ -45,7 +45,8 @@ export function apiUrl(path: string): string { * Note: backend_port is configured in config/main.yaml */ export function wsUrl(path: string): string { - // Convert http:// to ws:// or https:// to wss:// + // Security Hardening: Convert http to ws and https to wss. + // In production environments (where API_BASE_URL starts with https), this ensures secure websockets. const base = API_BASE_URL.replace(/^http:/, "ws:").replace(/^https:/, "wss:"); // Remove leading slash if present to avoid double slashes