Security, performance and stability quick wins - #183
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Add ban enforcement on HTTP API routes (game, clans, pvp, payment) - Restrict JWT verification to HS256 algorithm (access, refresh, socket) - Differentiate dev JWT secrets for access vs refresh tokens - Enable Content Security Policy in Helmet with proper directives - Add per-IP rate limiting on PvP fights (20/min) - Add username character validation (letters, numbers, spaces, hyphens, underscores) - Whitelist settings keys to prevent storage bloat Performance: - Add compression middleware (gzip/brotli) - Add Cache-Control headers (1y immutable for hashed assets, 10m for shell) - Add missing DB indexes (User.updatedAt, Mission type+status, Purchase.stripePaymentId) - Parallelize loadActorAndTarget queries with Promise.all Stability: - Fix race condition in registration and username change (catch P2002 instead of check-then-act) - Remove competing shutdown handlers (prisma.js vs index.js) - Store and clear token cleanup interval on shutdown Functionality: - Update defender ELO in PvP (both players' ratings now change) - Emit COMBAT_MONSTER_DEFEATED event so defeat_enemies missions can progress Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xc2Hvgc65no84vRm33PUnt
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
Full codebase audit across security, performance, stability, and functionality — followed by implementation of the 16 highest-priority quick wins (high impact, low difficulty).
Security (7 fixes)
requireNotBannedmiddleware on game/clans/pvp/payment routesjwt.verify()now explicitly requiresHS256on all 3 verification points (access, refresh, socket) to prevent algorithm confusion attacks[A-Za-z0-9_\- ]to prevent impersonation ([ADMIN] System) and control charactersPUT /api/auth/settingsnow only accepts known keys (theme, language, sfx, music)Performance (4 fixes)
compressionmiddleware (gzip/brotli)max-age=1y, immutable; shell files get 10 minUser.updatedAt(PvP opponent pool),Mission(clanId, type, status),Purchase.stripePaymentId(refund lookup)loadActorAndTargetnow usesPromise.allinstead of sequential queriesStability (3 fixes)
prisma.jsthat raced withindex.jsshutdownFunctionality (2 fixes)
COMBAT_MONSTER_DEFEATEDevent was never emitted, making thedefeat_enemiesmission (target: 1500) impossible to completeTest plan
npm test)npm run lint)npm run build)Generated by Claude Code