Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

feat: enhance websocket security and documentation

RinCodeForge92786ff7f1ea26e
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