fix: security, stability & performance quick wins - #179
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Remove competing shutdown handlers in prisma.js (was racing server/index.js graceful shutdown) - Add ban check to requireAuth middleware (banned users could still access HTTP API) - Add rate limiting to /api/auth/refresh endpoint - Enable Content Security Policy in production (helmet) - Pin JWT algorithm to HS256 on all verify calls - Translate French error messages to English in sprites routes Stability: - Add global error handlers (window.onerror, unhandledrejection) in frontend - Wrap startGame() in try/catch with user-friendly fallback - Add database connectivity check to /api/health endpoint - Centralize default game state in server/lib/defaults.js (fixes inconsistent starting gold: 0 vs 100) Performance: - Add missing database indexes (User.updatedAt, RefreshToken.expiresAt, Purchase.stripePaymentId) - Add Cache-Control header to monster templates endpoint DevEx: - Add lint step to CI pipeline - Remove unused shopState destructuring in game routes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EakBjb5ztr2j3csio31CG1
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
Quick-win fixes across security, stability, performance, and developer experience — all low-risk, high-impact changes identified during a full codebase audit.
Security
requireAuthnow checks ban status on every authenticated request./api/auth/refresh: the token refresh endpoint had no rate limiter (only the global 100/min), allowing faster token churn with a leaked refresh token.jwt.verifycalls now specify{ algorithms: ['HS256'] }to prevent algorithm confusion attacks.server/lib/prisma.jsregistered its own SIGINT/SIGTERM handlers that calledprocess.exit(0), racing the graceful shutdown inserver/index.jsand potentially preventing proper HTTP/socket draining.Stability
window.onerrorandunhandledrejectionlisteners so errors are logged instead of silently swallowed.startGame()wrapped in try/catch: a network error during init no longer leaves users on a blank screen — shows a user-friendly fallback message./api/healthnow runsSELECT 1against PostgreSQL, making it useful for load balancer health probes.gold: 0, but loading/saving created state withgold: 100. Centralized inserver/lib/defaults.js.Performance
User.updatedAt(PvP opponent query),RefreshToken.expiresAt(24h cleanup job),Purchase.stripePaymentId(refund webhook lookup)./api/monsters/templatesendpoint was the only template route missing theCache-Control: public, max-age=3600header.Developer Experience
npm run lint, letting lint violations slip intomain.shopStatedestructuring in game routes.sprites.jswere in French while the rest of the API is English.Test plan
npm test)npm run lint) — no new warningsnpm run build)/api/healthreturns 503 when DB is unreachable🤖 Generated with Claude Code
https://claude.ai/code/session_01EakBjb5ztr2j3csio31CG1
Generated by Claude Code