Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions server/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type validationError struct {
}

const (
wsMaxMessageSize = 64 * 1024
wsMaxMessageSize = 8 * 1024 * 1024
wsWriteWait = 10 * time.Second
wsPongWait = 60 * time.Second
wsPingPeriod = (wsPongWait * 9) / 10
Expand Down Expand Up @@ -198,7 +198,11 @@ func handleWSMessage(wsConn *wsConnection, message []byte) {
return
}

utils.Info("WebSocket Request ID: %v, Method: %s, Params: %s", req.ID, req.Method, string(req.Params))
paramsLog := string(req.Params)
if len(paramsLog) > 256 {
paramsLog = paramsLog[:256] + fmt.Sprintf("…(%d bytes total)", len(req.Params))
}
Comment on lines +202 to +204
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use rune-safe truncation to preserve the 256-character contract.

Line 202/Line 203 currently truncate by bytes (len + [:256]), not characters. This can cut UTF-8 mid-rune and produce invalid output while undercutting the stated 256-character behavior.

Proposed fix
+import "unicode/utf8"
...
-	paramsLog := string(req.Params)
-	if len(paramsLog) > 256 {
-		paramsLog = paramsLog[:256] + fmt.Sprintf("…(%d bytes total)", len(req.Params))
-	}
+	paramsLog := string(req.Params)
+	if utf8.RuneCountInString(paramsLog) > 256 {
+		r := []rune(paramsLog)
+		paramsLog = string(r[:256]) + fmt.Sprintf("…(%d bytes total)", len(req.Params))
+	}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if len(paramsLog) > 256 {
paramsLog = paramsLog[:256] + fmt.Sprintf("…(%d bytes total)", len(req.Params))
}
paramsLog := string(req.Params)
if utf8.RuneCountInString(paramsLog) > 256 {
r := []rune(paramsLog)
paramsLog = string(r[:256]) + fmt.Sprintf("…(%d bytes total)", len(req.Params))
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/websocket.go` around lines 202 - 204, The truncation currently slices
paramsLog by bytes (paramsLog[:256]) and uses len(req.Params) which can split
UTF-8 runes; change to a rune-safe truncation: convert paramsLog to runes (e.g.,
[]rune(paramsLog)), if rune length > 256 build a new string from the first 256
runes and append a suffix that reports the total rune count
(len([]rune(req.Params))) so both the 256-character contract and the accurate
total are preserved; update the block that references paramsLog and req.Params
accordingly.

utils.Info("WebSocket Request ID: %v, Method: %s, Params: %s", req.ID, req.Method, paramsLog)

handleWSMethodCall(wsConn, req)
}
Expand Down
Loading