Fix security, stability, and performance quick wins - #191
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Server-side gold validation: reject suspiciously large client gold increases (>500 delta) - Rate-limit the /api/auth/refresh endpoint to prevent abuse - Make username change atomic (use P2002 catch instead of check-then-act) Stability: - Remove competing SIGTERM handler in prisma.js (server/index.js already handles shutdown) - Guard against null user after OAuth retry exhaustion (Discord & Google) - Add try/catch to chat:share-combat socket handler (was unhandled rejection) - Fix event listener accumulation in home screen (off before on) - Health check now verifies DB connectivity (returns 503 if unreachable) Performance: - Add Cache-Control headers to monster templates, sprites, and payment packs endpoints - Set long-term immutable caching for Vite hashed assets, 1h for other static files - Add missing DB indexes: User.isGuest, Clan.ownerId, Purchase.stripePaymentId Observability: - Emit SAVE_FAILED event + show user toast when server save fails Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MFGbMG4n9XhxzVZyyxmMye
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 security, stability, performance, and functionality. This PR implements the highest-priority quick wins (low difficulty, high impact).
Security
PUT /api/game/stateendpoint now rejects client gold increases exceeding 500 above the server-known balance, logging anomalies. Prevents players from setting arbitrary gold via modified clients./api/auth/refreshnow uses the sameauthLimiteras login/register (5 req/min), preventing brute-force token rotation.POST /api/auth/change-username— now relies on the DB unique constraint and catchesP2002directly.Stability
server/lib/prisma.jshad its ownSIGTERM/SIGINThandler that could callprocess.exit(0)beforeserver/index.jsfinishes draining HTTP connections. Removed the duplicate.null.id.chat:share-combat: The socket handler had no error handling — an asyncresolveChannelfailure became an unhandled rejection. Now caught and reported to the client.home.jsregistered aCHAT_UPDATEDlistener on everyrender()call without removing the old one. Now doesoffbeforeon./api/healthnow runsSELECT 1and returns 503 if the database is unreachable, so Railway won't route traffic to a node with a dead DB.Performance
public, max-age=3600to monster templates, sprites, and payment packs endpoints (matching the existing equipment/player template endpoints)./assets/*) now served withmax-age=30d, immutable; other static files getmax-age=1h.User.isGuest,Clan.ownerId, and a unique constraint onPurchase.stripePaymentId(used by refund webhook lookups).Observability
SAVE_FAILEDevent now fires and shows a user-facing toast ("Progress save failed — retrying…") instead of silently logging to console.Test plan
npm test)npm run lint)npm run build)Generated by Claude Code