Harden server: compression, CSP, rate limits, gold guard, DB indexes#176
Open
Sparksx wants to merge 1 commit into
Open
Harden server: compression, CSP, rate limits, gold guard, DB indexes#176Sparksx wants to merge 1 commit into
Sparksx wants to merge 1 commit into
Conversation
… health check Security: - Enable Content-Security-Policy via Helmet (was disabled) with directives tailored to the game (Stripe, OAuth providers, WebSocket, inline styles) - Add gold guard on PUT /api/game/state: client can only decrease gold, never inflate it — server-granted gold (expeditions, Stripe) is protected - Add stricter rate limiters for payment (10/min) and save (30/min) endpoints Performance: - Add compression middleware (gzip) for all HTTP responses - Add DB indexes on ChatMessage.senderId, Purchase(userId+status), Purchase.stripePaymentId for faster lookups on growing tables Stability: - Remove competing SIGINT/SIGTERM handlers in prisma.js that raced with the graceful shutdown in index.js and called process.exit() prematurely - Upgrade /api/health to verify DB connectivity and report memory/uptime, so Railway detects a degraded backend instead of returning false-ok Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017fXA9zS9e4SASWZFKZnAmY
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 improvements from a full codebase audit across security, performance, stability, and functionality. These are the highest-impact, lowest-effort changes identified.
contentSecurityPolicy: false). Now active with directives tailored to the game (Stripe checkout, OAuth providers, WebSocket, inline styles).PUT /api/game/stateno longer allows the client to inflate gold. The server compares submitted gold against the DB and silently caps it, closing the main cheat vector.compressionmiddleware (gzip). All REST responses are now compressed (~60-70% size reduction on JSON payloads).ChatMessage.senderId,Purchase(userId, status), andPurchase.stripePaymentIdfor faster lookups on growing tables.prisma.jsthat raced with the graceful shutdown inindex.js, causing prematureprocess.exit()before HTTP connections drained./api/healthnow verifies DB connectivity and reports memory/uptime. Returns 503 when the database is unreachable, so Railway can detect a degraded backend.Test plan
npm test— 524 tests pass (no regressions)npm run build— production build succeedsnpm run lint— no new errors (only pre-existing warnings)Content-Encoding: gzip) on API responsesGenerated by Claude Code