Skip to content

fix(golf): use server-generated UUID for WebSocket client identification#1118

Merged
aaylward merged 1 commit intomainfrom
fix-golf-client-id-collision
Mar 7, 2026
Merged

fix(golf): use server-generated UUID for WebSocket client identification#1118
aaylward merged 1 commit intomainfrom
fix-golf-client-id-collision

Conversation

@aaylward
Copy link
Copy Markdown
Collaborator

@aaylward aaylward commented Mar 7, 2026

Summary

Fixes a security vulnerability where WebSocket client IDs were derived from RemoteAddr, causing collisions when multiple clients connect through the same proxy. Clients are now identified by a server-generated UUID assigned at connection time.

What Changed

  • hub.Client gains an ID string field populated with uuid.New().String() in ServeWs
  • GolfHub.getClientID now prefers client.ID over client.Conn.RemoteAddr(), with the old behavior as fallback for backward compatibility
  • hub/BUILD.bazel adds @com_github_google_uuid//:uuid dependency

Testing Done

  • All games_ws_backend tests pass (bazel test //domains/games/apis/games_ws_backend/...)
  • Added TestGetClientID_UsesIDFieldOverRemoteAddr covering the proxy collision scenario, ID field precedence, and fallback behavior

Diagram

sequenceDiagram
    participant P as Proxy
    participant S as Server (ServeWs)
    participant H as GolfHub

    Note over P,H: Before fix — both clients get RemoteAddr "10.0.0.1:443"
    P->>S: Client A connects
    S->>H: Register Client{Conn: RemoteAddr="10.0.0.1:443"}
    P->>S: Client B connects
    S->>H: Register Client{Conn: RemoteAddr="10.0.0.1:443"}
    Note over H: ⚠️ getClientID(A) == getClientID(B) — collision

    Note over P,H: After fix — each client gets a unique UUID
    P->>S: Client A connects
    S->>H: Register Client{ID: "uuid-a", Conn: ...}
    P->>S: Client B connects
    S->>H: Register Client{ID: "uuid-b", Conn: ...}
    Note over H: ✅ getClientID(A) != getClientID(B)
Loading

Fixed a security vulnerability where client IDs were derived from
RemoteAddr, leading to potential collisions when clients connect via
a proxy.

- Added ID field (UUID) to hub.Client
- Updated ServeWs to initialize client with a unique UUID
- Updated GolfHub.getClientID to prefer client.ID over RemoteAddr
- Updated hub/BUILD.bazel to include github.com/google/uuid dependency
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
1d4-web 4625c74 Commit Preview URL

Branch Preview URL
Mar 07 2026, 06:21 AM

@aaylward aaylward enabled auto-merge (squash) March 7, 2026 06:22
@aaylward aaylward merged commit c1a7af4 into main Mar 7, 2026
12 checks passed
@aaylward aaylward deleted the fix-golf-client-id-collision branch March 7, 2026 06:27
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.

1 participant