Skip to content

Security, stability, and performance quick wins - #194

Merged
Sparksx merged 1 commit into
mainfrom
claude/focused-curie-4qu1o8
Aug 1, 2026
Merged

Security, stability, and performance quick wins#194
Sparksx merged 1 commit into
mainfrom
claude/focused-curie-4qu1o8

Conversation

@Sparksx

@Sparksx Sparksx commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive codebase audit across security, stability, performance, and functionality — implementing the highest-priority quick wins (13 fixes across 12 files).

Security

  • Enable CSPcontentSecurityPolicy: false → proper directive set (scripts, styles, connect, frames)
  • Ban check on HTTP routes — bans previously only blocked socket connections; now all requireAuth routes reject banned users
  • Separate JWT dev secrets — access and refresh tokens shared the same default secret in dev mode
  • PvP rate limiting — 3 fights per 10 seconds to prevent Elo manipulation via scripted requests
  • Settings key whitelistPUT /api/auth/settings now rejects unknown keys instead of blindly merging
  • Server-side clan creation costCLAN_CREATE_COST (500g) moved to shared/ and enforced in a transaction; previously only checked client-side

Stability

  • Atomic clan leave — ownership transfer + member deletion wrapped in a single transaction (was a TOCTOU race)
  • Atomic refund clawback — payment webhook's gold deduction now runs inside one transaction (was a read-then-write race)
  • Remove duplicate shutdown handlerprisma.js had its own SIGTERM/SIGINT handlers that raced with server/index.js
  • Socket error boundarieschat:share-combat and chat:join handlers now have try/catch

Performance

  • Lightweight clan listingGET /api/clans now uses _count instead of loading full member game states (was fetching all equipment JSON for 25 clans × N members, unused in list view)
  • Cache-Control on packsGET /api/payment/packs returns static config data, now cached 1 hour

Frontend

  • Reliable tab-close save — uses keepalive: true on the unload fetch so the browser completes the request after page teardown

Test plan

  • All 524 existing tests pass
  • Build succeeds (npm run build)
  • Lint unchanged (53 warnings, 0 errors — no new issues)
  • Verify clan creation deducts 500g (manual test)
  • Verify banned user gets 403 on API routes (manual test)
  • Verify PvP rate limit triggers after 3 rapid fights

Generated by Claude Code

Security:
- Enable Content Security Policy (was disabled via contentSecurityPolicy: false)
- Add ban check to HTTP API middleware (bans previously only blocked sockets)
- Separate JWT access/refresh dev secrets (were identical)
- Rate-limit PvP fights (3 per 10s) to prevent Elo manipulation
- Whitelist settings keys to prevent arbitrary JSON injection
- Enforce clan creation gold cost server-side (was client-only)

Stability:
- Wrap clan leave + ownership transfer in a single transaction (race condition)
- Atomize refund gold clawback in payment webhook (read-then-write race)
- Remove duplicate SIGTERM/SIGINT handler from prisma.js (conflicts with server/index.js)
- Add error boundaries to unprotected socket event handlers
- Use keepalive: true on tab-close state save for reliable unload persistence

Performance:
- Clan listing no longer fetches full member data (only needs _count)
- Add Cache-Control header to payment packs endpoint (static data)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYVzzEyTHnYUKXfUAXCamQ
@Sparksx
Sparksx merged commit 0dd6e46 into main Aug 1, 2026
1 check passed
@Sparksx
Sparksx deleted the claude/focused-curie-4qu1o8 branch August 1, 2026 10:07
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