Skip to content

All four WebSocket security and AI-trigger issues (#134, #136, #138, …#230

Merged
soomtochukwu merged 1 commit into
DXmakers:mainfrom
harystyleseze:main
May 30, 2026
Merged

All four WebSocket security and AI-trigger issues (#134, #136, #138, …#230
soomtochukwu merged 1 commit into
DXmakers:mainfrom
harystyleseze:main

Conversation

@harystyleseze
Copy link
Copy Markdown
Contributor

Summary

Resolves four audit findings in the agent WebSocket server.

Changes

#134 — Authorize userId ownership on WebSocket

Extracted validateUserId() (pure function) to reject empty/whitespace-only strings, strings over 128 chars, and
strings with ASCII control characters. Connection handler now returns 4000 for invalid userId and 4001 if that userId
already has an active session, preventing silent session overwrite.

#136 — Add WebSocket origin allowlist

Added ALLOWED_ORIGINS env variable (comma-separated, defaults to http://localhost:3000). NotificationServer now
accepts an allowedOrigins option and passes verifyClient to the underlying WebSocketServer. Non-browser clients
(no Origin header) are always accepted. Empty list = allow all (dev/test mode).

#138 — Send proactive messages only to target user

Removed the (notificationServer as unknown as {...}).clients type-unsafe cast and the broadcastMessage() call that
was sending one user's AI-generated financial data (balance, shortfall, contribution amounts) to every connected
client. Replaced with notificationServer.sendMessage(goal.userId, ...) using the now-public targeted send method.

#141 — Wire AI proactive trigger into monitoring loop

triggerProactiveMessage was defined but never called. The monitoring loop in startMonitoring() now accepts an
optional aiTrigger callback via NotificationServerOptions. When set, falling-behind goals receive an AI-generated
Gemini message instead of the built-in template. hasNotified is set before the async call to prevent re-entry on the
next 5-minute tick.

Test plan

  • npm run build passes with no TypeScript errors
  • npm run test — 65 tests across 7 suites, all pass
  • New websocket-server.test.ts covers validateUserId (13 cases) and isOriginAllowed (8 cases)
  • Updated env.test.ts covers parseAllowedOrigins (6 cases) and ALLOWED_ORIGINS in validateEnv

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@harystyleseze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@soomtochukwu soomtochukwu merged commit b6dd54a into DXmakers:main May 30, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants