Skip to content

Commit e6791f0

Browse files
[FIX] truncate long WebSocket close reasons to 123 bytes
1 parent 7d0878c commit e6791f0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

web/jrpc/jrpc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,10 @@ func (s *Service) closeWS(conn *websocket.Conn, code int, err error) {
881881
reason, _, _ = apperror.Split(err)
882882
log.Trace().Field("code", code).Err(err).Msg("websocket connection closing with error")
883883
}
884+
if len(reason) > 123 {
885+
log.Warn().Field("length", len(reason)).Field("code", code).Field("reason", reason).Msg("close reason too long, truncating to 123 bytes")
886+
reason = reason[:123] // Close reason must be <= 123 bytes
887+
}
884888
err = conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(code, reason), time.Now().Add(time.Second))
885889
if err != nil && !errors.Is(err, websocket.ErrCloseSent) && !errors.Is(err, net.ErrClosed) {
886890
log.Error().Err(err).Msg("failed to send websocket close message")

0 commit comments

Comments
 (0)