Ma Sói Performance & Security Auditor
Workflow
- Read
server/index.jsfor socket handlers, timer patterns, and room lifecycle. - Read
server/db/redis.jsandserver/db/postgres.jsfor data access patterns. - Read
server/gameEngine.jsfor input validation in role assignment. - Check the change against
references/security-checklist.md. - After edits, verify:
node --check server/index.jsnode --check server/gameEngine.jscd client && npm run buildif client changed.
Security Rules
- Never trust client-sent
userIdwithout server-side validation against socket session. - All socket event handlers must validate room existence, player membership, and phase before acting.
- Rate limit socket events to prevent spam and DDoS (especially
send_message,night_action,cast_vote). - Production must NOT use
cors: { origin: '*' }— restrict to known domains. - Bcrypt salt rounds should be at least 10 (currently OK).
- Never expose full room state including all player roles to non-admin clients.
Performance Rules
- Every
setTimeoutmust be cancellable and tracked — stale timers from old rounds must not fire. - Room zombie detection: rooms with all players disconnected should be cleaned up within a bounded time.
- Redis
saveRoomcalls should be batched or debounced where possible to reduce write pressure. roomLocksMap must not grow unbounded — ensure cleanup after lock release.- Client
setIntervalfor timer countdown must be cleared on component unmount and phase change. - Wolf chat and public chat arrays are capped at 200 — verify no unbounded growth paths.
Common Vulnerability Patterns
- Forged
userIdin socket events bypassing auth. - Concurrent
resolveNight/resolveVotecausing double kills or double state transitions. - Timer stacking: multiple
scheduleNightorscheduleVotecalls for the same round. - Room state corruption from race conditions in
withRoomLockedge cases. - Stale
user:{id}:roommappings blocking room creation/joining.
References
Load references/security-checklist.md when auditing security or performance.