Skip to content

Fix stability, security, and performance quick wins#158

Open
Sparksx wants to merge 1 commit into
mainfrom
claude/focused-curie-sx86gy
Open

Fix stability, security, and performance quick wins#158
Sparksx wants to merge 1 commit into
mainfrom
claude/focused-curie-sx86gy

Conversation

@Sparksx

@Sparksx Sparksx commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive codebase audit identified 23 improvements across security, stability, performance, and functionality. This PR implements the 10 highest-priority quick wins — high impact, low risk, minimal code change.

Stability fixes

  • Remove duplicate SIGTERM/SIGINT handlersprisma.js and index.js both registered shutdown handlers, causing a race where prisma.js called process.exit(0) before index.js could flush Socket.io connections and close the HTTP server cleanly
  • Wrap clan rank management in transactions — promote/demote/kick loaded the actor and target outside a transaction, then mutated; a concurrent request could change roles between the permission check and the update, enabling privilege escalation
  • Validate expedition reward values — guard against NaN/negative rewardXp/rewardGold from data corruption; early-return when no members joined
  • Catch token cleanup interval errorssetInterval(asyncFn) silently dropped rejections, potentially leaking memory

Security fixes

  • Enable Content Security Policy in production (was contentSecurityPolicy: false) — defense-in-depth against XSS
  • Fix open redirect in payment checkoutreq.headers.origin was used raw to build Stripe success/cancel URLs; now validated against an explicit allowlist

Performance fixes

  • Optimize clan listing query/api/clans loaded every member's full gameState for all 25 clans just to show a list; now uses _count only (members are loaded on detail view)
  • Add composite index Expedition(status, endsAt) for the lazy-resolution timer query
  • Raise Socket.io compression threshold from 1KB to 4KB — most chat messages are <1KB, so compression was wasting CPU

Minor fixes

  • Null-safe chat serialization — deleted users caused username: undefined crash in conversation member list

Test plan

  • All 308 existing tests pass (npm test)
  • Lint passes with no new warnings (npm run lint)
  • Production build succeeds (npm run build)
  • Verify CSP doesn't block legitimate resources (Stripe checkout, WebSocket, inline styles)
  • Test clan promote/demote/kick still works correctly
  • Verify payment checkout redirects to correct origin

Remaining items from audit (not in this PR)

Priority Issue
Medium Stricter rate limiting on payment endpoints
Medium Profile picture whitelist validation
Medium PvP opponent pool query optimization
Medium Chat history sender data over-fetching
Medium i18n — extract ~40 hardcoded UI strings
Medium Vite code splitting (admin, dungeon, chat)
High Accessibility — ARIA attributes + keyboard navigation

🤖 Generated with Claude Code

https://claude.ai/code/session_01DoxYEXoRR2mhPGwqJd7Wdj


Generated by Claude Code

- Remove duplicate SIGTERM/SIGINT handlers (prisma.js vs index.js race)
- Enable Content Security Policy headers in production
- Fix open redirect in payment checkout (validate origin against whitelist)
- Wrap clan rank management (promote/demote/kick) in transactions to prevent
  race conditions that could allow privilege escalation
- Validate expedition reward values before distributing (guard NaN/negative)
- Early-return on empty expedition members to avoid wasted DB operations
- Optimize clan listing endpoint: use _count instead of loading all members
- Add composite index on Expedition(status, endsAt) for timer queries
- Fix chat crash on deleted users (null-safe serialization)
- Raise Socket.io compression threshold from 1KB to 4KB (reduce CPU on small messages)
- Catch unhandled promise rejection in token cleanup interval

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DoxYEXoRR2mhPGwqJd7Wdj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants