Skip to content

Fix critical security, stability, and performance quick wins#167

Open
Sparksx wants to merge 1 commit into
mainfrom
claude/focused-curie-yrvkyy
Open

Fix critical security, stability, and performance quick wins#167
Sparksx wants to merge 1 commit into
mainfrom
claude/focused-curie-yrvkyy

Conversation

@Sparksx

@Sparksx Sparksx commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Comprehensive codebase audit across security, stability, performance, and functionality — this PR implements the highest-priority quick wins (high impact, low difficulty).

Security

  • Refund webhook silent failurecharge.refunded webhook now returns 500 on DB error instead of 200, so Stripe retries instead of assuming success (prevents gold leakage)
  • Open redirect via Stripe URLs — success/cancel URLs validated against allowed origins whitelist instead of trusting raw Origin/Referer headers

Stability

  • Save loss on tab closebeforeunload flush now uses navigator.sendBeacon() for guaranteed delivery (+ new /api/game/state/beacon endpoint)
  • Clan leave race condition — ownership transfer + member delete wrapped in a single interactive transaction
  • Mission progress double-completion — progress check re-reads current value inside transaction to prevent concurrent completeMission() calls
  • Expedition resolution crash — per-expedition try/catch so one failed resolution doesn't crash the entire handler
  • Chat history hang — emits error response on DB failure instead of leaving client waiting forever
  • Negative expedition rewards — clamp xpGain/goldPot to Math.max(0, ...)

Performance

  • HTTP compression — added compression middleware for gzip responses on all API payloads
  • Mission contribution over-fetchcontributions query limited to take: 3 + orderBy: desc at DB level (was fetching all, sorting in JS, slicing to 3)
  • Missing indexesChatMessage.senderId and User.createdAt for admin/moderation queries

Quality

  • Forge probability validation — new test suite verifying all 35 FORGE_LEVELS rows sum to 100%, have 7 slots, and no negative values

Test plan

  • npm test — 311 tests pass (including 3 new forge validation tests)
  • npm run lint — 0 errors (only pre-existing warnings)
  • npm run build — production build succeeds
  • Verify sendBeacon save works on tab close (manual browser test)
  • Verify Stripe checkout redirects to correct origin in prod
  • Verify clan leave as owner correctly transfers/disbands

🤖 Generated with Claude Code

https://claude.ai/code/session_01LecvFszB9cnNJfRBMpX2ia


Generated by Claude Code

Security:
- Refund webhook now returns 500 on failure instead of silently claiming success
- Stripe checkout URLs validated against allowed origins (prevent open redirect)

Stability:
- Use sendBeacon for save flush on tab close (guaranteed delivery)
- Clan leave wrapped in a single transaction (prevent ownership race)
- Mission progress uses interactive transaction (prevent double completion)
- Expedition resolution errors caught per-expedition (no handler crash)
- Chat history emits error response on failure (prevent client hang)
- Clamp expedition rewards to non-negative values

Performance:
- Add HTTP compression middleware (gzip responses)
- Mission contributions limited to top 3 at query level
- Add database indexes: ChatMessage.senderId, User.createdAt

Quality:
- Add forge probability validation tests (sum=100, 7 slots, no negatives)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LecvFszB9cnNJfRBMpX2ia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants