Skip to content

Instantly share code, notes, and snippets.

@erikdubbelboer
Created February 5, 2025 05:13
Show Gist options
  • Save erikdubbelboer/9487f4262a6aae9bcc3ae765b3e7d8b6 to your computer and use it in GitHub Desktop.
Save erikdubbelboer/9487f4262a6aae9bcc3ae765b3e7d8b6 to your computer and use it in GitHub Desktop.
Asking DeepSeek R1 to look at https://github.com/poki/netlib

Here are the potential issues found in the codebase:

  1. Ignored Sync Error in Logging (cmd/signaling/main.go)

    • File: cmd/signaling/main.go
    • Issue: logger.Sync() error is ignored with // nolint:errcheck. In production, this could lead to lost log entries during shutdown.
    • Fix: Handle the error or log it.
  2. Panic in Test Proxy (cmd/testproxy/main.go)

    • File: cmd/testproxy/main.go
    • Issue: HTTP handlers use panic(err) which crashes the server on errors. Not suitable for production.
    • Fix: Return HTTP 500 errors instead of panicking.
  3. Potential Sleep After Context Cancel (internal/cloudflare/credentials.go)

    • File: internal/cloudflare/credentials.go
    • Issue: The loop sleeps without checking ctx.Done(), delaying shutdown.
    • Fix: Use select with <-ctx.Done() and <-time.After(...).
  4. Max Players Check Logic (internal/signaling/stores/postgres.go)

    • File: internal/signaling/stores/postgres.go (JoinLobby)
    • Issue: len(peerlist) >= maxPlayers blocks if maxPlayers is 0. Default is 64, but code should handle 0 as "unlimited".
    • Fix: Add maxPlayers <= 0 check to bypass the condition.
  5. SQL Injection Risk in Publish (internal/signaling/stores/postgres.go)

    • File: internal/signaling/stores/postgres.go (Publish)
    • Issue: Using string interpolation for NOTIFY payload. Malicious data could break the query.
    • Fix: Validate topic and data length/format strictly.
  6. Insecure CORS Configuration (internal/signaling/handler.go)

    • File: internal/signaling/handler.go
    • Issue: cors.Default() allows any origin. In production, this should be restricted.
    • Fix: Configure CORS with allowed origins from environment variables.
  7. Deprecated rand.Seed Usage (cmd/signaling/main.go)

    • File: cmd/signaling/main.go
    • Issue: rand.Seed is deprecated in Go 1.20+.
    • Fix: Use rand.New(rand.NewSource(...)) for local generators.
  8. Test Proxy Arbitrary SQL Execution (cmd/testproxy/main.go)

    • File: cmd/testproxy/main.go (/sql endpoint)
    • Issue: Executes arbitrary SQL, a security risk if exposed outside tests.
    • Fix: Ensure the testproxy is only enabled in test environments.
  9. Race Condition in Reconnection (lib/signaling.ts)

    • File: lib/signaling.ts (reconnect method)
    • Issue: Backoff uses Math.random() * 100 * attempt, leading to unpredictable retries.
    • Fix: Use exponential backoff with jitter.
  10. Unhandled Promise Rejection (example/main.ts)

    • File: example/main.ts (create lobby)
    • Issue: void n.create(...) without error handling.
    • Fix: Add .catch() to handle errors.
  11. Potential Deadlock in Leader Election (internal/signaling/stores/postgres.go)

    • File: internal/signaling/stores/postgres.go (DoLeaderElection)
    • Issue: Locking the entire peers table could cause contention.
    • Fix: Optimize locking scope or use advisory locks.
  12. Missing Error Handling in MarkPeerAsActive (internal/signaling/timeout_manager.go)

    • File: internal/signaling/timeout_manager.go (MarkPeerAsActive)
    • Issue: Logs errors but doesn’t retry, possibly marking active peers as inactive.
    • Fix: Implement retry logic or queue for retries.
  13. WebSocket Origin Vulnerability (internal/signaling/handler.go)

    • File: internal/signaling/handler.go
    • Issue: InsecureSkipVerify: true allows any WebSocket origin.
    • Fix: Validate the Origin header against allowed domains.
  14. ICE Server Filtering (lib/peer.ts)

    • File: lib/peer.ts (_addPeer)
    • Issue: Removes TURN servers if credentials are missing, potentially breaking NAT traversal.
    • Fix: Ensure at least one STUN server remains if TURN is unavailable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment