Security, stability and performance quick wins#169
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Enable CSP headers (was disabled) with Stripe/Google/Discord/WS allowlist - Enforce ban check on all login paths (password, Discord, Google OAuth) - Add rate limiter on game state save endpoint (30 req/min) - Validate username format (alphanumeric, underscore, hyphen only) - Use distinct JWT_SECRET and JWT_REFRESH_SECRET defaults in dev - Validate settings payload size (max 20 keys, 200 char values) Stability: - Remove competing SIGINT/SIGTERM handlers from prisma.js (index.js handles shutdown) - Clear cleanup intervals on graceful shutdown - Export combat log cleanup interval for shutdown cleanup - Health check now verifies database connectivity Performance: - Batch expedition member gold/XP updates (was N individual queries per member) - Use atomic PvP rating increment instead of direct set (prevents concurrent race) - Add missing database index on ChatMessage.senderId - Add Cache-Control header on monster templates endpoint Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0181r4N9n3YMSMMPWbkDGSNo
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 audit of the game across security, stability, performance, and functionality — implementing all high-priority quick wins (low difficulty, high impact).
Security fixes
contentSecurityPolicy: false), now enforces a real policy allowing Stripe, Google, Discord, and WebSocket originsPUT /api/game/stateto prevent abuse[a-zA-Z0-9_-]on register and change-username (was only length-checked)JWT_SECRETandJWT_REFRESH_SECREThad identical defaults, making access/refresh tokens interchangeableStability fixes
prisma.jshad its own SIGINT/SIGTERM handlers that raced with the mainshutdown()inindex.js, potentially exiting before the HTTP server drained/api/healthnow runsSELECT 1so load balancers detect database outagesPerformance fixes
updateManycalls per member; now uses 2 bulk operations regardless of party sizepvpRatingwas set directly (losing concurrent updates); now uses{ increment: ratingChange }for safe concurrent fightsChatMessage.senderIdindex for admin profile lookupsmax-age=3600(was missing, unlike equipment/player templates)Full audit results (not implemented — for future work)
Security (remaining)
PUT /api/game/stateaccepts any gold valuePerformance (remaining)
save()calls (4+ per game tick during active play)Stability (remaining)
Functionality (remaining)
Test plan
/api/healthreturns 503 when DB is down🤖 Generated with Claude Code
https://claude.ai/code/session_0181r4N9n3YMSMMPWbkDGSNo
Generated by Claude Code