fix(terminal): bound websocket input frames

This commit is contained in:
naiba
2026-08-12 02:27:12 +00:00
parent 71d43c6a6e
commit c3c165c146
3 changed files with 16 additions and 1 deletions
+6
View File
@@ -14,6 +14,11 @@ import (
"github.com/nezhahq/nezha/service/singleton" "github.com/nezhahq/nezha/service/singleton"
) )
// Allow the frontend's 512 KiB clipboard payload plus xterm's bracketed-paste
// control bytes, while keeping the complete tagged message below the 1 MiB
// IO stream relay buffer.
const terminalWebSocketInputLimit int64 = 512*1024 + 64
// Create web ssh terminal // Create web ssh terminal
// @Summary Create web ssh terminal // @Summary Create web ssh terminal
// @Description Create web ssh terminal // @Description Create web ssh terminal
@@ -100,6 +105,7 @@ func terminalStream(c *gin.Context) (any, error) {
if err != nil { if err != nil {
return nil, newWsError("%v", err) return nil, newWsError("%v", err)
} }
wsConn.SetReadLimit(terminalWebSocketInputLimit)
conn := websocketx.NewConn(wsConn) conn := websocketx.NewConn(wsConn)
pingTransport := newWebsocketPingTransport(conn, wsConn.Close) pingTransport := newWebsocketPingTransport(conn, wsConn.Close)
stopPing := startWebsocketPingTicker(c.Request.Context(), time.Second*10, pingTransport) stopPing := startWebsocketPingTicker(c.Request.Context(), time.Second*10, pingTransport)
@@ -0,0 +1,9 @@
package controller
import "testing"
func TestTerminalWebSocketInputLimitAllowsBoundedPaste(t *testing.T) {
if terminalWebSocketInputLimit != 512*1024+64 {
t.Fatalf("terminal WebSocket input limit = %d, want 512 KiB plus control-byte allowance", terminalWebSocketInputLimit)
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
name: "OfficialAdmin" name: "OfficialAdmin"
repository: "https://github.com/nezhahq/admin-frontend" repository: "https://github.com/nezhahq/admin-frontend"
author: "nezhahq" author: "nezhahq"
version: "v2.3.2" version: "v2.3.3"
is_admin: true is_admin: true
is_official: true is_official: true
- path: "user-dist" - path: "user-dist"