Skip to content

Commit f0440cf

Browse files
Validate the reconnect secret
Right now the secret is ignored as we don't check if any actual rows have been updated (with the `WHERE secret = ?`). I tried writing a test for this but we don't have an easy way to change the secret during a test. This issue was found by OpenAI o3.
1 parent 0dbfcd8 commit f0440cf

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

internal/signaling/stores/postgres.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func (s *PostgresStore) MarkPeerAsDisconnected(ctx context.Context, peerID strin
419419
func (s *PostgresStore) MarkPeerAsReconnected(ctx context.Context, peerID, secret, gameID string) (bool, []string, error) {
420420
now := util.NowUTC(ctx)
421421

422-
_, err := s.DB.Exec(ctx, `
422+
result, err := s.DB.Exec(ctx, `
423423
UPDATE peers
424424
SET
425425
disconnected = FALSE,
@@ -432,6 +432,9 @@ func (s *PostgresStore) MarkPeerAsReconnected(ctx context.Context, peerID, secre
432432
if err != nil {
433433
return false, nil, err
434434
}
435+
if result.RowsAffected() == 0 {
436+
return false, nil, nil
437+
}
435438

436439
var lobbies []string
437440
rows, err := s.DB.Query(ctx, `

0 commit comments

Comments
 (0)