Security, performance, and stability quick wins - #177
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Add ban enforcement on HTTP API routes (banned users were only blocked from Socket.io, not REST endpoints) — critical fix - Enable Content Security Policy via helmet (was fully disabled) - Fix Stripe checkout redirect URLs: use server-configured CORS_ORIGIN instead of client-supplied Origin/Referer headers (anti-phishing) - Add rate limiting to the /refresh endpoint (was missing authLimiter) - Whitelist allowed keys in PUT /api/auth/settings to prevent arbitrary JSON storage - Use distinct JWT_SECRET and JWT_REFRESH_SECRET dev fallback values to prevent token confusion in development Performance: - Use lightweight include for clan listing (skip full member equipment JSON — was loading hundreds of KB of gear data for 25 clans) - Add Cache-Control headers to monster templates, sprites, and payment packs endpoints (static data, 1h TTL) - Add maxAge + etag to express.static for production asset caching - Parallelize socket ban check + role fetch (Promise.all instead of sequential queries, halving connection latency) Stability: - Store and clear setInterval handles (token cleanup, combat log cleanup) during graceful shutdown to prevent process hang - Remove duplicate Prisma SIGINT/SIGTERM handlers that could race with the main shutdown handler and bypass io.close()/server.close() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019E8KUzJGkSxnfmeDY8KPG8
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 Gear Master codebase across security, performance, stability, and functionality — followed by implementation of all high-priority quick wins (low effort, high impact).
Security fixes
banGuardmiddleware to all gameplay routes.contentSecurityPolicy: false, removing all browser-level XSS protection. Now sets a functional CSP allowing self, Stripe, Google, Discord, and necessary inline styles.success_url/cancel_urlwere built from client-suppliedOrigin/Refererheaders (phishing risk). Now uses server-configuredCORS_ORIGIN./refresh— was missing theauthLimiterapplied to all other auth endpoints.PUT /api/auth/settingsaccepted arbitrary JSON keys. Now only allows known keys (theme,language,sfx,music,notifications).JWT_SECRETandJWT_REFRESH_SECRETshared the same fallback value in development, enabling token confusion.Performance fixes
GET /api/clanswas loading full member equipment JSON (hundreds of KB) for all 25 clans when onlymemberCountis needed for the list view.express.staticnow setsmaxAge: '1d'+etag: truein production.Promise.allinstead of sequential queries.Stability fixes
setIntervalhandles for token cleanup (24h) and combat log cleanup (1h) are now stored and cleared during graceful shutdown.shutdown()function and bypassio.close()/server.close().Test plan
npm test)npm run lint)npm run build)🤖 Generated with Claude Code
https://claude.ai/code/session_019E8KUzJGkSxnfmeDY8KPG8
Generated by Claude Code