Harden security, stability, and performance (quick wins) - #174
Open
Sparksx wants to merge 1 commit into
Open
Conversation
Security: - Cap gold increases per save to prevent client-side gold injection (anti-cheat) - Drop dead currency fields (diamonds/essence/skills/research) from state save - Enable Content Security Policy via helmet - Add dedicated rate limiter on payment endpoints (5/min) - Wrap creditPurchase and refund clawback in transactions (atomicity) Stability: - Wrap clan leave + ownership transfer in an interactive transaction - Use transactional read-compute-write for admin gold/essence/diamond edits - Remove duplicate SIGTERM/SIGINT handlers from prisma.js (index.js owns shutdown) - Use fetch keepalive for beforeunload save flush (survives page teardown) Performance: - Use lightweight include (member count only) for clan list endpoint Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AKMRqzDdMm76d4zHUNhFn5
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-stack analysis of the game across security, stability, performance, and functionality — followed by implementation of the highest-priority quick wins (high impact, low risk).
Security
PUT /api/game/stateendpoint was fully client-authoritative for gold. A player could send{ gold: 999999 }and bypass Stripe purchases entirely. Now rejects gold increases exceeding 500 per save (legitimate boss/forge rewards are tiny: 10–50g).diamonds,essence,skills,research,shopStatefrom the state save endpoint. These are dormant systems that were needlessly exposed.contentSecurityPolicy: false). Now configured with proper directives allowing Google/Stripe/Discord integrations while blocking XSS payloads./create-checkout-sessionand/confirmto prevent Stripe API abuse.creditPurchaseand the refund clawback now run inside$transactionblocks, preventing race conditions where gold could be double-credited or the clawback could be overwritten by a concurrent client save.Stability
prisma.jsandindex.jsboth registered SIGTERM/SIGINT handlers that raced each other. Removed the prisma.js handlers;index.jsowns the full shutdown sequence.beforeunloadsave used barefetch()which browsers may kill before completion. Now usesfetchwithkeepalive: truefor reliable delivery.Performance
GET /api/clanswas loading full member rosters (equipment JSON, player data) for all 25 clans. Now fetches only_count.members, reducing payload from potentially 1MB+ to a few KB.Test plan
npm test)npm run lint)npm run build)🤖 Generated with Claude Code
https://claude.ai/code/session_01AKMRqzDdMm76d4zHUNhFn5
Generated by Claude Code