Skip to content

generateClientID produces control characters in WebSocket client IDs #331

Description

@adnaan

Bug

generateClientID() in internal/serve/websocket.go produces non-printable control characters in the client ID when clientCounter > 0:

func generateClientID() string {
    clientCounter++
    return time.Now().Format("20060102150405") + "-" + string(rune(clientCounter))
}

string(rune(1)) produces "\x01" (SOH control character), not "1". The intent was decimal-stringification of clientCounter; the result is the Unicode codepoint at that integer value.

Repro

2026/05/20 12:00:00 WebSocket client connected: 20260520120000-\x01 (total: 1)
2026/05/20 12:00:05 WebSocket client connected: 20260520120000-\x02 (total: 2)

The IDs do differ across counter values, so client-identity tracking still technically works — but log lines contain non-printable characters, and any code that compares client IDs against printable strings (or persists them to a log scraper that escapes non-printable chars) will see drift.

Fix

return time.Now().Format("20060102150405") + "-" + strconv.FormatUint(uint64(clientCounter), 10)

Scope

Pre-existing on lvt main (verified across the d2ffa33..f2f7e61 range — generateClientID is untouched). Flagged by claude-review on lvt#330 and pulled out as a separate issue per Phase 5 scope discipline.

Out of scope for this issue

  • clientCounter is a package-level int with no mutex — a separate race-condition bug. Worth a second issue or rolled into a "WebSocketManager.generateClientID hardening" PR alongside this fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions