Security, performance & stability quick wins - #170
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Enable Content Security Policy (was disabled) with proper directives for Google/Discord OAuth, Stripe, and WebSocket connections - Use distinct JWT secret fallbacks in dev (access vs refresh were identical) - Add ban check to REST API middleware (was only on Socket.io) - Rate-limit /api/auth/refresh endpoint (was unprotected) - Whitelist allowed keys in PUT /api/auth/settings (prevented arbitrary key injection) - Wrap refund gold clawback in a Prisma transaction (was a non-atomic read-modify-write) Performance: - Add HTTP response compression middleware (compression package) - Fix N+1 query: clan list no longer fetches all members+gameState, uses lightweight include - Add immutable cache headers for hashed /assets/ (1 year max-age) - Add database indexes: User.updatedAt (PvP matchmaking), Purchase.stripePaymentId (refund lookup) - Fix 18 npm audit vulnerabilities (0 remaining) Stability: - Wrap clan leave in a single transaction (was split across multiple queries, race condition) - Remove competing SIGTERM/SIGINT handler in prisma.js (raced with server/index.js shutdown) - Remove dead shopState destructuring from game state save route Misc: - Fix admin panel forge level prompt showing "1-12" instead of dynamic MAX_FORGE_LEVEL (35) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PHyAxehXQVsp2JoJTvdjAj
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 analysis of the codebase across 4 axes (security, performance, stability, functionality) followed by implementation of the highest-priority quick wins — changes with high impact and low risk.
Changes
Security (6 fixes)
contentSecurityPolicy: false); now configured with proper directives for Google/Discord OAuth, Stripe checkout, and WebSocket connectionsrequireAuthmiddleware now checks active bans on all authenticated API routes/api/auth/refresh— endpoint was unprotected, allowing rapid token rotation with a stolen refresh token; now uses the sameauthLimiteras login/registerPUT /api/auth/settingsaccepted arbitrary keys (prototype pollution vector); now rejects unknown keys$transactionPerformance (5 fixes)
compressionmiddleware; JSON responses compress 70-90% (clan listings, PvP fight logs, chat history)GET /api/clanswas loading all members + their full gameState for every clan in the list, then discarding it; now uses a lightweight_count-only include/assets/files now served withmax-age=1y, immutableheadersUser.updatedAt(PvP matchmaking ORDER BY) andPurchase.stripePaymentId(refund webhook lookup)Stability (3 fixes)
$transactionSIGTERM/SIGINThandler inprisma.jsthat could callprocess.exit(0)before the HTTP server finished draining in-flight requestsshopStatedestructuring from game state save routeMisc
MAX_FORGE_LEVEL(35)Test plan
npm test— 308 tests passingnpm run lint— 0 errors (only pre-existing warnings)npm run build— builds successfully🤖 Generated with Claude Code
https://claude.ai/code/session_01PHyAxehXQVsp2JoJTvdjAj
Generated by Claude Code