Skip to content

Security, stability & performance quick wins - #168

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

Security, stability & performance quick wins#168
Sparksx wants to merge 1 commit into
mainfrom
claude/focused-curie-hz848t

Conversation

@Sparksx

@Sparksx Sparksx commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive analysis of the game across 4 axes (security, stability, performance, functionality) followed by implementation of the highest-priority quick wins.

  • Security: Enable CSP in production, harden JWT verification with explicit algorithm, add socket rate limiting
  • Stability: Fix race conditions in clan leave and mission progress, fix event listener leak
  • Performance: Cache PvP leaderboard, fix dependency classification

Changes

Security

  • Enable Content-Security-Policy in production (server/index.js) — was fully disabled (contentSecurityPolicy: false), now enforces default-src 'self' with targeted exceptions for Stripe checkout and Google OAuth
  • Explicit JWT algorithm (server/middleware/auth.js, server/routes/auth.js) — all jwt.verify() calls now specify algorithms: ['HS256'] to prevent algorithm substitution attacks
  • Socket rate limiting (server/socket/chat.js) — added per-socket rate limits on chat:player-profile (10/10s) and chat:request-history (5/5s) to prevent abuse and information enumeration

Stability

  • Clan leave transaction (server/routes/clans.js) — member deletion + ownership transfer + clan disband now wrapped in a single interactive transaction (was sequential, risked leaderless clans on crash)
  • Mission progress race condition (server/routes/clans.js) — mission progress reporting now uses an interactive transaction with a fresh read of mission state, preventing concurrent requests from double-completing a mission and duplicating clan XP
  • Event listener leak (src/screens/home.js) — CHAT_UPDATED listener was added on every render() call without cleanup; now properly removes the previous listener before adding a new one

Performance

  • PvP leaderboard cache (server/routes/pvp.js) — 30-second in-memory cache, invalidated on rated fights. Eliminates redundant DB queries for mostly-static data
  • socket.io-client dependency (package.json) — moved from devDependencies to dependencies (correct classification for a runtime dependency)

Test plan

  • All 308 existing tests pass (npm test)
  • Zero lint errors (npm run lint)
  • Production build succeeds (npm run build)
  • Verify CSP doesn't block Stripe checkout or Google OAuth flows in production
  • Verify clan leave still works correctly (owner transfer, disband)
  • Verify mission progress reports correctly with concurrent clan members

🤖 Generated with Claude Code

https://claude.ai/code/session_018UFcpKe77wqjaqWHNPnaZz


Generated by Claude Code

Security:
- Enable Content-Security-Policy in production (was disabled)
- Add explicit algorithms: ['HS256'] to all jwt.verify() calls
- Add per-socket rate limiting on chat:player-profile and chat:request-history

Stability:
- Wrap clan leave + ownership transfer in a single interactive transaction
- Fix mission progress race condition using interactive transaction with
  fresh read (prevents double-completion and XP duplication)
- Fix event listener leak in home.js (CHAT_UPDATED added on every render
  without cleanup)

Performance:
- Cache PvP leaderboard for 30s (invalidated on rated fights)
- Move socket.io-client from devDependencies to dependencies

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018UFcpKe77wqjaqWHNPnaZz
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