Security, stability, and performance quick wins - #194
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Comprehensive codebase audit across security, stability, performance, and functionality — implementing the highest-priority quick wins (13 fixes across 12 files).
Security
contentSecurityPolicy: false→ proper directive set (scripts, styles, connect, frames)requireAuthroutes reject banned usersPUT /api/auth/settingsnow rejects unknown keys instead of blindly mergingCLAN_CREATE_COST(500g) moved toshared/and enforced in a transaction; previously only checked client-sideStability
prisma.jshad its own SIGTERM/SIGINT handlers that raced withserver/index.jschat:share-combatandchat:joinhandlers now have try/catchPerformance
GET /api/clansnow uses_countinstead of loading full member game states (was fetching all equipment JSON for 25 clans × N members, unused in list view)GET /api/payment/packsreturns static config data, now cached 1 hourFrontend
keepalive: trueon the unload fetch so the browser completes the request after page teardownTest plan
npm run build)Generated by Claude Code