Restrict starting a game to its participants when it is ready - #55
Open
paskal wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the /start/:id game-start flow so only legitimate participants can start a game, and only when the game is in the correct phase, preventing unauthorized users from disrupting or resetting in-progress games.
Changes:
- Added
StartGameErrorand validation instartGame(gameId, currentUserId)for: game existence (404), participant membership (403), and"ready"phase (409). - Updated the
/start/:idroute to passreq.user.idand to translateStartGameErrorinto the corresponding HTTP status code + JSON error payload. - Replaced the prior instance update with an atomic
Game.update(... where phase="ready")guard to prevent concurrent double-starts from both reshuffling/wiping state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| services/start.ts | Adds start-time authorization/phase validation and an atomic update guard to prevent unauthorized or concurrent destructive starts. |
| routers/game.ts | Passes the authenticated user into startGame and maps domain errors to appropriate HTTP responses. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Previously, POST /start/:id only required authentication: any logged-in user could start any game in any phase, and starting an in-progress game reshuffled the letters and wiped its turns and score. After this change, startGame verifies the game exists (404), the caller is one of its players (403) and the phase is "ready" (409), so games can no longer be started by outsiders or restarted mid-play.
paskal
force-pushed
the
fix/start-game-authorization
branch
from
July 4, 2026 12:05
2570a67 to
c836955
Compare
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.
Problem
POST /start/:idonly ranauthMiddleware: any logged-in user could start any game, in any phase.startGamedid no membership or phase check, and starting a game that was already in progress reshuffled the letters and wipedturns,scoreandresult— so one request could destroy an ongoing game belonging to other people.Fix
startGame(gameId, currentUserId)now validates, before touching the game:StartGameError(404, "game_not_found")StartGameError(403, "not_a_participant")"ready"→ otherwiseStartGameError(409, "game_not_ready")The route passes
req.user.idand mapsStartGameErrorto its status code; anything else still goes to the default error handler. Legitimate flow (a participant starting a ready game) is unchanged.